net.xoetrope.optional.service
Class XServiceModelNode

java.lang.Object
  extended by net.xoetrope.xui.data.XModel
      extended by net.xoetrope.optional.service.XServiceModelNode

public class XServiceModelNode
extends XModel

Models a service as a model node. Getting the node value causes the service to be invoked. The node attributes are used as the arguments for the service call.

Copyright (c) Xoetrope Ltd., 2001-2006, see license.txt for details


Field Summary
protected  ServiceProxy callProxy
           
protected  boolean dirty
           
protected  long expires
           
protected  java.lang.String serviceId
           
 
Fields inherited from class net.xoetrope.xui.data.XModel
parentModel, tagName
 
Constructor Summary
XServiceModelNode()
          Set the dirty flag to true
 
Method Summary
 java.lang.Object append(java.lang.String id)
          Append a new node with the specified name.
 void append(XModel newObject)
          Append a node
 java.lang.Object get()
          Start off the call through the route
 XModel get(int i)
          Get the XModel at element i
 java.lang.Object get(ServiceContext context)
          Start off the call through the route using a session context
 java.lang.String getAttribName(int i)
          Get the name of an argument
 int getAttribute(java.lang.String argName)
          Look up an argument name
 java.lang.Object getAttribValue(int idx)
          Retrieve the value of the argument at the specified index
 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.
 java.lang.String getId()
          Retrive the serviceId
 ServiceProxy getServiceProxy()
          Get the service proxy that implements this service call
 ServiceProxy getServiceProxy(java.lang.String reqdClass)
          Get the service proxy that implements this service call
 int getStatus()
          Get the call status, for example on a http request this should give the response code
 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)
          Gets the value attribute of the specified node as a string.
 int hashCode()
          The hashcode of the serviceID String
 void remove(XModel child)
           
 void set(java.lang.Object s)
          Sets the model value
 void set(java.lang.String attribName, java.lang.Object newObject)
          Set the named attribute value of this XModel node.
 void setAttribValue(int i, java.lang.Object value)
          Set the value of an argument
 void setAttribValue(int i, java.lang.String attribName, java.lang.Object value)
          Set the value of an argument
 void setAttribValue(java.lang.String name, java.lang.Object value)
          Set the value of an argument
 void setNumAttributes(int num)
          Set the number of arguments initially used in the route
 void setupService(java.lang.String methodName, ServiceProxy routeService, java.lang.String[] argNames)
          Setup the service with the passed name.
protected  void sync()
          Syncs the model with the service response is the request has been changed or if the node has timed out.
 
Methods inherited from class net.xoetrope.xui.data.XModel
addModelListener, clear, fireModelUpdated, get, getNumAttributes, getNumChildren, getParent, getTagName, hasAutoId, hasAutoId, prefixOutputPath, removeChildren, reset, resetAttributes, setId, setNumChildren, setParent, setTagName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dirty

protected boolean dirty

expires

protected long expires

serviceId

protected java.lang.String serviceId

callProxy

protected ServiceProxy callProxy
Constructor Detail

XServiceModelNode

public XServiceModelNode()
Set the dirty flag to true

Method Detail

setupService

public void setupService(java.lang.String methodName,
                         ServiceProxy routeService,
                         java.lang.String[] argNames)
Setup the service with the passed name. The routeService parameter is the first ServiceProxy in the route. The argNames parameter contains the names of the arguments expected by the service

Parameters:
methodName - The name of the service
routeService - the first ServiceProxy in the route
argNames - the argument names expected by the service

getServiceProxy

public ServiceProxy getServiceProxy()
Get the service proxy that implements this service call

Returns:
the service proxy

getServiceProxy

public ServiceProxy getServiceProxy(java.lang.String reqdClass)
Get the service proxy that implements this service call

Returns:
the service proxy

hashCode

public int hashCode()
The hashcode of the serviceID String

Specified by:
hashCode in class XModel
Returns:
The hashcode of the serviceID String

sync

protected void sync()
Syncs the model with the service response is the request has been changed or if the node has timed out.


get

public java.lang.Object get()
Start off the call through the route

Specified by:
get in class XModel
Returns:
the result of the call

get

public java.lang.Object get(ServiceContext context)
Start off the call through the route using a session context

Parameters:
context - the ServiceContext containing context arguments
Returns:
The result of the service call

append

public java.lang.Object append(java.lang.String id)
Description copied from class: XModel
Append a new node with the specified name. This method does not replace any existing nodes.

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

get

public XModel get(int i)
Description copied from class: XModel
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

append

public void append(XModel newObject)
Description copied from class: XModel
Append a node

Specified by:
append in class XModel
Parameters:
newObject - the child node

set

public void set(java.lang.Object s)
Description copied from class: XModel
Sets the model value

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

set

public void set(java.lang.String attribName,
                java.lang.Object newObject)
Description copied from class: XModel
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:
attribName - The path to the XModel in the format 'base/foo
newObject - The new value of the XModel

getId

public java.lang.String getId()
Retrive the serviceId

Specified by:
getId in class XModel
Returns:
the service's serviceID

getAttribName

public java.lang.String getAttribName(int i)
Get the name of an argument

Specified by:
getAttribName in class XModel
Parameters:
i - The index of the attribute whose name is required
Returns:
the argument name

getAttribute

public int getAttribute(java.lang.String argName)
Look up an argument name

Specified by:
getAttribute in class XModel
Parameters:
argName - the argument name
Returns:
the argument index or -1 if not found

setAttribValue

public void setAttribValue(int i,
                           java.lang.Object value)
Set the value of an argument

Specified by:
setAttribValue in class XModel
Parameters:
i - the argument index
value - the new argument value

setAttribValue

public void setAttribValue(java.lang.String name,
                           java.lang.Object value)
Set the value of an argument

Parameters:
name - the name of the argument to be set
value - The value of be applied to the attribute

setAttribValue

public void setAttribValue(int i,
                           java.lang.String attribName,
                           java.lang.Object value)
Set the value of an argument

Specified by:
setAttribValue in class XModel
Parameters:
i - the argument index
attribName - the name of the attribute
value - the new argument value

getValueAsDouble

public double getValueAsDouble(java.lang.String elementName)
Description copied from class: XModel
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

getAttribValueAsInt

public int getAttribValueAsInt(int i)
Description copied from class: XModel
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

getValueAsInt

public int getValueAsInt(java.lang.String elementName)
Description copied from class: XModel
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

getAttribValueAsString

public java.lang.String getAttribValueAsString(int i)
Description copied from class: XModel
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

getValueAsString

public java.lang.String getValueAsString(java.lang.String elementName)
Gets the value attribute of the specified node as a string.

Specified by:
getValueAsString in class XModel
Parameters:
elementName -
Returns:
the value as a string

getAttribValue

public java.lang.Object getAttribValue(int idx)
Retrieve the value of the argument at the specified index

Specified by:
getAttribValue in class XModel
Parameters:
idx - the index of the required argument
Returns:
the requested argument value

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.

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
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

remove

public void remove(XModel child)

setNumAttributes

public void setNumAttributes(int num)
Set the number of arguments initially used in the route

Overrides:
setNumAttributes in class XModel
Parameters:
num - the number of arguments

getStatus

public int getStatus()
Get the call status, for example on a http request this should give the response code

Returns:
the status or response value (if appropriate)