org.formaria.data.pojo
Class PojoHelper

java.lang.Object
  extended by org.formaria.data.pojo.PojoHelper

public class PojoHelper
extends java.lang.Object

A helper for the pojo model nodes

Copyright (c) Formaria Ltd., 2008
License: see license.txt


Constructor Summary
PojoHelper(java.lang.Object model)
          Creates a new instance of PojoHelper
 
Method Summary
protected static java.lang.Class convertType(java.lang.String typeName)
          Returns Class object whose simple name is in the given String.
protected static java.lang.Object convertValue(java.lang.String type, java.lang.String value)
          Gets the original value of the specified object.
 PojoModel get(java.lang.String path)
          Gets the pojo model at the specified path
protected static java.lang.Class[] getArgumentTypes(java.lang.String propertyMethod)
          Retrieves the argument types from the passed String describing property method( either getter or setter) The describing String must be in the format: method(typeName1, typeName2,...)
protected static java.lang.Object[] getArgumentValues(java.lang.String element)
          Retrieves argument values from the given element.
protected static java.lang.String getElementIndex(java.lang.String element)
          Retrieves the collection index from the given element.
protected static java.lang.String getMethodName(java.lang.String propertyMethod)
          Retrieves the method name from the passed String describing property method.
static java.lang.String getPropertyKey(java.lang.String propertyName, java.lang.Class[] types)
          Gets the unique key for the given property
static java.lang.String getPropertyName(java.lang.String element)
          Retrieves the property name from the given String which must be in the format: property(arg1,arg2)[idx]"
 PojoModel getRootModel()
          Gets the root of the pojo model
static java.lang.Integer getSignatureKey(java.lang.Class[] types)
          Returns the key for the specified argument types which will be used in the getters/setters hashtable
static java.lang.Class[] getTypes(java.lang.Object[] objects)
          Returns the table constisting of the classes whose instances are the given objects.
 boolean isDirty(java.lang.String path)
          Indicates whether specified model node is dirty.
static boolean isPrimitiveType(java.lang.Class type)
          Determines whether the specified class is either a primitive or a primitive wrapper.
static boolean needsAdapter(java.lang.Class type)
          Indicates whether specified class needs an adapter
 PojoModel set(java.lang.String path, java.lang.Object value)
          Sets the model value for the specified child of the base node
 void setDirty()
          Marks all nodes of the pojo model tree as dirty.
 void setDirty(java.lang.String path)
          Marks the specified model node and its property subtree as dirty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PojoHelper

public PojoHelper(java.lang.Object model)
Creates a new instance of PojoHelper

Parameters:
model - the root of the pojo model
Method Detail

setDirty

public void setDirty(java.lang.String path)
Marks the specified model node and its property subtree as dirty.

Parameters:
path - the path to the model node to be marked

setDirty

public void setDirty()
Marks all nodes of the pojo model tree as dirty.


isDirty

public boolean isDirty(java.lang.String path)
Indicates whether specified model node is dirty.

Parameters:
path - the path to the model node to be queried
Returns:
true if the specified node is dirty, false otherwise

getRootModel

public PojoModel getRootModel()
Gets the root of the pojo model

Returns:
pojo model node

get

public PojoModel get(java.lang.String path)
Gets the pojo model at the specified path

Parameters:
path - the path to the child node
Returns:
pojo model node

set

public PojoModel set(java.lang.String path,
                     java.lang.Object value)
Sets the model value for the specified child of the base node

Parameters:
path - the path to the child node
value - the new value
Returns:
PojoModel node located at the specified path

needsAdapter

public static boolean needsAdapter(java.lang.Class type)
Indicates whether specified class needs an adapter

Parameters:
type - the Class to be checked
Returns:
true if the given class needs adapter, false whterwise

isPrimitiveType

public static boolean isPrimitiveType(java.lang.Class type)
Determines whether the specified class is either a primitive or a primitive wrapper.

Parameters:
type - the class to be queried
Returns:
true if the given class is a primitive, false otherwise

convertValue

protected static java.lang.Object convertValue(java.lang.String type,
                                               java.lang.String value)
Gets the original value of the specified object.

Parameters:
type - the type to which the value is to be converted
value - the value to be converted
Returns:
converted value

convertType

protected static java.lang.Class convertType(java.lang.String typeName)
Returns Class object whose simple name is in the given String.

Parameters:
typeName - the simple name of the type.

getMethodName

protected static java.lang.String getMethodName(java.lang.String propertyMethod)
Retrieves the method name from the passed String describing property method. The describing String must be in the format: method(typeName1, typeName2, ...)

Parameters:
propertyMethod - String describing property method
Returns:
the name of the method

getArgumentTypes

protected static java.lang.Class[] getArgumentTypes(java.lang.String propertyMethod)
Retrieves the argument types from the passed String describing property method( either getter or setter) The describing String must be in the format: method(typeName1, typeName2,...)

Parameters:
propertyMethod - String describing property method
Returns:
table containing argument types or null if something went wrong (e.g. one of the specified types was incorrect)

getArgumentValues

protected static java.lang.Object[] getArgumentValues(java.lang.String element)
Retrieves argument values from the given element. if there are any (e.g. for the element "finder(String:arg1, String:arg2)" this method will return table containig "arg1" and "arg2" values that have specified types.

Parameters:
element - the binding path element
Returns:
table containing argument values

getElementIndex

protected static java.lang.String getElementIndex(java.lang.String element)
Retrieves the collection index from the given element. (e.g. for the element "finder(arg1,arg2)[0]" this method will return "0")

Parameters:
element - the binding path element
Returns:
index in the collection

getPropertyName

public static java.lang.String getPropertyName(java.lang.String element)
Retrieves the property name from the given String which must be in the format: property(arg1,arg2)[idx]"

Parameters:
element - the binding path element
Returns:
the property name

getPropertyKey

public static java.lang.String getPropertyKey(java.lang.String propertyName,
                                              java.lang.Class[] types)
Gets the unique key for the given property

Parameters:
propertyName - the name of the property
types - the table containing the types of the property arguments.

getSignatureKey

public static java.lang.Integer getSignatureKey(java.lang.Class[] types)
Returns the key for the specified argument types which will be used in the getters/setters hashtable

Parameters:
argument - types signature
Returns:
key of the given argument types which can be used

getTypes

public static java.lang.Class[] getTypes(java.lang.Object[] objects)
Returns the table constisting of the classes whose instances are the given objects.

Parameters:
objects - the table consisting of the object whose classes are to retrieved
Returns:
requested table consisting of classes.