de.mguennewig.pobjects.metadata
Class AbstractType

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.AbstractType
All Implemented Interfaces:
Type
Direct Known Subclasses:
FileType, ScalarType

public abstract class AbstractType
extends java.lang.Object
implements Type

Abstract type implementation.

Author:
Michael Günnewig

Field Summary
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
AbstractType()
          Creates a new type.
 
Method Summary
 java.lang.String format(java.lang.Object value)
          Map value to its string representation.
 java.lang.String formatNative(java.lang.Object value)
          Map value from its `native' string representation to its internal representation based on the type.
 Description getDescription()
           
 java.lang.String getTypeClass()
          Returns the fully qualified class name of the type class that is used instead of this one.
 java.lang.String name(int variant)
          Returns different names depending on variant for the code generator.
 java.lang.Object parse(java.lang.String value)
          Map value to its internal representation.
 void setDescription(Description description)
           
 void setTypeClass(java.lang.String typeClass)
          Sets the fully qualified class name of the type class that should be used instead of this one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjects.metadata.Type
addMap, checkConstraints, checkSyntax, expand, getJavaClass, getMap, getMaxFieldSize, getResult, getResultInc, isScalar, labelToValue, parseNative, setParam, valueToLabel
 

Constructor Detail

AbstractType

public AbstractType()
Creates a new type.

Method Detail

getDescription

public final Description getDescription()
Specified by:
getDescription in interface Type

setDescription

public final void setDescription(Description description)
Specified by:
setDescription in interface Type

formatNative

public java.lang.String formatNative(java.lang.Object value)
Map value from its `native' string representation to its internal representation based on the type.

This mapping is a one-to-one mapping of string values to the type's value set, without any translation based on MapItems associated with the type.

For example, an integer type's implementation would accept a value like `1' and translate it to the string `&dblquote;1&dblquote;', independent of any label associated with the value `1'.

The value null is always mapped to the empty string.

Specified by:
formatNative in interface Type
Throws:
java.lang.IllegalArgumentException - if value is not in this type's value set. For example a String when we expect an Integer.
See Also:
Type.getJavaClass()

format

public java.lang.String format(java.lang.Object value)
Map value to its string representation.

If value matches one of the MapItem.getValue()s associated with this type, then it return its associated label. Otherwise, delegate the job to formatNative(java.lang.Object).

Specified by:
format in interface Type
Throws:
java.lang.IllegalArgumentException - if value is not in this type's value set. For example a String when we expect an Integer.
See Also:
Type.addMap(MapItem), formatNative(Object), Type.valueToLabel(Object,ObjectRef)

parse

public java.lang.Object parse(java.lang.String value)
                       throws PObjSyntaxException
Map value to its internal representation.

If value matches one of the labels associated with this type, then it returns its associated value. Otherwise, delegates the job to Type.parseNative(String).

Furthermore the syntax of the value is checked.

Specified by:
parse in interface Type
Throws:
PObjSyntaxException - if value couldn't be parsed as a string representation of this type.
See Also:
Type.addMap(MapItem), Type.labelToValue(String,ObjectRef), Type.checkSyntax(String), Type.parseNative(String)

getTypeClass

public final java.lang.String getTypeClass()
Returns the fully qualified class name of the type class that is used instead of this one.

Specified by:
getTypeClass in interface Type
Returns:
null if this type class is used, otherwise the fully qualified class name that should be used.

setTypeClass

public final void setTypeClass(java.lang.String typeClass)
Sets the fully qualified class name of the type class that should be used instead of this one.

Specified by:
setTypeClass in interface Type

name

public java.lang.String name(int variant)
Returns different names depending on variant for the code generator.

Specified by:
name in interface Type
Throws:
java.lang.IllegalArgumentException - if variant is unknown.