public class XMLElement extends Object implements Serializable, Cloneable
When classes that extends this class are created, they can call this class constructor without arguments, in which case the member of this class that corresponds to the XML element name is filled with the name of extended class, or with the argument that represents the name of element, where such name directly sets the previously mentioned member (This is the case when creating 'attribute' or 'choice' XML elements). The label to be written in a dialog for editing value of element, is set to the language specific value, which has to be defined in the property file under the key: "ElementNameKey".
This class contains method #getPanel, which should be overriden by classes
that extends this class, and which is used to show the panel with the field
that represent a value of XML element (In the case of complex elements, the
panel will show fields of all elements that complex element is made of). This
panel is shown in a dialog (see XMLElementDialog) that allows user to
edit this field, and when user presses OK, the new value is put in the value
member of this class.
When program decides to write an XML file according to it's XMLElement derived class members, it calls #toXML method of those classes, which is defined by this class, but has no implementation. This method has to write the proper element opening and closing tag (defined by element name), and the previously defined value of element to put inside tags.
When there is a need of reading an XML file, the values that corresponds to particular element (determined by element name and it's position within other elements) are put into this element value member by calling #fromXML method, and passing it a tag to process.
This class also defines methods that are performing a check for validity, emptiness or mandatory status of the element, and are also supposed to be redefined by classes that extends it.
NOTE: Although this class is not declared abstract, it is uselles without redefining it's methods. XML元素的基类
| 限定符和类型 | 字段和说明 |
|---|---|
protected AttributeSet |
atts |
protected boolean |
isCollapsed |
protected boolean |
isReadOnly
Used in dialogs to forbid editing of an element value.
|
protected boolean |
isRequired
Indicates if an element is required - corresponds to the same XML element
definition.
|
protected boolean |
isVisible |
protected String |
labelName
Language specific name of XML element that is shown in editing dialog.
|
protected String |
name
Equivalent for XML element name.
|
protected String |
NEWLINE |
protected String |
OFFSET |
protected Object |
value
Supposed to contain the value for XML element.
|
| 构造器和说明 |
|---|
XMLElement()
Creates a new instance of element: sets the
name member to
the name of inner class that extends this element, and the
labelName member to the value read from property file
under the key of previously set name member. |
XMLElement(String name)
Creates a new instance of element: sets the
name member to
the specified one, and the labelName member to the value
read from property file under the key of previously set name
member. |
| 限定符和类型 | 方法和说明 |
|---|---|
Object |
clone()
Used to create exact copy of instance of this class.
|
void |
fromXML(Node node)
Supposed to be overriden by derived classes to implement element specific
reading from an XML file.
|
void |
fromXML(String name,
Node node)
Supposed to be used (and overriden) by class that represent XML choice of
complex elements.
|
DefaultMutableTreeNode |
getNode()
Make tree node for this element and all subelements.
|
XMLPanel |
getPanel()
Returns the panel for editing the element.
|
String |
getPrintDescription(String indent,
StyledDocument doc)
Description of this element and all subelements.
|
String |
getPrintDescription(StyledDocument doc)
This method will call getPrintDescription(String indent) with parameter OFFSET.
|
boolean |
isCollapsed() |
boolean |
isEmpty()
Indicates if element is empty.
|
boolean |
isReadOnly()
Returns the 'read only' status of element.
|
boolean |
isRequired()
Returns the 'required' property of the element.
|
boolean |
isValid()
Indicates if element is valid in XML XML sense.
|
boolean |
isValidEnter(XMLPanel p)
Indicates if dialog data enter for element is valid.
|
boolean |
isVisible() |
void |
refreshLabelName() |
void |
setCollapsed(boolean isCollapsed) |
void |
setLabelName(String lName) |
void |
setReadOnly(boolean ro)
Sets the 'read only' property of element to the specified one.
|
void |
setRequired(boolean r)
Sets the 'required' property of the element.
|
void |
setValue(Object v)
Sets the element value (in the sense of XML element).
|
void |
setVisible(boolean isVisible) |
String |
toLabel()
Returns the text for element 'name' presentation within a dialog for
editing element.
|
String |
toName()
Returns the name of element.
|
String |
toString()
Returns the text representation of element's 'value'.
|
Object |
toValue()
Gets the element value.
|
void |
toXML(Node parent)
Supposed to be overriden by derived classes to implement element specific
writting to an XML file.
|
protected String name
protected String labelName
protected Object value
protected boolean isRequired
protected boolean isReadOnly
protected boolean isVisible
protected boolean isCollapsed
protected String OFFSET
protected String NEWLINE
protected AttributeSet atts
public XMLElement()
name member to
the name of inner class that extends this element, and the
labelName member to the value read from property file
under the key of previously set name member.public XMLElement(String name)
name member to
the specified one, and the labelName member to the value
read from property file under the key of previously set name
member.name - The name of XML element that this class represents.public void setReadOnly(boolean ro)
ro - true if element will be 'read only', false
otherwise.public boolean isReadOnly()
public void setRequired(boolean r)
r - true if element will be 'required', false
otherwise.public boolean isRequired()
public boolean isEmpty()
public boolean isValid()
public boolean isValidEnter(XMLPanel p)
public void toXML(Node parent) throws DOMException
parent - indicates how much tabulators to put before element tag.DOMExceptionpublic void fromXML(Node node)
node - The content retrieved from XML file, that represents tag for
this element.public void fromXML(String name, Node node)
name - The element name.node - The content retrieved from XML file, that represents tag for
this element.public XMLPanel getPanel()
public void setLabelName(String lName)
public void setValue(Object v)
v - The value to set.public Object toValue()
public String toLabel()
public String toName()
public String toString()
toString method of it's value member, if value is
null, returns labelName member.public Object clone()
public void refreshLabelName()
public DefaultMutableTreeNode getNode()
public String getPrintDescription(StyledDocument doc)
public String getPrintDescription(String indent, StyledDocument doc)
public void setVisible(boolean isVisible)
public boolean isVisible()
public void setCollapsed(boolean isCollapsed)
public boolean isCollapsed()
Copyright © 2023 onecode. All rights reserved.