net.xoetrope.optional.data.pojo
Class XPojoModel

java.lang.Object
  extended by net.xoetrope.xui.data.XModel
      extended by net.xoetrope.optional.data.pojo.XPojoModel
Direct Known Subclasses:
XPojoHibernateModel, XPojoIterator

public class XPojoModel
extends XModel

A model node for interacting with POJOs

Copyright (c) Xoetrope Ltd., 2001-2006
License: see license.txt


Field Summary
protected  XPojoAdapter adapter
           
protected  XPojoModel[] collectionElements
           
protected  XPojoDataSource dataSource
           
protected  boolean dirty
           
protected  int elIdx
           
protected  java.lang.reflect.Method getter
           
protected  java.lang.Object[] getterArgValues
           
protected  java.lang.Object pojo
           
protected  java.util.Hashtable properties
           
protected  java.lang.String propertyName
           
protected  java.lang.reflect.Method setter
           
 
Fields inherited from class net.xoetrope.xui.data.XModel
parentModel, tagName
 
Constructor Summary
protected XPojoModel(XModel parent, java.lang.Object p, XPojoDataSource ds)
          Creates a new instance of XPojoModel
protected XPojoModel(XModel parent, java.lang.String subPath, XPojoDataSource ds)
          Creates a new instance of XPojoModel
 
Method Summary
 java.lang.Object append(java.lang.String elementName)
          Append a new node with the specified name.
 void append(XModel childNode)
          Append a node
 void clear()
          Removes all POJOs from the tree the root of which is this model node
 void copyTo(XPojoModel target)
          Copies the underlying pojo to the specified target model
protected  java.lang.Object executeGetter(XPojoModel childNode)
          Executes the getter method of the given model node and returns the value returned by it.
protected  void executeSetter(XPojoModel childNode, java.lang.Object value)
          Executes the setter method of the given model node
 java.lang.Object get()
          Gets the value of this model node
 XModel get(int i)
          Get the XModel at element i
 java.lang.Object get(java.lang.String element)
          Get the value of the element located at the path in the element parameter.
 java.lang.String getAttribName(int i)
          Retrieve the name of the attribute at the specified index
 int getAttribute(java.lang.String attribName)
          Returns the index of the attribiteNames array whose value is the same as the attribName
 java.lang.Object getAttribValue(int i)
          Retrieve the value of the attribute at the specified index and return it.
 double getAttribValueAsDouble(int i)
          Deprecated. use getAttribValueAsDouble( i, decimalSeparator, groupingSeparator ) instead, if the locale is different from the locale used to write the values to the model, then the parsed value may be incorrect.
 double getAttribValueAsDouble(int i, char decimalSeparator, char groupingSeparator)
          Convert the attribute at the specified index to a double and return it
 int getAttribValueAsInt(int i)
          Retrieve the value of the attribute at the specified index, convert it to an int and return it.
 java.lang.String getAttribValueAsString(int i)
          Retrieve the value of the attribute at the specified index, convert it to a String and return it.
protected  XPojoModel[] getCollectionElements()
          Gets the table containing pojo collection elements
 XPojoDataSource getDataSource()
          Gets the data source object
protected  int getElIdx()
          Gets the collection's position at which the pojo of this model node is located
protected  java.lang.reflect.Method getGetter()
          Returns the getter method that should be used to obtain a pojo of this model node.
protected  java.lang.Object[] getGetterArguments()
          Gets the argument values of the getter method associated with this model node
 java.lang.String getId()
          Gets the value of the ID attribute
 int getNumAttributes()
          Gets the number of attributes of this node
 int getNumChildren()
          Gets the number of immediate children of this node
protected  java.lang.Object getPojo()
          Gets the underlying POJO
protected  java.lang.String getPropertyName()
          Gets the property name of this model node
protected  java.lang.Object getPropertyValue(XPojoModel childNode)
          Gets the value of the specified property
protected  java.lang.reflect.Method getSetter()
          Returns the setter method which should be used to set this model node's pojo
 double getValueAsDouble(java.lang.String elementName)
          Retrieve the named child, convert it's value to a double and return it.
 int getValueAsInt(java.lang.String elementName)
          Retrieve the named child, convert it's value to an int and return it.
 java.lang.String getValueAsString(java.lang.String elementName)
          Retrieve the named child, convert it's value to a String and return it.
 void hasAutoId(boolean b)
          Used for elements which need a name assigned temporarily because one doesn't exist in the DataSource.
 int hashCode()
          The hashcode of this instance.
