de.mguennewig.pobjects.metadata
Class FileType

java.lang.Object
  extended by de.mguennewig.pobjects.metadata.AbstractType
      extended by de.mguennewig.pobjects.metadata.FileType
All Implemented Interfaces:
Type

public final class FileType
extends AbstractType

Used for file uploads within forms.

NOTE: This type can not be used for database expressions.

Author:
Michael Günnewig
See Also:
FileEntry

Field Summary
 
Fields inherited from interface de.mguennewig.pobjects.metadata.Type
CLASS_NAME, TYPE_NAME
 
Constructor Summary
FileType()
          Creates a new FileType.
 
Method Summary
 void addMap(MapItem item)
          Adds a mapping to this type.
 void checkConstraints(Record rec, Column column)
          Checks all constraints imposed on values of this type.
 void checkSyntax(java.lang.String value)
          
 ClassDecl expand(ClassDecl classDecl, Field field)
          Expands this type to an extra table.
 java.lang.String formatNative(java.lang.Object value)
          Map value from its `native' string representation to its internal representation based on the type.
 java.lang.Class<?> getJavaClass()
          Returns the Java class instance that is being used for the values of this type.
 java.util.List<MapItem> getMap()
          Returns the list of mappings.
 int getMaxFieldSize()
          Returns the maximum field size required to enter a value of this type.
 java.lang.Object getResult(JdbcContainer db, java.sql.ResultSet rs, int column)
          Reads the value for this type from the result set.
 int getResultInc()
          Returns the number of columns read from the ResultSet.
 boolean isScalar()
          Tests whether this type is scalar.
 boolean labelToValue(java.lang.String label, ObjectRef valueRef)
          Maps label to its value if defined.
 java.lang.String name(int variant)
          Returns different names depending on variant for the code generator.
 java.lang.Object parseNative(java.lang.String value)
          Parse value according to the `native' string representation of this type.
 void setParam(JdbcContainer db, java.sql.PreparedStatement statm, int pos, java.lang.Object value)
          Sets the parameter(s) starting at startPos.
 boolean valueToLabel(java.lang.Object value, ObjectRef labelRef)
          Maps value to its label if defined.
 
Methods inherited from class de.mguennewig.pobjects.metadata.AbstractType
format, getDescription, getTypeClass, parse, setDescription, setTypeClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileType

public FileType()
Creates a new FileType.

Method Detail

addMap

public void addMap(MapItem item)
Adds a mapping to this type.

Throws:
java.lang.UnsupportedOperationException - always, as maps are not supported.

getJavaClass

public java.lang.Class<?> getJavaClass()
Returns the Java class instance that is being used for the values of this type.


getMap

public java.util.List<MapItem> getMap()
Returns the list of mappings.

Returns:
an empty unmodifiable list
See Also:
Type.addMap(MapItem), Type.labelToValue(String,ObjectRef), Type.valueToLabel(Object,ObjectRef)

checkConstraints

public void checkConstraints(Record rec,
                             Column column)
Checks all constraints imposed on values of this type.

Parameters:
rec - The record which contains column.
column - The column of rec which has this type.

expand

public ClassDecl expand(ClassDecl classDecl,
                        Field field)
Expands this type to an extra table.

Non-scalar types can not be saved directly in a field, so they will be expanded to another table whose declaration will be generated by this method.

Returns:
null
See Also:
Type.isScalar()

isScalar

public boolean isScalar()
Tests whether this type is scalar.

Returns:
false
See Also:
Type.expand(de.mguennewig.pobjects.metadata.ClassDecl, de.mguennewig.pobjects.metadata.Field)

getMaxFieldSize

public int getMaxFieldSize()
Returns the maximum field size required to enter a value of this type.

This is the maximum number of characters required to enter a string representation of all valid values of this type. The typical size of an input field may be much smaller.

Returns:
255, which is equivalent to MAX_PATH on most platforms.

labelToValue

public boolean labelToValue(java.lang.String label,
                            ObjectRef valueRef)
Maps label to its value if defined.

Parameters:
label - The label for which the corresponding value should be returned.
valueRef - An optional reference which will be used to return the corresponding value if it exists.
Returns:
true if the label could mapped, otherwise false.
See Also:
Type.valueToLabel(Object,ObjectRef), Type.addMap(MapItem)

valueToLabel

public boolean valueToLabel(java.lang.Object value,
                            ObjectRef labelRef)
Maps value to its label if defined.

Parameters:
value - The internal object in the type's set for which the corresponding label should be returned.
labelRef - An optional reference which will be used to return the corresponding label if it exists.
Returns:
true if the value could mapped, otherwise false.
See Also:
Type.labelToValue(String,ObjectRef), Type.addMap(MapItem)

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
Overrides:
formatNative in class AbstractType
Throws:
java.lang.UnsupportedOperationException - always, as a file can not be formatted.
See Also:
Type.getJavaClass()

checkSyntax

public void checkSyntax(java.lang.String value)


parseNative

public java.lang.Object parseNative(java.lang.String value)
Parse value according to the `native' string representation of this type.

This representation is a one-to-one mapping of the type's value set to strings, 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 an integer object, but would reject a label like `"Yes"' that may be associated with the value `1'.

Throws:
java.lang.UnsupportedOperationException - always, as a string can not be parsed into a file.
See Also:
Type.addMap(MapItem), Type.parse(String)

getResult

public java.lang.Object getResult(JdbcContainer db,
                                  java.sql.ResultSet rs,
                                  int column)
Reads the value for this type from the result set.

Throws:
java.lang.UnsupportedOperationException - always, as a string can not be parsed into a file.
See Also:
Type.getResultInc()

getResultInc

public int getResultInc()
Returns the number of columns read from the ResultSet.

See Also:
Type.getResult(JdbcContainer,ResultSet,int)

setParam

public void setParam(JdbcContainer db,
                     java.sql.PreparedStatement statm,
                     int pos,
                     java.lang.Object value)
Sets the parameter(s) starting at startPos.

This method is the counterpart to Type.getResult(JdbcContainer,ResultSet,int) and Type.getResultInc().


name

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

Specified by:
name in interface Type
Overrides:
name in class AbstractType