Package uk.ac.starlink.util
Class PrimitiveXMLEncodeDecode
- java.lang.Object
-
- uk.ac.starlink.util.PrimitiveXMLEncodeDecode
-
- All Implemented Interfaces:
XMLEncodeDecode
public abstract class PrimitiveXMLEncodeDecode extends java.lang.Object implements XMLEncodeDecode
An abstract base-class for objects that want to encode and decode themselves from an XML stream.It contains the
XMLEncodeDecodeinterface (with an unimplemented encode() method) and a number of support methods for encoding and decoding primitive values.This implementation also provides default implementations of
ChangeListenermethods that allow an extending class to provide services for registering, responding and issuingChangeEvents.- Version:
- $Id$
- Author:
- Peter W. Draper
-
-
Field Summary
Fields Modifier and Type Field Description protected javax.swing.event.EventListenerListlisteners
-
Constructor Summary
Constructors Constructor Description PrimitiveXMLEncodeDecode()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.CDATASectionaddCDATASection(org.w3c.dom.Element rootElement, java.lang.String value)Create a new CDATA section with the given content and add it as a child of a given element.voidaddChangeListener(javax.swing.event.ChangeListener l)Registers a listener who wants to be informed about changes.static org.w3c.dom.ElementaddChildElement(org.w3c.dom.Element rootElement, java.lang.String name)Create a child element with no content and add it to the given element.static org.w3c.dom.ElementaddChildElement(org.w3c.dom.Element rootElement, java.lang.String name, boolean value)Add an element with boolean value as a child of another element.static org.w3c.dom.ElementaddChildElement(org.w3c.dom.Element rootElement, java.lang.String name, double value)Add an element with double value as a child of another element.static org.w3c.dom.ElementaddChildElement(org.w3c.dom.Element rootElement, java.lang.String name, int value)Add an element with integer value as a child of another element.static org.w3c.dom.ElementaddChildElement(org.w3c.dom.Element rootElement, java.lang.String name, java.lang.String value)Add an element with String value as a child of another element.static booleanbooleanFromString(java.lang.String value)Convert a String back to a boolean.static java.lang.StringbooleanToString(boolean value)Convert a boolean to a String.voiddecode(org.w3c.dom.Element rootElement)Decode (ie, restore) the internal state of this object from an Element.static doubledoubleFromString(java.lang.String value)Convert a String back to a double.static java.lang.StringdoubleToString(double value)Convert a double to a String.abstract voidencode(org.w3c.dom.Element rootElement)Encode the internal state of this object so that it is rooted in the given Element.protected voidfireChanged()Send ChangeEvent event to all listeners.static java.util.List<org.w3c.dom.Element>getChildElements(org.w3c.dom.Element element)Return all the Elements that are children of another Element.static org.w3c.dom.NodeListgetChildren(org.w3c.dom.Element rootElement)Return a List of all children.static java.lang.StringgetElementName(org.w3c.dom.Element element)Get the name of an element.static java.lang.StringgetElementValue(org.w3c.dom.Element element)Get the "value" of an element (really the content).static intintFromString(java.lang.String value)Convert a String back to an integer.static java.lang.StringintToString(int value)Convert an integer to a String.static longlongFromString(java.lang.String value)Convert a String back to a long.static java.lang.StringlongToString(long value)Convert a long to a String.voidremoveChangeListener(javax.swing.event.ChangeListener l)De-registers a listener for changes.abstract voidsetFromString(java.lang.String name, java.lang.String value)Set the value of a object field using string representation of the field name and its value.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface uk.ac.starlink.util.XMLEncodeDecode
getTagName
-
-
-
-
Method Detail
-
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener l)
Registers a listener who wants to be informed about changes.- Parameters:
l- the ChangeListener listener.
-
removeChangeListener
public void removeChangeListener(javax.swing.event.ChangeListener l)
De-registers a listener for changes.- Parameters:
l- the ChangeListener listener.
-
fireChanged
protected void fireChanged()
Send ChangeEvent event to all listeners.
-
encode
public abstract void encode(org.w3c.dom.Element rootElement)
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
public void decode(org.w3c.dom.Element rootElement)
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
public static java.util.List<org.w3c.dom.Element> getChildElements(org.w3c.dom.Element element)
Return all the Elements that are children of another Element.
-
setFromString
public abstract void setFromString(java.lang.String name, java.lang.String value)Set the value of a object field using string representation of the field name and its value. Users of the default decode implementation must re-implement this method.
-
addChildElement
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element rootElement, java.lang.String name)Create a child element with no content and add it to the given element.
-
addCDATASection
public static org.w3c.dom.CDATASection addCDATASection(org.w3c.dom.Element rootElement, java.lang.String value)Create a new CDATA section with the given content and add it as a child of a given element.
-
addChildElement
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element rootElement, java.lang.String name, java.lang.String value)Add an element with String value as a child of another element. The String is stored as CDATA.
-
addChildElement
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element rootElement, java.lang.String name, boolean value)Add an element with boolean value as a child of another element.
-
addChildElement
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element rootElement, java.lang.String name, int value)Add an element with integer value as a child of another element.
-
addChildElement
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element rootElement, java.lang.String name, double value)Add an element with double value as a child of another element.
-
getChildren
public static org.w3c.dom.NodeList getChildren(org.w3c.dom.Element rootElement)
Return a List of all children. Use the NodeList interface to step through these.
-
getElementName
public static java.lang.String getElementName(org.w3c.dom.Element element)
Get the name of an element.
-
getElementValue
public static java.lang.String getElementValue(org.w3c.dom.Element element)
Get the "value" of an element (really the content).
-
doubleToString
public static java.lang.String doubleToString(double value)
Convert a double to a String.
-
doubleFromString
public static double doubleFromString(java.lang.String value)
Convert a String back to a double.
-
booleanToString
public static java.lang.String booleanToString(boolean value)
Convert a boolean to a String.
-
booleanFromString
public static boolean booleanFromString(java.lang.String value)
Convert a String back to a boolean.
-
intToString
public static java.lang.String intToString(int value)
Convert an integer to a String.
-
intFromString
public static int intFromString(java.lang.String value)
Convert a String back to an integer.
-
longToString
public static java.lang.String longToString(long value)
Convert a long to a String.
-
longFromString
public static long longFromString(java.lang.String value)
Convert a String back to a long.
-
-