com.arsdigita.util.parameter
Class AbstractParameter

java.lang.Object
  extended bycom.arsdigita.util.parameter.AbstractParameter
All Implemented Interfaces:
Parameter
Direct Known Subclasses:
BooleanParameter, ClassParameter, EnumerationParameter, FileParameter, IntegerParameter, MapParameter, StringParameter

public abstract class AbstractParameter
extends Object
implements Parameter

Subject to change. A base implementation of the Parameter interface. It offers subclasses use of the Apache BeanUtils framework, should they opt to use it. Methods of the form doXXX are extension points for subclasses. The isRequired() and getDefaultValue() methods may also be overriden.

Version:
$Id: //core-platform/dev/src/com/arsdigita/util/parameter/AbstractParameter.java#8 $
Author:
Justin Ross <jross@redhat.com>
See Also:
Parameter

Field Summary
static String versionId
           
 
Fields inherited from interface com.arsdigita.util.parameter.Parameter
OPTIONAL, REQUIRED
 
Constructor Summary
protected AbstractParameter(String name, Class type)
          Constructs a new parameter using the beanutils converter for type type.
protected AbstractParameter(String name, int multiplicity, Object defaalt)
          Constructs a new parameter with the default value defaalt.
protected AbstractParameter(String name, int multiplicity, Object defaalt, Class type)
          Constructs a new parameter with the default value defaalt and using the beanutils converter registered for type.
 
Method Summary
protected  Object doRead(ParameterReader reader, ErrorList errors)
          Reads the value of the parameter from reader, unmarshals it, and returns it.
protected  void doValidate(Object value, ErrorList errors)
          Validates value, placing any validation errors in errors.
protected  void doWrite(ParameterWriter writer, Object value)
          Marshals and writes value to writer.
 Object getDefaultValue()
          Parameter users may override this method to achieve dynamic defaulting.
 ParameterInfo getInfo()
          Gets metadata associated with the parameter if it is available.
 String getName()
          Gets the name of the parameter.
 boolean isRequired()
          Parameter users may override this method to make the multiplicity of the parameter dependent on the multiplicity of related parameters.
protected  String marshal(Object value)
          Converts value to a representative String, which is returned.
 Object read(ParameterReader reader, ErrorList errors)
          Calls doRead(ParameterReader,ErrorList).
 void setInfo(ParameterInfo info)
          Sets the optional parameter metadata to info.
 String toString()
          Returns a String representation of this object.