protected  boolean hasTransientAncestestor()
          Tests whether the property wrapped by this node has a transient ancestor in the pojo property tree
 boolean isCollection()
          Tests whether the underlying pojo is an instance of Collection
 boolean isDirty()
          Gets the dirty flag of this node.
protected  boolean isPropertyTransient(java.lang.String propertyName)
          Tests whether the specified property of this model node is transient.
 boolean isTransient()
          Tests whether the property wrapped by this model node is transient.
protected  void markSubtreeAsDirty()
          Marks the children of this node as dirty.
protected  XPojoModel retrieveModelNode(java.lang.String subPath)
          Gets the previously created model node located at the specified subpath.
protected  void saveModelNode(java.lang.String subPath, XPojoModel model)
          Stores the specified model node
 void set(java.lang.Object value)
          Sets the model value
 void set(java.lang.String elementName, java.lang.Object newObject)
          Set the named attribute value of this XModel node.
 void setAttribValue(int i, java.lang.Object value)
          Sets the attribute value
 void setAttribValue(int i, java.lang.String attribName, java.lang.Object value)
          Sets the attribute name and value
 void setDirty(boolean isDirty)
          Sets the dirty state of this node.
protected  void setGetter(java.lang.reflect.Method gtr)
          Sets the getter method which should be used to obtain this model node's pojo
 void setId(java.lang.String newId)
          Sets the ID attribute
 void setNumChildren(int num)
          Set the number of children of this node
protected  void setPojo(java.lang.Object newPojo)
          Sets the new pojo of this model
protected  void setPropertyValue(XPojoModel childNode, java.lang.Object value)
          Sets the pojo of the passed XPojoModel object
protected  void setSetter(java.lang.reflect.Method str)
          Sets the setter method which should be used to set this model node's pojo
protected  void sync()
          Syncs the underlying pojo
 
Methods inherited from class net.xoetrope.xui.data.XModel
addModelListener, fireModelUpdated, getParent, getTagName, hasAutoId, prefixOutputPath, removeChildren, reset, resetAttributes, setNumAttributes, setParent, setTagName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adapter

protected XPojoAdapter adapter

dataSource

protected XPojoDataSource dataSource

propertyName

protected java.lang.String propertyName

getter

protected java.lang.reflect.Method getter

setter

protected java.lang.reflect.Method setter

getterArgValues

protected java.lang.Object[] getterArgValues

elIdx

protected int elIdx

pojo

protected java.lang.Object pojo

collectionElements

protected XPojoModel[] collectionElements

properties

protected java.util.Hashtable properties

dirty

protected boolean dirty
Constructor Detail

XPojoModel

protected XPojoModel(XModel parent,
                     java.lang.String subPath,
                     XPojoDataSource ds)
Creates a new instance of XPojoModel

Parameters:
parent - the parent model node
subPath - String in the format: propertyName(property arguments)[collection idx]

XPojoModel

protected XPojoModel(XModel parent,
                     java.lang.Object p,
                     XPojoDataSource ds)
Creates a new instance of XPojoModel

Parameters:
parent - the parent model node
p - the root pojo
ds - the data source object
Method Detail

setPojo

protected void setPojo(java.lang.Object newPojo)
Sets the new pojo of this model

Parameters:
newPojo - the new pojo

getDataSource

public XPojoDataSource getDataSource()
Gets the data source object

Returns:
XPojoDataSource object

getGetter

protected java.lang.reflect.Method getGetter()
Returns the getter method that should be used to obtain a pojo of this model node.

Returns:
the getter method

setGetter

protected void setGetter(java.lang.reflect.Method gtr)
Sets the getter method which should be used to obtain this model node's pojo

Parameters:
gtr - the getter method

getSetter

protected java.lang.reflect.Method getSetter()
Returns the setter method which should be used to set this model node's pojo

Returns:
the setter method

setSetter

protected void setSetter(java.lang.reflect.Method str)
Sets the setter method which should be used to set this model node's pojo

Parameters:
str - the setter method

getPropertyName

protected java.lang.String getPropertyName()
Gets the property name of this model node


getGetterArguments

protected java.lang.Object[] getGetterArguments()
Gets the argument values of the getter method associated with this model node

Returns:
table containing argument values

getElIdx

protected int getElIdx()
Gets the collection's position at which the pojo of this model node is located

Returns:
pojo's position in a collection

markSubtreeAsDirty

protected void markSubtreeAsDirty()
Marks the children of this node as dirty.


setDirty

public void setDirty(boolean isDirty)
Sets the dirty state of this node.

Parameters:
isDirty - the new dirty state

isDirty

public boolean isDirty()
Gets the dirty flag of this node.

Returns:
true if the pojo stored in this node is out of sync, false otherwise

getPojo

protected java.lang.Object getPojo()
Gets the underlying POJO

Returns:
POJO

getCollectionElements

protected XPojoModel[] getCollectionElements()
Gets the table containing pojo collection elements

Returns:
collection elements if the underlying pojo is an instance of Collection, null otherwise

getId

public java.lang.String getId()
Gets the value of the ID attribute

Specified by:
getId in class XModel
Returns:
the ID attribute

setId

public void setId(java.lang.String newId)
Sets the ID attribute

Overrides:
setId in class XModel
Parameters:
newId - the new name

set

public void set(java.lang.String elementName,
                java.lang.Object newObject)
Set the named attribute value of this XModel node. If the attribName is null then this node's value is updated.

Specified by:
set in class XModel
Parameters:
elementName - The path to the XModel in the format 'base/foo
newObject - The new value of the XModel

getAttribute

public int getAttribute(java.lang.String attribName)
Returns the index of the attribiteNames array whose value is the same as the attribName

Specified by:
getAttribute in class XModel
Parameters:
attribName - The name of the attribute we are trying to locate
Returns:
The index of the attributeNames array containg the name

setAttribValue

public void setAttribValue(int i,
                           java.lang.Object value)
Sets the attribute value

Specified by:
setAttribValue in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
value - the value object

setAttribValue

public void setAttribValue(int i,
                           java.lang.String attribName,
                           java.lang.Object value)
Sets the attribute name and value

Specified by:
setAttribValue in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
attribName - the name of the attribute
value - the value of the object

sync

protected void sync()
Syncs the underlying pojo


get

public XModel get(int i)
Get the XModel at element i

Specified by:
get in class XModel
Parameters:
i - The index of the values array
Returns:
The XModel at location i

get

public java.lang.Object get()
Gets the value of this model node

Specified by:
get in class XModel
Returns:
the value of the model

copyTo

public void copyTo(XPojoModel target)
Copies the underlying pojo to the specified target model

Parameters:
target - model

isPropertyTransient

protected boolean isPropertyTransient(java.lang.String propertyName)
Tests whether the specified property of this model node is transient.

Parameters:
propertyName - the name of the property
Returns:
true if the property is transient, false otherwise

hasTransientAncestestor

protected boolean hasTransientAncestestor()
Tests whether the property wrapped by this node has a transient ancestor in the pojo property tree

Returns:
true if the property has a transient ancestor false otherwise

isTransient

public boolean isTransient()
Tests whether the property wrapped by this model node is transient.

Returns:
true if the property is transient, false otherwise

isCollection

public boolean isCollection()
Tests whether the underlying pojo is an instance of Collection


getPropertyValue

protected java.lang.Object getPropertyValue(XPojoModel childNode)
Gets the value of the specified property

Parameters:
childNode - the model representing property , the value of which is to be retrieved
Returns:
the value of the property

executeGetter

protected java.lang.Object executeGetter(XPojoModel childNode)
                                  throws java.lang.Exception
Executes the getter method of the given model node and returns the value returned by it.

Parameters:
childNode - the model node whose getter is to be called.
Returns:
object returned by the retrieved getter method
Throws:
java.lang.Exception

set

public void set(java.lang.Object value)
Sets the model value

Specified by:
set in class XModel
Parameters:
value - the new value

clear

public void clear()
Removes all POJOs from the tree the root of which is this model node

Overrides:
clear in class XModel

setPropertyValue

protected void setPropertyValue(XPojoModel childNode,
                                java.lang.Object value)
Sets the pojo of the passed XPojoModel object

Parameters:
childNode - model node of the property which value is to be set.
value - the new value of the property

executeSetter

protected void executeSetter(XPojoModel childNode,
                             java.lang.Object value)
                      throws java.lang.Exception
Executes the setter method of the given model node

Parameters:
childNode - the model node whose getter is to be called
value - the object to be passed as an argument to the setter call
Throws:
java.lang.Exception

retrieveModelNode

protected XPojoModel retrieveModelNode(java.lang.String subPath)
Gets the previously created model node located at the specified subpath.

Parameters:
subPath - path to the required model node
Returns:
XModel node

saveModelNode

protected void saveModelNode(java.lang.String subPath,
                             XPojoModel model)
Stores the specified model node

Parameters:
subPath - the sub path at wich the model is located
model - the model node to be saved

get

public java.lang.Object get(java.lang.String element)
Get the value of the element located at the path in the element parameter. The element name parameter can include an attribute name by appending '@attributeName' to the path, where attributeName is the name of the attribute.

Overrides:
get in class XModel
Parameters:
element - The path to the XModel required
Returns:
The value of the XModel or the attribute

hasAutoId

public void hasAutoId(boolean b)
Used for elements which need a name assigned temporarily because one doesn't exist in the DataSource.

Overrides:
hasAutoId in class XModel
Parameters:
b - true if there was no name in the DataSource

getAttribName

public java.lang.String getAttribName(int i)
Retrieve the name of the attribute at the specified index

Specified by:
getAttribName in class XModel
Parameters:
i - The index of the attributeNames array whose value we want
Returns:
The string value of the attributeNames array at position i

getAttribValueAsString

public java.lang.String getAttribValueAsString(int i)
Retrieve the value of the attribute at the specified index, convert it to a String and return it.

Specified by:
getAttribValueAsString in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribValue

public java.lang.Object getAttribValue(int i)
Retrieve the value of the attribute at the specified index and return it.

Specified by:
getAttribValue in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The string value of the attributeValues array at position i

getAttribValueAsDouble

public double getAttribValueAsDouble(int i)
Deprecated. use getAttribValueAsDouble( i, decimalSeparator, groupingSeparator ) instead, if the locale is different from the locale used to write the values to the model, then the parsed value may be incorrect.

Retrieve the value of the attribute at the specified index, convert it to a double and return it.

Specified by:
getAttribValueAsDouble in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The double value of the attributeValues array at position i

getAttribValueAsDouble

public double getAttribValueAsDouble(int i,
                                     char decimalSeparator,
                                     char groupingSeparator)
Convert the attribute at the specified index to a double and return it

Specified by:
getAttribValueAsDouble in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
decimalSeparator - the decimal separator
groupingSeparator - the grouping (thousands) separator
Returns:
The double value of the attributeValues array at position i

getAttribValueAsInt

public int getAttribValueAsInt(int i)
Retrieve the value of the attribute at the specified index, convert it to an int and return it.

Specified by:
getAttribValueAsInt in class XModel
Parameters:
i - The index of the attributeValues array whose value we want
Returns:
The int value of the attributeValues array at position i

getValueAsDouble

public double getValueAsDouble(java.lang.String elementName)
Retrieve the named child, convert it's value to a double and return it.

Specified by:
getValueAsDouble in class XModel
Parameters:
elementName - The name of the child whose value is required
Returns:
the value as a double

getValueAsInt

public int getValueAsInt(java.lang.String elementName)
Retrieve the named child, convert it's value to an int and return it.

Specified by:
getValueAsInt in class XModel
Parameters:
elementName - The name of the child to be retrieved
Returns:
the value as an int

getValueAsString

public java.lang.String getValueAsString(java.lang.String elementName)
Retrieve the named child, convert it's value to a String and return it.

Specified by:
getValueAsString in class XModel
Parameters:
elementName - The name of the child whose value is required
Returns:
the value as a string

hashCode

public int hashCode()
The hashcode of this instance. Based on the ID String

Specified by:
hashCode in class XModel
Returns:
The hashcode of this instance

getNumChildren

public int getNumChildren()
Gets the number of immediate children of this node

Overrides:
getNumChildren in class XModel
Returns:
the number of children

getNumAttributes

public int getNumAttributes()
Gets the number of attributes of this node

Overrides:
getNumAttributes in class XModel
Returns:
the number of attributes

setNumChildren

public void setNumChildren(int num)
Set the number of children of this node

Overrides:
setNumChildren in class XModel
Parameters:
num - the new number of children

append

public void append(XModel childNode)
Append a node

Specified by:
append in class XModel
Parameters:
childNode - the child node to be appended

append

public java.lang.Object append(java.lang.String elementName)
Append a new node with the specified name. This method does not replace any existing nodes.

Specified by:
append in class XModel
Parameters:
elementName - The immediate path to the XModel required
Returns:
The value of the XModel or the attribute