net.sf.cb2java.copybook.data
Class Data

java.lang.Object
  extended bynet.sf.cb2java.copybook.data.Data
Direct Known Subclasses:
GroupData, ValueData

public abstract class Data
extends java.lang.Object

The base type for all Data elements

Author:
James Watson

Constructor Summary
Data(Element definition)
          constructor
 
Method Summary
abstract  java.util.List getChildren()
          returns all the children of this item, if there are any
 Element getDefinition()
          the underlying type definition of the element
 java.lang.String getName()
          returns the name of the type that defines this element
abstract  java.lang.Object getValue()
          returns the Object as it's 'natural' Java type
abstract  boolean isLeaf()
          Returns whether this element is a leaf element.
 void setValue(java.lang.Object data)
          Sets the internal value of this item.
 void setValue(java.lang.String data)
          sets the value from an input String.
protected abstract  void setValueImpl(java.lang.Object data)
          called by setData after validate is called
abstract  java.lang.String toString(java.lang.String indent)
          gives a string representation of this element with the given indention
protected abstract  java.lang.Object translate(java.lang.String data)
          Converts the String to the underlying Data type's 'natural' type.
 void validate(java.lang.Object data)
          Validates the data passed in using the underlying definition
 void write(java.io.OutputStream stream)
          writes this Data instance to the stream as COBOL application data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Data

public Data(Element definition)
constructor

Parameters:
definition - the underlying type definition
Method Detail

getName

public java.lang.String getName()
returns the name of the type that defines this element


isLeaf

public abstract boolean isLeaf()
Returns whether this element is a leaf element. i.e. returns true if it is not a group.

Returns:
whether this element is a leaf element

getChildren

public abstract java.util.List getChildren()
returns all the children of this item, if there are any


toString

public abstract java.lang.String toString(java.lang.String indent)
gives a string representation of this element with the given indention

Parameters:
indent - the string used to indent

getDefinition

public Element getDefinition()
the underlying type definition of the element


getValue

public abstract java.lang.Object getValue()
returns the Object as it's 'natural' Java type


setValue

public final void setValue(java.lang.Object data)
Sets the internal value of this item. If the data is not compatible with this type, an Exception will be thrown. See the documentation of the specific subtypes for a list of acceptable types and other rules for valid input.

Parameters:
data - the data to set. Must be compatible with the the instance.

setValue

public final void setValue(java.lang.String data)
sets the value from an input String. The input String must be understood by the underlying type. See the translate method for the concrete Data type in question

Parameters:
data - the string to use to set this data's value

translate

protected abstract java.lang.Object translate(java.lang.String data)
Converts the String to the underlying Data type's 'natural' type. The String must be understood by the data type.

Parameters:
data - the string to use to set this data's value
Returns:
an instance of the Data type's 'natural' type

setValueImpl

protected abstract void setValueImpl(java.lang.Object data)
called by setData after validate is called

Parameters:
data - the data to set

write

public void write(java.io.OutputStream stream)
           throws java.io.IOException
writes this Data instance to the stream as COBOL application data.

Parameters:
stream - the stream to write to
Throws:
java.io.IOException

validate

public final void validate(java.lang.Object data)
Validates the data passed in using the underlying definition

Parameters:
data - the data to validate