net.xoetrope.xui.data
Class XModelHelper

java.lang.Object
  extended by net.xoetrope.xui.data.XModelHelper
Direct Known Subclasses:
XModelHelper

public class XModelHelper
extends java.lang.Object

A helper to eliminate some typecasting with the XModel

Copyright (c) Xoetrope Ltd., 2002-2004

$Revision: 1.14 $

License: see License.txt

License: see license.txt


Constructor Summary
XModelHelper(java.lang.Object node)
          Construct a new helper node
 
Method Summary
static double addModels(java.lang.Object model1, java.lang.Object model2)
          Retrieve the double values of the models and return their sum
static XModel clone(java.lang.Object src)
          Clones the current model node.
static XModel clone(java.lang.Object src, boolean cloneSubNodes)
          Clones the current model node.
 XModel get()
          Do a get on the model and return its value as a model node
static XModel get(java.lang.Object baseNode)
          Do a get on the model and return its value as a model node
 XModel get(java.lang.String path)
          Get the model value for the specificed path and return its value as a model node
static XModel get(XProject project, java.lang.Object baseNode, java.lang.String path)
          Get the model value for the specificed path and return its value as a model node
static java.lang.String getAttrib(java.lang.Object model, java.lang.String name)
          Retrieve the named attribute of the passed model
static boolean getBooleanValue(java.lang.Object model)
          Retrieves the value of the passed model and converts it to a boolean
static boolean getBooleanValue(java.lang.Object model, java.lang.String att)
          Retrieves the value of the specified attribute from the passed model and converts it to a boolean
