de.enough.polish.dataeditor
Class DataType

java.lang.Object
  extended by de.enough.polish.dataeditor.DataType

public class DataType
extends Object

Represents a data-type. A type can be user defined and consist of other types.

Copyright Enough Software 2004 - 2011

 history
        18-Oct-2004 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
static DataType ASCII_STRING
           
static int ASCII_STRING_ID
           
static DataType BOOLEAN
           
static int BOOLEAN_ID
           
static DataType BYTE
           
static int BYTE_ID
           
static DataType INTEGER
           
static int INTEGER_ID
           
static DataType LONG
           
static int LONG_ID
           
static DataType PNG_IMAGE
           
static int PNG_IMAGE_ID
           
static DataType SHORT
           
static int SHORT_ID
           
static DataType UNSIGNED_BYTE
           
static int UNSIGNED_BYTE_ID
           
static DataType UNSIGNED_SHORT
           
static int UNSIGNED_SHORT_ID
           
static int USER_DEFINED_ID
           
static DataType UTF_STRING
           
static int UTF_STRING_ID
           
 
Constructor Summary
DataType(org.jdom.Element typeElement, DataManager dataManager)
           
DataType(String name, DataType[] subtypes)
          Creates a new user defined type.
DataType(String name, int type, int numberOfBytes)
          Creates a new simple type.
 
Method Summary
 void addCode(String count, String paramName, StringBuffer buffer)
          Adds the Java code to load this type.
 void addInstanceDeclaration(String count, String paramName, StringBuffer buffer)
           
 void addInternalClass(Map implementedTypes, StringBuffer buffer)
           
static DataType[] getDefaultTypes()
           
 Object getDefaultValue()
           
 int getIntRepresentation(Object data)
          Retrieves the INT representation for a given object.
 String getJavaType()
           
 String getName()
          Retrieves the name of this DataType.
 int getNumberOfBytes()
           
 DataType[] getSubtypes()
           
 int getType()
           
 String getXmlRepresentation()
          Retrieves the XML representation for this DataEntry.
 boolean isDynamic()
          Determines when this type has a dynamic (i.e.
 boolean isUserDefined()
           
 Object loadData(DataInputStream in)
          Loads data for this type from the given input stream
 Object parseDataString(String value)
           
 void saveData(Object value, DataOutputStream out)
          Saves the data for this type.
 String toString()
           
 String toString(Object data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BYTE_ID

public static final int BYTE_ID
See Also:
Constant Field Values

UNSIGNED_BYTE_ID

public static final int UNSIGNED_BYTE_ID
See Also:
Constant Field Values

SHORT_ID

public static final int SHORT_ID
See Also:
Constant Field Values

UNSIGNED_SHORT_ID

public static final int UNSIGNED_SHORT_ID
See Also:
Constant Field Values

INTEGER_ID

public static final int INTEGER_ID
See Also:
Constant Field Values

LONG_ID

public static final int LONG_ID
See Also:
Constant Field Values

ASCII_STRING_ID

public static final int ASCII_STRING_ID
See Also:
Constant Field Values

UTF_STRING_ID

public static final int UTF_STRING_ID
See Also:
Constant Field Values

BOOLEAN_ID

public static final int BOOLEAN_ID
See Also:
Constant Field Values

PNG_IMAGE_ID

public static final int PNG_IMAGE_ID
See Also:
Constant Field Values

USER_DEFINED_ID

public static final int USER_DEFINED_ID
See Also:
Constant Field Values

BYTE

public static final DataType BYTE

UNSIGNED_BYTE

public static final DataType UNSIGNED_BYTE

SHORT

public static final DataType SHORT

UNSIGNED_SHORT

public static final DataType UNSIGNED_SHORT

INTEGER

public static final DataType INTEGER

LONG

public static final DataType LONG

ASCII_STRING

public static final DataType ASCII_STRING

UTF_STRING

public static final DataType UTF_STRING

BOOLEAN

public static final DataType BOOLEAN

PNG_IMAGE

public static final DataType PNG_IMAGE
Constructor Detail

DataType

public DataType(String name,
                int type,
                int numberOfBytes)
Creates a new simple type.

Parameters:
name - the name of this type
type - the type-ID
numberOfBytes - the number of bytes which are needed to store this type, -1 if undefined

DataType

public DataType(String name,
                DataType[] subtypes)
Creates a new user defined type.

Parameters:
name - the name of this type
subtypes - the subtypes of this user defined type.

DataType

public DataType(org.jdom.Element typeElement,
                DataManager dataManager)
Parameters:
typeElement -
dataManager -
Method Detail

getType

public int getType()

getSubtypes

public DataType[] getSubtypes()

isUserDefined

public boolean isUserDefined()

getNumberOfBytes

public int getNumberOfBytes()

getDefaultValue

public Object getDefaultValue()

toString

public String toString(Object data)

parseDataString

public Object parseDataString(String value)

getName

public String getName()
Retrieves the name of this DataType.

Returns:
the name

getIntRepresentation

public int getIntRepresentation(Object data)
Retrieves the INT representation for a given object.

Parameters:
data - the data object to represent
Returns:
the INT representation

getXmlRepresentation

public String getXmlRepresentation()
Retrieves the XML representation for this DataEntry. This is useful e.g. for saving it into a file.

Returns:
the XML representation

toString

public String toString()
Overrides:
toString in class Object

getDefaultTypes

public static DataType[] getDefaultTypes()

isDynamic

public boolean isDynamic()
Determines when this type has a dynamic (i.e. -1) length

Returns:
true when this type is dynamic

getJavaType

public String getJavaType()

addInstanceDeclaration

public void addInstanceDeclaration(String count,
                                   String paramName,
                                   StringBuffer buffer)

addCode

public void addCode(String count,
                    String paramName,
                    StringBuffer buffer)
Adds the Java code to load this type. The input-streams name is "in".

Parameters:
count - the number of instances which should be loaded, can either be a number or a term like "rows * cells".
paramName - the name of the parameter
buffer - the string buffer to which the code should be added.

addInternalClass

public void addInternalClass(Map implementedTypes,
                             StringBuffer buffer)

loadData

public Object loadData(DataInputStream in)
                throws IOException
Loads data for this type from the given input stream

Parameters:
in - the input stream
Returns:
the read type-dependent value
Throws:
IOException - when the data could not be read

saveData

public void saveData(Object value,
                     DataOutputStream out)
              throws IOException
Saves the data for this type.

Parameters:
value - the value
out - the data output stream
Throws:
IOException - when the data could not be stored