com.waveset.object
Class GenericObject

java.lang.Object
  extended bycom.waveset.util.AbstractXmlObject
      extended bycom.waveset.object.GenericObject
All Implemented Interfaces:
java.util.Map, javax.naming.Referenceable, XmlObject
Direct Known Subclasses:
QueryOptions, SAPHRActiveSyncAdapter.IDOC_Segment, ServerAffinity, TraceConfig

public class GenericObject
extends AbstractXmlObject
implements java.util.Map

A class used to represent objects as an abstract collection of name/value pairs rather than a specific Java class. It is essentially a Map, but implements a few extensions to make manipulating hierarchies of objects easier. In particular, it supports a concept called "path expressions" where complex object traversals can be specified as a string, this string can be used as the key to the map.

This is the foundation of "views" at the Session level. The motivation for path expressions stems from the need to reference attributes in a flat namespace when editing an object with HTML forms.


Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static java.lang.String ATT_ID
           
static java.lang.String ATT_NAME
           
static java.lang.String ATT_TYPE
           
static java.lang.String ATT_VALUE
           
static java.lang.String code_id
           
static java.lang.String EL_ATTRIBUTE
           
static java.lang.String EL_FORMREF
           
static java.lang.String ELEMENT
          The name of the XML element used when serializing this object.
static int FLATTEN_ALL
          Flattening level value passed to toMap() to indicate that all lists, including simple value lists, should be flattened.
static int FLATTEN_NOTHING
          Flattening level value passed to toMap() to indicate that no list flattening is to be performed.
static int FLATTEN_OBJECT_LISTS
          Flattening level value passed to toMap() to indicate that flattening of GenericObject lists should be performed, but not flattening of simple value lists.
static int SYN_MISMATCHED_NAMES
          Attempt to assign a GEO to a named list element but the names don't match, e.g.
static int SYN_MISPLACED_DOT
          Misplaced dot, foo[.
static int SYN_MISPLACED_LBRACKET
          Misplaced [, foo[[ or foo.[
static int SYN_NAMED_LIST
          Nested list with symbolic name, foo[bar][0] Meaningless since nested lists can't have names.
static int SYN_NO_DOT
          Missing dot, foo[0]bar Could be smarter about this.
static int SYN_NO_GEO
          Attempting to traverse through something with foo[bar].x Where foo[bar] isn't a generic object.
static int SYN_NO_INDEX
          Empty list index, foo[]
static int SYN_NO_LIST
          Indexing something that isn't a list, e.g.
static int SYN_NO_NAME
          Dot with target but no name, I don't think this can happen.
static int SYN_NO_TARGET
          Dot with no target, just "."
 
Fields inherited from class com.waveset.util.AbstractXmlObject
_trace
 
Constructor Summary
GenericObject()
           
GenericObject(org.w3c.dom.Element e)
           
GenericObject(java.util.Map map)
           
GenericObject(java.lang.String xml)
           
GenericObject(java.lang.String xml, boolean validate)
           
 
Method Summary
 void add(java.lang.String path, java.lang.Object value)
          Add an element to a list.
 void addAlias(java.lang.String alias, java.lang.String attribute)
          Add an alias.
 void assimilate(java.util.Map map)
          Given a map containing a flat list of attributes, assimilate the values into our object.
 void assimilateModifications(java.util.Map map)
          A variant of assimilate that recognizes Modification objects.
 void browse()
          Method to bring up the view browser.
 void clear()
           
 void clearAliases()
          Clear the aliases.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
static void dumpMap(java.util.Map map)
           
 java.util.Set entrySet()
           
 void filter(java.lang.String[] names)
          Given an array of strings, remove any attributes entries whose names are contained in the array.
static GenericObject findObject(java.util.List list, java.lang.String name)
          Given a list of what are expected to be GenericObjects, return the one with the given name.
static GenericObject findObject(java.util.List list, java.lang.String attname, java.lang.Object value)
          Given a list of what are expected to be GenericObjects, return the one whose attribute matches the given value.
 java.lang.Object get(java.lang.Object key)
           
 java.util.Map getAttributes()
           
 boolean getBoolean(java.lang.String name)
           
 java.util.Date getDate(java.lang.String name)
          Coerce an object into a date.
 java.util.Date getDate(java.lang.String name, boolean throwExceptions)
          Coerce an object into a date.
 java.util.Date getDate(java.lang.String name, boolean throwExceptions, java.util.Locale locale)
          Coerce a string into a date.
 java.lang.String getElementName()
          Return the element name.
 EncryptedData getEncrypted(java.lang.String name)
          Coerce an object into an encrypted string.
 Form getForm()
           
 ObjectRef getFormRef()
           
 java.lang.String getId()
           
 int getInt(java.lang.String name)
          Coerce an Object into an int primitive.
 java.util.List getList(java.lang.String name)
           
 java.util.List getListOfStrings(java.lang.String name)
           
 java.lang.Object getLocal(java.lang.String name)
           
 long getLong(java.lang.String name)
          Coerce an Object value into a long primitive.
 java.lang.String getName()
           
 GenericObject getObject(java.lang.String name)
           
 GenericObject getObjectCreateIfNull(java.lang.String name)
           
 java.lang.String getString(java.lang.String name)
           
 boolean isEmpty()
           
 java.util.Set keySet()
           
static void main(java.lang.String[] args)
           
 void parseXml(org.w3c.dom.Element e)
           
 void parseXml(java.lang.String xml, boolean validate)
           
static void println(java.lang.String msg)
           
 java.lang.Object put(java.lang.Object key, boolean b)
           
 java.lang.Object put(java.lang.Object key, int i)
           
 java.lang.Object put(java.lang.Object key, long l)
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map src)
           
 void putLocal(java.lang.String name, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 void removeLocal(java.lang.String name)
           
 void setAliases(java.util.Map aliases)
          Set the alias map.
 void setAttributes(java.util.Map map)
          Given a simple Map, possibly containing dotted names, expand it into a hierarchical GenericObject.
 void setForm(Form f)
           
 void setFormRef(ObjectRef ref)
           
 void setId(java.lang.String id)
           
 void setIgnoreForm(boolean b)
           
 void setName(java.lang.String s)
           
 int size()
           
static void sort(java.util.List list)
          Sort a List of GenericObjects by name.
static void sort(java.util.List list, java.lang.String attname)
          Sort a List of GenericObjects according to one if its attributes.
static void test1(java.lang.String[] args)
           
static void test2()
           
static void test3(java.lang.String[] args)
           
 java.lang.String toDisplayString()
           
 void toDisplayString(java.lang.StringBuffer b, int indent, boolean showName)
           
 java.util.Map toMap()
          Convert a hierarchy of GenericObjects into a flat Map of name/value pairs.
 java.util.Map toMap(boolean flattenLists)
          Deprecated. - Use toMap(int level) instead.
 java.util.Map toMap(int level)
           
 java.util.Map toMap(java.lang.String context)
           
 java.util.Map toMap(java.lang.String context, boolean flattenLists)
          Deprecated. - Use toMap(String, int) instead.
 java.util.Map toMap(java.lang.String context, int level)
           
 java.lang.String toString()
           
 void toXml(java.lang.StringBuffer b, int indent)
          Serialize into a buffer with optional indentation.
 java.lang.String toXmlNoForm()
          Serialize the object without the form, even if it is owned by this object.
 java.lang.String toXmlNormalized()
           
 void toXmlNormalized(java.lang.StringBuffer b, int indent)
           
 void toXmlNormalized(java.lang.StringBuffer b, int indent, java.lang.String name)
           
 void trace()
           
 void trace(java.lang.String title)
          Debugging trick, dump the object to the console, but don't include the form.
 java.util.Collection values()
           
 
Methods inherited from class com.waveset.util.AbstractXmlObject
addXmlHeader, cloneObject, dump, dumpFile, getReference, println, setTrace, toIdentityString, toVerboseString, toVerboseString, toXml, toXml, toXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

ELEMENT

public static final java.lang.String ELEMENT
The name of the XML element used when serializing this object.

See Also:
Constant Field Values

FLATTEN_NOTHING

public static final int FLATTEN_NOTHING
Flattening level value passed to toMap() to indicate that no list flattening is to be performed.

See Also:
Constant Field Values

FLATTEN_OBJECT_LISTS

public static final int FLATTEN_OBJECT_LISTS
Flattening level value passed to toMap() to indicate that flattening of GenericObject lists should be performed, but not flattening of simple value lists.

See Also:
Constant Field Values

FLATTEN_ALL

public static final int FLATTEN_ALL
Flattening level value passed to toMap() to indicate that all lists, including simple value lists, should be flattened.

See Also:
Constant Field Values

SYN_MISPLACED_DOT

public static final int SYN_MISPLACED_DOT
Misplaced dot, foo[.

See Also:
Constant Field Values

SYN_NO_GEO

public static final int SYN_NO_GEO
Attempting to traverse through something with foo[bar].x Where foo[bar] isn't a generic object.

See Also:
Constant Field Values

SYN_NO_TARGET

public static final int SYN_NO_TARGET
Dot with no target, just "."

See Also:
Constant Field Values

SYN_NO_NAME

public static final int SYN_NO_NAME
Dot with target but no name, I don't think this can happen.

See Also:
Constant Field Values

SYN_MISPLACED_LBRACKET

public static final int SYN_MISPLACED_LBRACKET
Misplaced [, foo[[ or foo.[

See Also:
Constant Field Values

SYN_NAMED_LIST

public static final int SYN_NAMED_LIST
Nested list with symbolic name, foo[bar][0] Meaningless since nested lists can't have names.

See Also:
Constant Field Values

SYN_NO_LIST

public static final int SYN_NO_LIST
Indexing something that isn't a list, e.g. foo[bar] where "foo" is an object.

See Also:
Constant Field Values

SYN_NO_INDEX

public static final int SYN_NO_INDEX
Empty list index, foo[]

See Also:
Constant Field Values

SYN_NO_DOT

public static final int SYN_NO_DOT
Missing dot, foo[0]bar Could be smarter about this.

See Also:
Constant Field Values

SYN_MISMATCHED_NAMES

public static final int SYN_MISMATCHED_NAMES
Attempt to assign a GEO to a named list element but the names don't match, e.g. foo[bar] = obj where obj name isn't bar.

See Also:
Constant Field Values

ATT_TYPE

public static final java.lang.String ATT_TYPE
See Also:
Constant Field Values

ATT_ID

public static final java.lang.String ATT_ID
See Also:
Constant Field Values

ATT_NAME

public static final java.lang.String ATT_NAME
See Also:
Constant Field Values

ATT_VALUE

public static final java.lang.String ATT_VALUE
See Also:
Constant Field Values

EL_ATTRIBUTE

public static final java.lang.String EL_ATTRIBUTE
See Also:
Constant Field Values

EL_FORMREF

public static final java.lang.String EL_FORMREF
See Also:
Constant Field Values
Constructor Detail

GenericObject

public GenericObject()

GenericObject

public GenericObject(java.util.Map map)
              throws WavesetException

GenericObject

public GenericObject(java.lang.String xml)
              throws WavesetException

GenericObject

public GenericObject(java.lang.String xml,
                     boolean validate)
              throws WavesetException

GenericObject

public GenericObject(org.w3c.dom.Element e)
              throws WavesetException
Method Detail

setId

public void setId(java.lang.String id)

setFormRef

public void setFormRef(ObjectRef ref)

setForm

public void setForm(Form f)

setIgnoreForm

public void setIgnoreForm(boolean b)

toString

public java.lang.String toString()

toDisplayString

public java.lang.String toDisplayString()

toDisplayString

public void toDisplayString(java.lang.StringBuffer b,
                            int indent,
                            boolean showName)

getElementName

public java.lang.String getElementName()
Description copied from class: AbstractXmlObject
Return the element name.

Specified by:
getElementName in interface XmlObject
Specified by:
getElementName in class AbstractXmlObject

getId

public java.lang.String getId()

getFormRef

public ObjectRef getFormRef()

getForm

public Form getForm()

getAttributes

public java.util.Map getAttributes()

trace

public void trace(java.lang.String title)
Debugging trick, dump the object to the console, but don't include the form.


trace

public void trace()

clearAliases

public void clearAliases()
Clear the aliases.


addAlias

public void addAlias(java.lang.String alias,
                     java.lang.String attribute)
Add an alias.


setAliases

public void setAliases(java.util.Map aliases)
Set the alias map. Both keys and values must be Strings.


filter

public void filter(java.lang.String[] names)
            throws WavesetException
Given an array of strings, remove any attributes entries whose names are contained in the array.

Throws:
WavesetException

findObject

public static GenericObject findObject(java.util.List list,
                                       java.lang.String name)
Given a list of what are expected to be GenericObjects, return the one with the given name. This isn't really an operation on "this" object, but its a handy method, that has to be hung somewhere.


findObject

public static GenericObject findObject(java.util.List list,
                                       java.lang.String attname,
                                       java.lang.Object value)
Given a list of what are expected to be GenericObjects, return the one whose attribute matches the given value. This isn't really an operation on "this" object, but its a handy method, that has to be hung somewhere.


clear

public void clear()
Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
                     throws java.lang.IllegalArgumentException
Specified by:
put in interface java.util.Map
Throws:
java.lang.IllegalArgumentException

putAll

public void putAll(java.util.Map src)
            throws java.lang.UnsupportedOperationException
Specified by:
putAll in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

remove

public java.lang.Object remove(java.lang.Object key)
                        throws java.lang.IllegalArgumentException
Specified by:
remove in interface java.util.Map
Throws:
java.lang.IllegalArgumentException

size

public int size()
Specified by:
size in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            boolean b)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

put

public java.lang.Object put(java.lang.Object key,
                            int i)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

put

public java.lang.Object put(java.lang.Object key,
                            long l)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

add

public void add(java.lang.String path,
                java.lang.Object value)
         throws WavesetException
Add an element to a list. Could be smarter about maintianing path traversal state.

Throws:
WavesetException

getLocal

public java.lang.Object getLocal(java.lang.String name)

putLocal

public void putLocal(java.lang.String name,
                     java.lang.Object value)
              throws WavesetException
Throws:
WavesetException

removeLocal

public void removeLocal(java.lang.String name)

getString

public java.lang.String getString(java.lang.String name)

getList

public java.util.List getList(java.lang.String name)

getListOfStrings

public java.util.List getListOfStrings(java.lang.String name)

getObject

public GenericObject getObject(java.lang.String name)

getObjectCreateIfNull

public GenericObject getObjectCreateIfNull(java.lang.String name)

getBoolean

public boolean getBoolean(java.lang.String name)

getEncrypted

public EncryptedData getEncrypted(java.lang.String name)
Coerce an object into an encrypted string.


getDate

public java.util.Date getDate(java.lang.String name)
Coerce an object into a date.


getDate

public java.util.Date getDate(java.lang.String name,
                              boolean throwExceptions)
                       throws WavesetException
Coerce an object into a date.

Throws:
WavesetException

getDate

public java.util.Date getDate(java.lang.String name,
                              boolean throwExceptions,
                              java.util.Locale locale)
                       throws WavesetException
Coerce a string into a date. Partially localized. This should REALLY be fully localized.

Throws:
WavesetException

getInt

public int getInt(java.lang.String name)
Coerce an Object into an int primitive.


getLong

public long getLong(java.lang.String name)
Coerce an Object value into a long primitive.


setName

public void setName(java.lang.String s)

getName

public java.lang.String getName()

setAttributes

public void setAttributes(java.util.Map map)
                   throws WavesetException
Given a simple Map, possibly containing dotted names, expand it into a hierarchical GenericObject. This is unfortunately necessary because path processing will always assume that a dot is a traversal, might want to make it always check for a local attribute first? // * Is this what the constructor should call?

Throws:
WavesetException

assimilate

public void assimilate(java.util.Map map)
                throws WavesetException
Given a map containing a flat list of attributes, assimilate the values into our object. We assume that the map names are path expressions. This should be able to exactly duplicate the object given a Map produced by the toMap method.

The exception will be that we will not be able to restore the class names of GenericObject's since those aren't included in the paths. // * Perhaps class names should be attributes?

Throws:
WavesetException

assimilateModifications

public void assimilateModifications(java.util.Map map)
                             throws WavesetException
A variant of assimilate that recognizes Modification objects.

Throws:
WavesetException

toMap

public java.util.Map toMap()
Convert a hierarchy of GenericObjects into a flat Map of name/value pairs. The resulting names will also be valid path expressions back into the GenericObject.

Objects that we don't know how to traverse will be left as-is in the map. Might want an option to coerce these to strings?

The resulting Map can be passed to the assimilate method to produce a duplicate of this object.


toMap

public java.util.Map toMap(boolean flattenLists)
Deprecated. - Use toMap(int level) instead.

Flatten an object including object lists and value lists.


toMap

public java.util.Map toMap(int level)

toMap

public java.util.Map toMap(java.lang.String context)

toMap

public java.util.Map toMap(java.lang.String context,
                           boolean flattenLists)
Deprecated. - Use toMap(String, int) instead.


toMap

public java.util.Map toMap(java.lang.String context,
                           int level)

sort

public static void sort(java.util.List list)
Sort a List of GenericObjects by name.


sort

public static void sort(java.util.List list,
                        java.lang.String attname)
Sort a List of GenericObjects according to one if its attributes.


toXmlNoForm

public java.lang.String toXmlNoForm()
Serialize the object without the form, even if it is owned by this object. Added for testing, since forms can be large and the data is usually more interesting.


toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Description copied from class: AbstractXmlObject
Serialize into a buffer with optional indentation. This must be implemented by the subclass.

Specified by:
toXml in interface XmlObject
Specified by:
toXml in class AbstractXmlObject

parseXml

public void parseXml(org.w3c.dom.Element e)
              throws WavesetException
Throws:
WavesetException

parseXml

public void parseXml(java.lang.String xml,
                     boolean validate)
              throws WavesetException
Throws:
WavesetException

toXmlNormalized

public java.lang.String toXmlNormalized()

toXmlNormalized

public void toXmlNormalized(java.lang.StringBuffer b,
                            int indent)

toXmlNormalized

public void toXmlNormalized(java.lang.StringBuffer b,
                            int indent,
                            java.lang.String name)

browse

public void browse()
Method to bring up the view browser. Try not to reference the class directly so we don't set up a package dependency between the two.


main

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

println

public static void println(java.lang.String msg)

dumpMap

public static void dumpMap(java.util.Map map)

test1

public static void test1(java.lang.String[] args)
                  throws java.lang.Exception
Throws:
java.lang.Exception

test2

public static void test2()
                  throws java.lang.Exception
Throws:
java.lang.Exception

test3

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