net.sf.cb2java.copybook
Class Element

java.lang.Object
  extended bynet.sf.cb2java.copybook.Element
Direct Known Subclasses:
Group, net.sf.cb2java.copybook.Leaf

public abstract class Element
extends java.lang.Object

base class for types represented in the copybook

Author:
James Watson

Constructor Summary
protected Element(java.lang.String name, int level, int occurs)
          constructor
 
Method Summary
 byte[] getBytes(java.lang.String s)
          converts a String to a byte array based on the current encoding
abstract  java.util.List getChildren()
          gets the children of this element or null if there are none
protected abstract  int getLength()
          returns the length of one instance of this element
 int getLevel()
          returns the level of this element
 java.lang.String getName()
          returns the name of this element
 int getOccurs()
          returns the number of times this item appears in data
 int getPosition()
          returns the position of this element
 java.lang.String getString(byte[] data)
          helper method for converting the given bytes to a string with the parent copybook's encoding
protected abstract  Value getValue()
          the value for this element
abstract  byte[] toBytes(java.lang.Object data)
          converts the supplied data to bytes
 java.lang.String toString()
           
abstract  void validate(java.lang.Object data)
          validates the data based on this element definition
 void write(java.io.OutputStream stream, java.lang.Object data)
          writes the data as bytes to the given stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

protected Element(java.lang.String name,
                  int level,
                  int occurs)
constructor

Parameters:
name - the element name
level - the level of the element
occurs - how many times the element occurs
Method Detail

getValue

protected abstract Value getValue()
the value for this element

Returns:
the value set for this element or the default

getChildren

public abstract java.util.List getChildren()
gets the children of this element or null if there are none

Returns:
the children of this element or null if there are none

getLength

protected abstract int getLength()
returns the length of one instance of this element

Returns:
the length of one instance of this element

validate

public abstract void validate(java.lang.Object data)
                       throws java.lang.IllegalArgumentException
validates the data based on this element definition

Parameters:
data - the data to validate
Throws:
java.lang.IllegalArgumentException - if the data is invalid

toBytes

public abstract byte[] toBytes(java.lang.Object data)
converts the supplied data to bytes

Parameters:
data - the data to convert to bytes
Returns:
the bytes for the data

getName

public final java.lang.String getName()
returns the name of this element

Returns:
the name of this element

getLevel

public final int getLevel()
returns the level of this element

Returns:
the level of this element

getPosition

public final int getPosition()
returns the position of this element

Returns:
the position of this element

getOccurs

public int getOccurs()
returns the number of times this item appears in data

Returns:
the number of times this item appears in data

write

public final void write(java.io.OutputStream stream,
                        java.lang.Object data)
                 throws java.io.IOException
writes the data as bytes to the given stream

Parameters:
stream - the outputstream
data - the data to write as bytes
Throws:
java.io.IOException

getString

public final java.lang.String getString(byte[] data)
helper method for converting the given bytes to a string with the parent copybook's encoding

Parameters:
data - the data to convert to a String
Returns:
the String value

getBytes

public final byte[] getBytes(java.lang.String s)
converts a String to a byte array based on the current encoding

Parameters:
s -
Returns:

toString

public java.lang.String toString()