hmi.xml
Class XMLAttributeMap

java.lang.Object
  extended by hmi.xml.XMLAttributeMap
All Implemented Interfaces:
XMLStructure

public class XMLAttributeMap
extends Object
implements XMLStructure

parlevink.xml.XMLAttributeMap is like java.util.properties, except that it is not limited to String-typed keys and values, and it is based on HashMaps, rather than Hashtables. Keys take the form of Id's or Strings, although internally Id's are used. For storing/retrieving Object-typed values, the prime methods are setAttribute(id, value) and getAttribute(id). When values are known to be Strings, the preferred methods are setString(id, string) and getString(id). In all cases, "id" can be an Id, or it can be a String.

Author:
Job Zwiers

Field Summary
private  LinkedHashMap<String,Object> attr
           
static String ATTRIBUTEMAPTAG
           
private  StringBuilder buf
           
private static int BUFLEN
          the (initial) length of the StringBuilder used for readXML(in).
static String CLASSNAME
           
private static int ENCODEBUFSIZE
           
private  String encoding
           
static int TAB
           
static String WRAPPEDCLASSNAME
           
private static String XMLTAG
           
 
Constructor Summary
XMLAttributeMap()
          creates a new, empty set of attributes.
XMLAttributeMap(int initialCapacity)
          creates a new, empty set of attributes.
 
Method Summary
private  void appendSpace(StringBuilder buf, int nsp)
           
 StringBuilder appendXML(StringBuilder buf)
          appends the value of this XMLList to buf.
 StringBuilder appendXML(StringBuilder buf, int tab)
          appends the value of this XMLList to buf.
 StringBuilder appendXML(StringBuilder buf, XMLFormatting fmt)
          appends the value of this XMLList to buf.
 Iterator<String> attributeNames()
          Returns an Iterator for all the property attribute keys.
 Iterator<Object> attributeValues()
          Returns an Iterator for all the attribute values.
private  void clearBuf(int len)
           
private  void encode(int tab)
           
 boolean equals(Object attributeMap)
           
 Object getAttribute(String key)
          retrieves the (Object-typed) value of the attribute identified by key.
 String getString(String key)
          retrieves the String-typed value of the attribute identified by key.
 String getXMLTag()
          returns the XML tag that is used to encode this type of XMLStructure.
 boolean hasAttribute(String key)
          checks whether an attribute for "key" has been defined.
 int hashCode()
           
protected  Iterator<Map.Entry<String,Object>> iterator()
           
 XMLStructure readXML(Reader in)
          reconstructs this XMLList object by reading and parsing XML encoded data Data is read until the end of data is reached, or until a '<' character is read.
 XMLStructure readXML(String s)
          reconstructs this XMLLIst object by parsing an XML encoded String s This method can throw an (unchecked) XMLScanException in case of incorrectly formatted XML.
 XMLStructure readXML(XMLTokenizer tokenizer)
          reconstructs this XMLList using a XMLTokenizer.
 Object setAttribute(String key, Object value)
          sets the value of the attribute identified by "key".
 Object setString(String key, String value)
          sets the String-typed value of the attribute identified by "key".
 String toString()
           
 String toXMLString()
          yields an XML encoded String of this XMLIzable object.
 String toXMLString(int tab)
          yields an XML encoded String of this XMLIzable object.
 String toXMLString(XMLFormatting fmt)
          yields an XML encoded String of this XMLIzable object.
 void writeXML(PrintWriter out)
          writes the value of this XMLList to out.
 void writeXML(PrintWriter out, int tab)
          writes the value of this XMLList to out.
 void writeXML(PrintWriter out, XMLFormatting fmt)
          writes the value of this XMLList to out.
static String xmlTag()
          The XML Stag for XML encoding -- use this static method when you want to see if a given String equals the xml tag for this class
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ENCODEBUFSIZE

private static final int ENCODEBUFSIZE
See Also:
Constant Field Values

attr

private LinkedHashMap<String,Object> attr

BUFLEN

private static final int BUFLEN
the (initial) length of the StringBuilder used for readXML(in).

See Also:
Constant Field Values

encoding

private String encoding

buf

private StringBuilder buf

TAB

public static final int TAB
See Also:
Constant Field Values

ATTRIBUTEMAPTAG

public static final String ATTRIBUTEMAPTAG
See Also:
Constant Field Values

XMLTAG

private static final String XMLTAG
See Also:
Constant Field Values

CLASSNAME

public static final String CLASSNAME
See Also:
Constant Field Values

WRAPPEDCLASSNAME

public static final String WRAPPEDCLASSNAME
See Also:
Constant Field Values
Constructor Detail

XMLAttributeMap

public XMLAttributeMap()
creates a new, empty set of attributes.


XMLAttributeMap

public XMLAttributeMap(int initialCapacity)
creates a new, empty set of attributes. The initial size of the internal Hasmap is specified by means of "initialCapacity"

Method Detail

setAttribute

public Object setAttribute(String key,
                           Object value)
sets the value of the attribute identified by "key". Returns the previously bound value for "key", or null, if "key" was not bound.


getAttribute

public Object getAttribute(String key)
retrieves the (Object-typed) value of the attribute identified by key. Returns the previously bound value for "key", or null, if "key" was not bound.


setString

public Object setString(String key,
                        String value)
sets the String-typed value of the attribute identified by "key". Returns the previously bound value for "key", or null, if "key" was not bound.


getString

public String getString(String key)
retrieves the String-typed value of the attribute identified by key. Returns the previously bound value for "key", or null, if "key" was not bound.


hasAttribute

public boolean hasAttribute(String key)
checks whether an attribute for "key" has been defined.


attributeNames

public Iterator<String> attributeNames()
Returns an Iterator for all the property attribute keys.


attributeValues

public Iterator<Object> attributeValues()
Returns an Iterator for all the attribute values.


iterator

protected Iterator<Map.Entry<String,Object>> iterator()

appendSpace

private void appendSpace(StringBuilder buf,
                         int nsp)

encode

private void encode(int tab)

readXML

public XMLStructure readXML(String s)
reconstructs this XMLLIst object by parsing an XML encoded String s This method can throw an (unchecked) XMLScanException in case of incorrectly formatted XML.

Specified by:
readXML in interface XMLStructure

readXML

public XMLStructure readXML(Reader in)
                     throws IOException
reconstructs this XMLList object by reading and parsing XML encoded data Data is read until the end of data is reached, or until a '<' character is read. This method can throw IOExceptions.

Specified by:
readXML in interface XMLStructure
Throws:
IOException

readXML

public XMLStructure readXML(XMLTokenizer tokenizer)
reconstructs this XMLList using a XMLTokenizer. This method can throw an (unchecked) XMLScanException in case of incorrectly formatted XML.

Specified by:
readXML in interface XMLStructure

writeXML

public void writeXML(PrintWriter out)
writes the value of this XMLList to out.

Specified by:
writeXML in interface XMLStructure

writeXML

public void writeXML(PrintWriter out,
                     int tab)
writes the value of this XMLList to out.

Specified by:
writeXML in interface XMLStructure

writeXML

public void writeXML(PrintWriter out,
                     XMLFormatting fmt)
writes the value of this XMLList to out.

Specified by:
writeXML in interface XMLStructure

appendXML

public StringBuilder appendXML(StringBuilder buf)
appends the value of this XMLList to buf.

Specified by:
appendXML in interface XMLStructure

appendXML

public StringBuilder appendXML(StringBuilder buf,
                               XMLFormatting fmt)
appends the value of this XMLList to buf.

Specified by:
appendXML in interface XMLStructure

appendXML

public StringBuilder appendXML(StringBuilder buf,
                               int tab)
appends the value of this XMLList to buf.

Specified by:
appendXML in interface XMLStructure

toXMLString

public String toXMLString()
yields an XML encoded String of this XMLIzable object. The readXML() methods are able to reconstruct this object from the String delivered by toXMLString().

Specified by:
toXMLString in interface XMLStructure

toXMLString

public String toXMLString(XMLFormatting fmt)
yields an XML encoded String of this XMLIzable object. The readXML() methods are able to reconstruct this object from the String delivered by toXMLString().

Specified by:
toXMLString in interface XMLStructure

toXMLString

public String toXMLString(int tab)
yields an XML encoded String of this XMLIzable object. The readXML() methods are able to reconstruct this object from the String delivered by toXMLString().

Specified by:
toXMLString in interface XMLStructure

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object attributeMap)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clearBuf

private void clearBuf(int len)

getXMLTag

public String getXMLTag()
returns the XML tag that is used to encode this type of XMLStructure. The default returns null.

Specified by:
getXMLTag in interface XMLStructure

xmlTag

public static String xmlTag()
The XML Stag for XML encoding -- use this static method when you want to see if a given String equals the xml tag for this class