com.flexive.shared.configuration.parameters
Class ObjectParameter<T>

java.lang.Object
  extended by com.flexive.shared.configuration.parameters.ParameterImpl<T>
      extended by com.flexive.shared.configuration.parameters.ObjectParameter<T>
Type Parameters:
T - type of the object stored in the parameter
All Implemented Interfaces:
Parameter<T>, java.io.Serializable

 class ObjectParameter<T>
extends ParameterImpl<T>

Generic Object parameter wrapper. Takes any java object, serializes it to XML (currently using XStream), and stores it in the configuration.

Author:
Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Constructor Summary
ObjectParameter(ParameterData<T> parameter, java.lang.Class<T> cls, boolean registerParameter)
          Creates a new object parameter definition.
ObjectParameter(ParameterData<T> parameter, java.lang.Class<T> cls, boolean registerParameter, com.thoughtworks.xstream.XStream xStream)
          Creates a new object parameter definition.
 
Method Summary
 Parameter<T> copy()
          Return a copy of this parameter instance.
protected  ObjectParameter<T> create(ParameterData<T> parameterData, boolean registerParameter)
           
 java.lang.String getDatabaseValue(T value)
          Convert the given value to a string that will be stored in the configuration.
static com.thoughtworks.xstream.XStream getDefaultXStream()
           
 T getValue(java.lang.Object dbValue)
          Convert the given database value (in string representation) to an object of type T.
 boolean isValid(T value)
          Returns true if the given value is a valid configuration value (e.g.
 
Methods inherited from class com.flexive.shared.configuration.parameters.ParameterImpl
freeze, getData, getDefaultValue, getKey, getPath, getScope, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectParameter

public ObjectParameter(ParameterData<T> parameter,
                       java.lang.Class<T> cls,
                       boolean registerParameter)
Creates a new object parameter definition.

Parameters:
parameter - parameter data
cls - the object's class
registerParameter - if the parameter should be registered in the static parameter table (don't do this for non-static parameter declarations)

ObjectParameter

public ObjectParameter(ParameterData<T> parameter,
                       java.lang.Class<T> cls,
                       boolean registerParameter,
                       com.thoughtworks.xstream.XStream xStream)
Creates a new object parameter definition.

Parameters:
parameter - parameter data
cls - the object's class
xStream - xStream instance to be used for loading and storing values for this parameter. If null, the default xStream instance stored in this class will be used.
registerParameter - if the parameter should be registered in the static parameter table (don't do this for non-static parameter declarations)
Method Detail

copy

public Parameter<T> copy()
Return a copy of this parameter instance. If this instance was frozen, the new object will be "unfrozen". The ParameterData instance will not be cloned, however you can replace it with a new instance, e.g. to update the parameter key.

Returns:
a copy of this parameter instance

create

protected ObjectParameter<T> create(ParameterData<T> parameterData,
                                    boolean registerParameter)

getValue

public T getValue(java.lang.Object dbValue)
Convert the given database value (in string representation) to an object of type T.

Parameters:
dbValue - the value to be converted
Returns:
dbValue as type T.

getDatabaseValue

public java.lang.String getDatabaseValue(T value)
Convert the given value to a string that will be stored in the configuration.

Specified by:
getDatabaseValue in interface Parameter<T>
Overrides:
getDatabaseValue in class ParameterImpl<T>
Parameters:
value - the parameter value to be stored
Returns:
the value's string representation
See Also:
Parameter.getValue(Object)

isValid

public boolean isValid(T value)
Returns true if the given value is a valid configuration value (e.g. primitive parameters may not be null).

Specified by:
isValid in interface Parameter<T>
Overrides:
isValid in class ParameterImpl<T>
Parameters:
value - the value to be checked
Returns:
true if the given value is a valid configuration value

getDefaultXStream

public static com.thoughtworks.xstream.XStream getDefaultXStream()