protected  Object unmarshal(String value, ErrorList errors)
          Converts a literal String value, value, to a Java object, which is returned.
 void validate(Object value, ErrorList errors)
          Calls doValidate(Object,ErrorList) if value is not null.
 void write(ParameterWriter writer, Object value)
          Calls doWrite(ParameterWriter,Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

AbstractParameter

protected AbstractParameter(String name,
                            int multiplicity,
                            Object defaalt,
                            Class type)
Constructs a new parameter with the default value defaalt and using the beanutils converter registered for type.

Parameters:
name - The name of the parameter; it cannot be null
multiplicity - The multiplicity type of the parameter
defaalt - The default value to use if the value is unset or is null
type - The Class whose beanutils converter will be used to unmarshal literal values

AbstractParameter

protected AbstractParameter(String name,
                            int multiplicity,
                            Object defaalt)
Constructs a new parameter with the default value defaalt.

Parameters:
name - The name of the parameter; it cannot be null
multiplicity - The multiplicity type of the parameter
defaalt - The default value to use if the value is unset or is null

AbstractParameter

protected AbstractParameter(String name,
                            Class type)
Constructs a new parameter using the beanutils converter for type type. By default, the parameter is required and has no default.

Parameters:
name - The name of the parameter; it cannot be null
type - The Class whose beanutils converter will be used to unmarshal literal values
Method Detail

isRequired

public boolean isRequired()
Parameter users may override this method to make the multiplicity of the parameter dependent on the multiplicity of related parameters.

Specified by:
isRequired in interface Parameter
Returns:
true if the parameter cannot be null; false if it can be null
See Also:
Parameter.isRequired()

getName

public final String getName()
Description copied from interface: Parameter
Gets the name of the parameter.

Specified by:
getName in interface Parameter
Returns:
The String parameter name; it cannot be null
See Also:
Parameter.getName()

getDefaultValue

public Object getDefaultValue()
Parameter users may override this method to achieve dynamic defaulting.

Specified by:
getDefaultValue in interface Parameter
Returns:
The fallback value; it may be null
See Also:
Parameter.getDefaultValue()

getInfo

public final ParameterInfo getInfo()
Description copied from interface: Parameter
Gets metadata associated with the parameter if it is available.

Specified by:
getInfo in interface Parameter
Returns:
The ParameterInfo object; it may be null
See Also:
Parameter.getInfo()

setInfo

public final void setInfo(ParameterInfo info)
Description copied from interface: Parameter
Sets the optional parameter metadata to info.

Specified by:
setInfo in interface Parameter
Parameters:
info - The ParameterInfo to associate; it may be null
See Also:
Parameter.setInfo(ParameterInfo)

read

public final Object read(ParameterReader reader,
                         ErrorList errors)
Calls doRead(ParameterReader,ErrorList).

Specified by:
read in interface Parameter
Parameters:
reader - The ParameterReader from which to recover a string literal value; it cannot be null
errors - The ErrorList in which to collect any errors encountered; it cannot be null
Returns:
The Java object value of the parameter
See Also:
Parameter.read(ParameterReader,ErrorList)

doRead

protected Object doRead(ParameterReader reader,
                        ErrorList errors)
Reads the value of the parameter from reader, unmarshals it, and returns it. If any errors are encountered, they are added to errors. If the literal string value from reader is not null, this method delegates to unmarshal(String,ErrorList). This implementation is suited to a parameter with a singular scalar value. Subclasses that are compound parameters should override this method to delegate to child parameters.

Parameters:
reader - The ParameterReader that will supply the literal stored value for this parameter; it cannot be null
errors - The ErrorList that will trap any errors encountered; it cannot be null

unmarshal

protected Object unmarshal(String value,
                           ErrorList errors)
Converts a literal String value, value, to a Java object, which is returned.

Parameters:
value - The String value to convert from; it cannot be null
errors - An ErrorList that holds any errors encountered during unmarshaling; it cannot be null

validate

public final void validate(Object value,
                           ErrorList errors)
Calls doValidate(Object,ErrorList) if value is not null. Otherwise, if the value is required and null, an error is added to errors and doValidate is not called.

Specified by:
validate in interface Parameter
Parameters:
value - The value to validate; this is typically the value returned by Parameter.read(com.arsdigita.util.parameter.ParameterReader, com.arsdigita.util.parameter.ErrorList); it may be null
errors - The ErrorList in which to collect any errors encountered; it cannot be null
See Also:
Parameter.validate(Object,ErrorList)

doValidate

protected void doValidate(Object value,
                          ErrorList errors)
Validates value, placing any validation errors in errors. This particular implementation does nothing. Subclasses are expected to add specific validation behaviors.

Parameters:
value - The value to validate; it cannot be null
errors - The ErrorList that traps validation errors; it cannot be null

write

public final void write(ParameterWriter writer,
                        Object value)
Calls doWrite(ParameterWriter,Object).

Specified by:
write in interface Parameter
Parameters:
writer - The ParameterWriter that will take the marshaled value and store it; it cannot be null
value - The Java object value of the parameter
See Also:
Parameter.write(ParameterWriter,Object)

doWrite

protected void doWrite(ParameterWriter writer,
                       Object value)
Marshals and writes value to writer. This implementation is suited to a parameter with a singular scalar value. Subclasses that are compound parameters should override this method to delegate to child parameters.

Parameters:
writer - The ParameterWriter we write to; it cannot be null
value - The value to write; it may be null

marshal

protected String marshal(Object value)
Converts value to a representative String, which is returned.

Parameters:
value - The value to marshal; it may be null
Returns:
The String literal representation of value; it may be null

toString

public String toString()
Returns a String representation of this object.

Returns:
super.toString() + "," + getName() + "," + isRequired()


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC