dd.util
Class AttributeHelper

java.lang.Object
  extended bydd.util.AttributeHelper

public class AttributeHelper
extends java.lang.Object

Provides support for attribute maps. Attributes are stored as name / value pairs in Map objects. This class provides useful static methods for maanipulating these attributes, such as reading to and writing from XML.

The attribute maps can be used in two ways. In the standard way, the keys are strings (attribute names) and the values are Objects, typically Float values. Another kind of attribute map includes layer information. In that case, the keys are Layer objects, and the values are attribute maps (so there are two levels of indirection.

Author:
Eric Scharff

Constructor Summary
AttributeHelper()
           
 
Method Summary
static void main(java.lang.String[] args)
           
static java.util.HashMap readAttributes(org.w3c.dom.Node node, Map world)
          Reads attributes from an XML representation.
static java.util.HashMap readAttributes(org.w3c.dom.Node node, Map world, java.lang.String tagName, java.lang.String keyField, java.lang.String valueField)
          Reads attributes from an XML representation.
static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document, java.util.HashMap map)
          Write attributes maps.
static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document, java.util.HashMap map, java.lang.String objName)
          Writes attribute maps.
static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document, java.util.HashMap map, java.lang.String objName, java.lang.String tagName)
          Writes attribute maps.
static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document, java.util.HashMap map, java.lang.String objName, java.lang.String tagName, java.lang.String keyName, java.lang.String valName)
          Write attributes with layer information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeHelper

public AttributeHelper()
Method Detail

writeAttributes

public static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document,
                                               java.util.HashMap map)
Write attributes maps. This method takes a map and outputs the attribute information as XML. It automatically detects if this is a simple name / value mapping or if it contains layer information.

Note that although the document is required to write the node properly, the node that is returned is not added to the document's DOM tree. This must be done by some other method in order for the node to appear in the result.

Parameters:
document - XML document to write
map - attribute map to write as XML
Returns:
an XML node that can be inserted into a DOM tree that contains the attribute values

writeAttributes

public static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document,
                                               java.util.HashMap map,
                                               java.lang.String objName)
Writes attribute maps. This allows you to customize the tag name used for the attribute map itself. Attributes will be placed inside a tag of this name, with sub-elements called "attribute".

Note that although the document is required to write the node properly, the node that is returned is not added to the document's DOM tree. This must be done by some other method in order for the node to appear in the result.

Parameters:
document - XML document to write
map - attribute map to write as XML
objName - name of the (parent) attribute tag
Returns:
an XML node that can be inserted into a DOM tree that contains the attribute values

writeAttributes

public static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document,
                                               java.util.HashMap map,
                                               java.lang.String objName,
                                               java.lang.String tagName)
Writes attribute maps. This allows you to customize the tag name used for the attribute map itself. Attributes will be placed inside a tag of this name, with sub-elements called "attribute".

Note that although the document is required to write the node properly, the node that is returned is not added to the document's DOM tree. This must be done by some other method in order for the node to appear in the result.

Parameters:
document - XML document to write
map - attribute map to write as XML
objName - name of the (parent) attribute tag
tagName - the name that will be given to each individual attribute
Returns:
an XML node that can be inserted into a DOM tree that contains the attribute values

writeAttributes

public static org.w3c.dom.Node writeAttributes(org.w3c.dom.Document document,
                                               java.util.HashMap map,
                                               java.lang.String objName,
                                               java.lang.String tagName,
                                               java.lang.String keyName,
                                               java.lang.String valName)
Write attributes with layer information. If the keys are Layer objects, then the values are attribute dictionaries for that layer, so the layer name should be written as attribute information.

Note that although the document is required to write the node properly, the node that is returned is not added to the document's DOM tree. This must be done by some other method in order for the node to appear in the result.

Important: The attribute tag "type" is reserved for type information. So, keyName or valName may not be "type".

Parameters:
document - XML document to write
map - attribute map to write as XML
objName - name of whole hash (default: "attributes")
tagName - name of hash entries (default: "attribute")
keyName - name of hash keys (default: "name")
valName - name of hash values (default: "value")
Returns:
an XML node that can be inserted into a DOM tree that contains the attribute values

readAttributes

public static java.util.HashMap readAttributes(org.w3c.dom.Node node,
                                               Map world)
Reads attributes from an XML representation. This method takes the XML root node of the list of attributes and populates the attribute dictionary from the list of values provided. The world map is required to read attribute dictionaries that refer to LandUse or Layer objects, so dictionaries that are simple name value pairs (and do not have layer information) can pass null in for the world. If layer information is provided, it is correctly added to the map (because the layers used in the Map and the layers used inside MapCell objects should be the same.

Parameters:
node - the XML node whose children are attribute name/value pairs
world - the Map to which layers are added (if necessary)
Returns:
a newly initialized attribute table (a set of name value pairs) correctly initialized with layer information.

readAttributes

public static java.util.HashMap readAttributes(org.w3c.dom.Node node,
                                               Map world,
                                               java.lang.String tagName,
                                               java.lang.String keyField,
                                               java.lang.String valueField)
Reads attributes from an XML representation. This method takes the XML root node of the list of attributes and populates the attribute dictionary from the list of values provided. The world map is required to read attribute dictionaries that refer to LandUse or Layer objects, so dictionaries that are simple name value pairs (and do not have layer information) can pass null in for the world. If layer information is provided, it is correctly added to the map (because the layers used in the Map and the layers used inside MapCell objects should be the same.

Parameters:
node - the XML node whose children are attribute name/value pairs
world - the Map to which layers are added (if necessary)
keyField - name of the XML attribute that stores the key
valueField - name of the XML attribute that stores the value
Returns:
a newly initialized attribute table (a set of name value pairs) correctly initialized with layer information.

main

public static void main(java.lang.String[] args)