Class PrimitiveXMLEncodeDecode
java.lang.Object
uk.ac.starlink.util.PrimitiveXMLEncodeDecode
- All Implemented Interfaces:
XMLEncodeDecode
An abstract base-class for objects that want to encode and decode
themselves from an XML stream.
It contains the XMLEncodeDecode interface (with an
unimplemented encode() method) and a number of support methods for
encoding and decoding primitive values.
This implementation also provides default implementations of
ChangeListener methods that allow an extending class to
provide services for registering, responding and issuing
ChangeEvents.
- Version:
- $Id$
- Author:
- Peter W. Draper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CDATASectionaddCDATASection(Element rootElement, String value) Create a new CDATA section with the given content and add it as a child of a given element.voidRegisters a listener who wants to be informed about changes.static ElementaddChildElement(Element rootElement, String name) Create a child element with no content and add it to the given element.static ElementaddChildElement(Element rootElement, String name, boolean value) Add an element with boolean value as a child of another element.static ElementaddChildElement(Element rootElement, String name, double value) Add an element with double value as a child of another element.static ElementaddChildElement(Element rootElement, String name, int value) Add an element with integer value as a child of another element.static ElementaddChildElement(Element rootElement, String name, String value) Add an element with String value as a child of another element.static booleanbooleanFromString(String value) Convert a String back to a boolean.static StringbooleanToString(boolean value) Convert a boolean to a String.voidDecode (ie, restore) the internal state of this object from an Element.static doubledoubleFromString(String value) Convert a String back to a double.static StringdoubleToString(double value) Convert a double to a String.abstract voidEncode the internal state of this object so that it is rooted in the given Element.protected voidSend ChangeEvent event to all listeners.getChildElements(Element element) Return all the Elements that are children of another Element.static NodeListgetChildren(Element rootElement) Return a List of all children.static StringgetElementName(Element element) Get the name of an element.static StringgetElementValue(Element element) Get the "value" of an element (really the content).static intintFromString(String value) Convert a String back to an integer.static StringintToString(int value) Convert an integer to a String.static longlongFromString(String value) Convert a String back to a long.static StringlongToString(long value) Convert a long to a String.voidDe-registers a listener for changes.abstract voidsetFromString(String name, String value) Set the value of a object field using string representation of the field name and its value.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface XMLEncodeDecode
getTagName
-
Field Details
-
listeners
-
-
Constructor Details
-
PrimitiveXMLEncodeDecode
public PrimitiveXMLEncodeDecode()
-
-
Method Details
-
addChangeListener
Registers a listener who wants to be informed about changes.- Parameters:
l- the ChangeListener listener.
-
removeChangeListener
De-registers a listener for changes.- Parameters:
l- the ChangeListener listener.
-
fireChanged
protected void fireChanged()Send ChangeEvent event to all listeners. -
encode
Description copied from interface:XMLEncodeDecodeEncode the internal state of this object so that it is rooted in the given Element.- Specified by:
encodein interfaceXMLEncodeDecode- Parameters:
rootElement- the Element within which the object should store its configuration.
-
decode
Description copied from interface:XMLEncodeDecodeDecode (ie, restore) the internal state of this object from an Element.- Specified by:
decodein interfaceXMLEncodeDecode- Parameters:
rootElement- the element to which a previous object this this type has attached its configuration.
-
getChildElements
-
setFromString
-
addChildElement
-
addCDATASection
Create a new CDATA section with the given content and add it as a child of a given element. -
addChildElement
-
addChildElement
-
addChildElement
-
addChildElement
-
getChildren
-
getElementName
-
getElementValue
-
doubleToString
Convert a double to a String. -
doubleFromString
Convert a String back to a double. -
booleanToString
Convert a boolean to a String. -
booleanFromString
Convert a String back to a boolean. -
intToString
Convert an integer to a String. -
intFromString
Convert a String back to an integer. -
longToString
Convert a long to a String. -
longFromString
Convert a String back to a long.
-