static double getDouble(java.lang.Object model, java.lang.String path)
          Deprecated. use getDoubleValue( model, att, 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.
static double getDouble(java.lang.Object model, java.lang.String path, char decimalSeparator, char groupingSeparator)
          Retrieves the value attribute of the passed model and converts it to a double
static double getDouble(java.lang.Object model, java.lang.String path, double defaultValue)
          Deprecated. use getDoubleValue( model, att, defaultValue, 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.
static double getDouble(java.lang.Object model, java.lang.String path, double defaultValue, char decimalSeparator, char groupingSeparator)
          Deprecated. use getDoubleValue( model, att, defaultValue, 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.
static double getDoubleValue(java.lang.Object model)
          Retrieves the value of the passed model and converts it to a double
static double getDoubleValue(java.lang.Object model, java.lang.String att)
          Deprecated. use getDoubleValue( model, att, 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.
static double getDoubleValue(java.lang.Object model, java.lang.String att, char decimalSeparator, char groupingSeparator)
          Retrieves the named attribute of the passed model and converts it to a double
static double getDoubleValue(java.lang.Object model, java.lang.String att, double defaultValue)
          Deprecated. use getDoubleValue( model, att, defaultValue, 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.
static double getDoubleValue(java.lang.Object model, java.lang.String att, double defaultValue, char decimalSeparator, char groupingSeparator)
          Deprecated. use getDoubleValue( model, att, defaultValue, 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.
static XModel getFirstChild(XModel model, java.lang.String value)
          Get the first child node that matches the speciofied value
static XModel getFirstChild(XModel model, java.lang.String path, java.lang.String value)
          Get the first child node that matches the speciofied value
static int getInt(java.lang.Object model)
          Retrieves the value of the passed model and converts it to an int
static int getInt(java.lang.Object model, java.lang.String path)
          Retrieves the value of the passed model and converts it to an int
static int getInt(java.lang.Object model, java.lang.String path, int defaultValue)
          Retrieves the value of the passed model and converts it to an int
static int getIntValue(java.lang.Object model)
          Retrieves the value of the passed model and converts it to an int
static int getIntValue(java.lang.Object model, java.lang.String att)
          Retrieves the named attribute of the passed model and converts it to an int
static int getIntValue(java.lang.Object model, java.lang.String att, int defaultValue)
          Retrieves the named attribute of the passed model and converts it to an int.
static XModel getNextSibling(XModel modelNode, boolean wrap)
          Get the next sibling node
static XModel getParent(java.lang.Object model, int level)
          Retrive the parent of the passed model.
static int getPositionInModel(java.lang.Object refModel)
          Retrieves the passed models position within its parent
static XModel getPrevSibling(XModel modelNode, boolean wrap)
          Get the previous sibling node
static XModel getSibling(boolean forward, XModel modelNode, boolean wrap)
          Get the sibling node
static java.lang.String getString(java.lang.Object baseNode, java.lang.String path)
          Get the model value for the specificed path and return its value as a model node
static java.lang.String getString(java.lang.String path)
          Get the model value for the specificed path and return its value as a model node
static java.lang.String getString(XProject project, java.lang.Object baseNode, java.lang.String path)
          Get the model value for the specificed path and return its value as a model node
static java.lang.String getTempVar(java.lang.String name)
          Retrieve the value of the named node within the 'temp' section of the model
static java.lang.String getValue(java.lang.Object model)
          Retrieves the string value of the passed model
static boolean isChildNode(java.lang.Object ref, java.lang.Object parent)
          Determines whether the ref XModel is a child of the parent XModel.
static void merge(java.lang.Object mainmodel, java.lang.Object newmodel)
          merge the conents of one model with another.
static double multipyAttribs(java.lang.Object model, java.lang.String attrib1, java.lang.String attrib2)
          Retrieve the double values of the attributes within the passed model and return their product
static double multipyModels(java.lang.Object model1, java.lang.Object model2)
          Retrieve the double values of the models and return their product
 void set(java.lang.Object value)
          Set the model value for this node
 void set(java.lang.String path, java.lang.Object value)
          Set the model value for the specificed path
static void set(XProject project, java.lang.Object baseNode, java.lang.String path, java.lang.Object value)
          Set the model value for the specificed child of the base node
static void setAttrib(java.lang.Object model, java.lang.String name, java.lang.Object value)
          Set the value of the named attribute within the passed model
static void setCurrentProject(XProject project)
          Set the current project, used for methods that do not provide a project as an argument
static void setTempVar(java.lang.String name, java.lang.String value)
          Set the value of a node in the 'temp' section of the model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XModelHelper

public XModelHelper(java.lang.Object node)
Construct a new helper node

Parameters:
node - the model node on which to operate
Method Detail

getNextSibling

public static XModel getNextSibling(XModel modelNode,
                                    boolean wrap)
Get the next sibling node

Parameters:
wrap - true to wrap to the first node if the request node is the last node
modelNode - the node whose next sibling is requested
Returns:
the model node

getPrevSibling

public static XModel getPrevSibling(XModel modelNode,
                                    boolean wrap)
Get the previous sibling node

Parameters:
wrap - true to wrap to the last node if the request node is the first node
modelNode - the node whose next sibling is requested
Returns:
the model node

getSibling

public static XModel getSibling(boolean forward,
                                XModel modelNode,
                                boolean wrap)
Get the sibling node

Parameters:
forward - true to search in a forward direction (find the next node)
wrap - true to wrap to the first/last node if the request node is the last/first node
modelNode - the node whose next sibling is requested
Returns:
the model node

setCurrentProject

public static void setCurrentProject(XProject project)
Set the current project, used for methods that do not provide a project as an argument

Parameters:
project - the project that owns the model being queried

get

public XModel get()
Do a get on the model and return its value as a model node

Returns:
the model node

get

public XModel get(java.lang.String path)
Get the model value for the specificed path and return its value as a model node

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

get

public static XModel get(java.lang.Object baseNode)
Do a get on the model and return its value as a model node

Parameters:
baseNode -
Returns:
the model node

get

public static XModel get(XProject project,
                         java.lang.Object baseNode,
                         java.lang.String path)
Get the model value for the specificed path and return its value as a model node

Parameters:
baseNode - the base node from which to look for the specified path
path - the path to the child node
Returns:
the model node

getString

public static java.lang.String getString(XProject project,
                                         java.lang.Object baseNode,
                                         java.lang.String path)
Get the model value for the specificed path and return its value as a model node

Parameters:
baseNode - the base node from which to look for the specified path
path - the path to the child node
Returns:
the model node

getString

public static java.lang.String getString(java.lang.Object baseNode,
                                         java.lang.String path)
Get the model value for the specificed path and return its value as a model node

Parameters:
baseNode - the base node from which to look for the specified path
path - the path to the child node
Returns:
the model node

getString

public static java.lang.String getString(java.lang.String path)
Get the model value for the specificed path and return its value as a model node

Parameters:
baseNode - the base node from which to look for the specified path
path - the path to the child node
Returns:
the model node

set

public void set(java.lang.Object value)
Set the model value for this node

Parameters:
value - the new value

set

public void set(java.lang.String path,
                java.lang.Object value)
Set the model value for the specificed path

Parameters:
path - the path to the child node
value - the new value

set

public static void set(XProject project,
                       java.lang.Object baseNode,
                       java.lang.String path,
                       java.lang.Object value)
Set the model value for the specificed child of the base node

Parameters:
baseNode - the node whose child is being modified
path - the path to the child node
value - the new value

clone

public static XModel clone(java.lang.Object src)
Clones the current model node. Need to call cloneChildren which iterated the children and creates new instances of the children. The call to super.clone() does not create new instance of the child nodes.

Parameters:
src - The XModel to be cloned
Returns:
the newly created XModel.

clone

public static XModel clone(java.lang.Object src,
                           boolean cloneSubNodes)
Clones the current model node. Need to call cloneChildren which iterated the children and creates new instances of the children. The call to super.clone() does not create new instance of the child nodes.

Parameters:
src - The XModel to be cloned
cloneSubNodes - boolean to indicate whether the child nodes should be included in the cloning.
Returns:
the newly created XModel.

merge

public static void merge(java.lang.Object mainmodel,
                         java.lang.Object newmodel)
merge the conents of one model with another. Calls cloneChildren which transfers the data.

Parameters:
mainmodel - The model to which the newmodel content will be merged
newmodel - the model which contains the data to be merge with the mainModel.

getAttrib

public static java.lang.String getAttrib(java.lang.Object model,
                                         java.lang.String name)
Retrieve the named attribute of the passed model

Parameters:
model - the model whose attribute is required
name - the name of the required attribute
Returns:
The named attribute of the passed XModel

setAttrib

public static void setAttrib(java.lang.Object model,
                             java.lang.String name,
                             java.lang.Object value)
Set the value of the named attribute within the passed model

Parameters:
model - the XModel whose attribute is to be set
name - the name of the attribute which is to be set
value - the new value of the attribute

getParent

public static XModel getParent(java.lang.Object model,
                               int level)
Retrive the parent of the passed model. Move up the model hierarchy by the amount specified by the level parameter

Parameters:
model - the model whose parent is required
level - the number of parents to be navigated
Returns:
The parent of the passed XModel

getPositionInModel

public static int getPositionInModel(java.lang.Object refModel)
Retrieves the passed models position within its parent

Parameters:
refModel - the model whose position is required
Returns:
The position within the parent model

getValue

public static java.lang.String getValue(java.lang.Object model)
Retrieves the string value of the passed model

Parameters:
model - the model whose value is required
Returns:
the String value of the model

getDouble

public static double getDouble(java.lang.Object model,
                               java.lang.String path)
Deprecated. use getDoubleValue( model, att, 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.

Retrieves the value attribute of the passed model and converts it to a double.

Parameters:
model - the model whose value is required
path - the model path for the desired node
Returns:
the double value of the model

getDouble

public static double getDouble(java.lang.Object model,
                               java.lang.String path,
                               char decimalSeparator,
                               char groupingSeparator)
Retrieves the value attribute of the passed model and converts it to a double

Parameters:
model - the model whose value is required
path - the model path for the desired node
decimalSeparator - the decimal separator
groupingSeparator - the grouping (thousands) separator
Returns:
the double value of the model

getDouble

public static double getDouble(java.lang.Object model,
                               java.lang.String path,
                               double defaultValue)
Deprecated. use getDoubleValue( model, att, defaultValue, 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.

Retrieves the value attribute of the passed model and converts it to a double. double. If there is a problem converting the value return the defaultValue

Parameters:
defaultValue - The double value to be returned if there is an exception
model - the model whose value is required
path - the model path for the desired node
Returns:
the double value of the model

getDouble

public static double getDouble(java.lang.Object model,
                               java.lang.String path,
                               double defaultValue,
                               char decimalSeparator,
                               char groupingSeparator)
Deprecated. use getDoubleValue( model, att, defaultValue, 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.

Retrieves the value attribute of the passed model and converts it to a double. If there is a problem converting the value return the defaultValue

Parameters:
defaultValue - The double value to be returned if there is an exception
model - the model whose value is required
path - the model path for the desired node
decimalSeparator - the decimal separator
groupingSeparator - the grouping (thousands) separator
Returns:
the double value of the model

getDoubleValue

public static double getDoubleValue(java.lang.Object model)
Retrieves the value of the passed model and converts it to a double

Parameters:
model - the model whose value is required
Returns:
the double value of the model

getDoubleValue

public static double getDoubleValue(java.lang.Object model,
                                    java.lang.String att)
Deprecated. use getDoubleValue( model, att, 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.

Retrieves the named attribute of the passed model and converts it to a double

Parameters:
model - the model whose value is required
att - the name of the attribute being requested
Returns:
the double value of the model

getDoubleValue

public static double getDoubleValue(java.lang.Object model,
                                    java.lang.String att,
                                    char decimalSeparator,
                                    char groupingSeparator)
Retrieves the named attribute of the passed model and converts it to a double

Parameters:
model - the model whose value is required
att - the name of the attribute being requested
decimalSeparator - the decimal separator
groupingSeparator - the grouping (thousands) separator
Returns:
the double value of the model

getDoubleValue

public static double getDoubleValue(java.lang.Object model,
                                    java.lang.String att,
                                    double defaultValue)
Deprecated. use getDoubleValue( model, att, defaultValue, 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.

Retrieves the named attribute of the passed model and converts it to a double. If there is a problem converting the value return the defaultValue

Parameters:
defaultValue - The double value to be returned if there is an exception
model - the model whose value is required
att - the name of the attribute being requested
Returns:
the double value of the model

getDoubleValue

public static double getDoubleValue(java.lang.Object model,
                                    java.lang.String att,
                                    double defaultValue,
                                    char decimalSeparator,
                                    char groupingSeparator)
Deprecated. use getDoubleValue( model, att, defaultValue, 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.

Retrieves the named attribute of the passed model and converts it to a double. If there is a problem converting the value return the defaultValue

Parameters:
defaultValue - The double value to be returned if there is an exception
model - the model whose value is required
att - the name of the attribute being requested
decimalSeparator - the decimal separator
groupingSeparator - the grouping (thousands) separator
Returns:
the double value of the model

getInt

public static int getInt(java.lang.Object model,
                         java.lang.String path)
Retrieves the value of the passed model and converts it to an int

Parameters:
model - the model whose value is required
path - the model path for the desired node
Returns:
the int value of the model

getInt

public static int getInt(java.lang.Object model,
                         java.lang.String path,
                         int defaultValue)
Retrieves the value of the passed model and converts it to an int

Parameters:
model - the model whose value is required
path - the model path for the desired node
Returns:
the int value of the model

getInt

public static int getInt(java.lang.Object model)
Retrieves the value of the passed model and converts it to an int

Parameters:
model - the model whose value is required
Returns:
the int value of the model

getIntValue

public static int getIntValue(java.lang.Object model)
Retrieves the value of the passed model and converts it to an int

Parameters:
model - the model whose value is required
Returns:
the int value of the model

getIntValue

public static int getIntValue(java.lang.Object model,
                              java.lang.String att)
Retrieves the named attribute of the passed model and converts it to an int

Parameters:
model - the model whose value is required
att - the name of the attribute being requested
Returns:
the int value of the model

getIntValue

public static int getIntValue(java.lang.Object model,
                              java.lang.String att,
                              int defaultValue)
Retrieves the named attribute of the passed model and converts it to an int. If there is a problem converting the value return the defaultValue

Parameters:
defaultValue - The value to be returned if there is a problem
model - the model whose value is required
att - the name of the attribute being requested
Returns:
the int value of the model

addModels

public static double addModels(java.lang.Object model1,
                               java.lang.Object model2)
Retrieve the double values of the models and return their sum

Parameters:
model1 - model whose value is to be added
model2 - model whose value is to be added
Returns:
the summed values

multipyModels

public static double multipyModels(java.lang.Object model1,
                                   java.lang.Object model2)
Retrieve the double values of the models and return their product

Parameters:
model1 - model whose value is to be multiplied
model2 - model whose value is to be multiplied
Returns:
the multiplied values

multipyAttribs

public static double multipyAttribs(java.lang.Object model,
                                    java.lang.String attrib1,
                                    java.lang.String attrib2)
Retrieve the double values of the attributes within the passed model and return their product

Parameters:
model - model whose value is to be multiplied
attrib1 - the name of the attribute to be multiplied
attrib2 - the name of the attribute to be multiplied
Returns:
the multiplied values

setTempVar

public static void setTempVar(java.lang.String name,
                              java.lang.String value)
Set the value of a node in the 'temp' section of the model

Parameters:
name - the name of the node to be set
value - the String value which is to be set

getTempVar

public static java.lang.String getTempVar(java.lang.String name)
Retrieve the value of the named node within the 'temp' section of the model

Parameters:
name - the name of the node which is to be retrieved
Returns:
the value of the node

getBooleanValue

public static boolean getBooleanValue(java.lang.Object model)
Retrieves the value of the passed model and converts it to a boolean

Parameters:
model - the model whose value is required
Returns:
the boolean value of the model

getBooleanValue

public static boolean getBooleanValue(java.lang.Object model,
                                      java.lang.String att)
Retrieves the value of the specified attribute from the passed model and converts it to a boolean

Parameters:
model - the model whose value is required
att - the name of the attribute to be converted
Returns:
the boolean value of the model

isChildNode

public static boolean isChildNode(java.lang.Object ref,
                                  java.lang.Object parent)
Determines whether the ref XModel is a child of the parent XModel. It does this by iterating the parent of the ref XModel until the parent is found or until no parent exists

Parameters:
ref - the XModel whose parentage is in question
parent - the XModel who is making a claim on the child
Returns:
a boolean indicating whether it is a parent or not

getFirstChild

public static XModel getFirstChild(XModel model,
                                   java.lang.String path,
                                   java.lang.String value)
Get the first child node that matches the speciofied value

Parameters:
path - the model path for the desired node
value - the value of the value attribute
Returns:
the first child node or null if not found

getFirstChild

public static XModel getFirstChild(XModel model,
                                   java.lang.String value)
Get the first child node that matches the speciofied value

Parameters:
value - the value of the value attribute
Returns:
the first child node or null if not found