de.unihalle.informatik.Alida.dataio.provider.cmdline
Class ALDStandardizedDataIOCmdline

java.lang.Object
  extended by de.unihalle.informatik.Alida.dataio.provider.cmdline.ALDStandardizedDataIOCmdline
All Implemented Interfaces:
ALDDataIO, ALDDataIOCmdline
Direct Known Subclasses:
ALDCollectionDataIOCmdline, ALDEnumDataIOCmdline, ALDNativeDataIOCmdline, ALDOperatorDataIOCmdline, ALDParametrizedClassDataIOCmdline

public abstract class ALDStandardizedDataIOCmdline
extends java.lang.Object
implements ALDDataIOCmdline

Abstract class providing basic methods for cmdline DataIO providers according to Alida conventions.

These conventions are detailed in the documentation if the methods readData and writeData in this class below. They handle IO from/to file and reading derived classes of the class handled by an dataIO provider.

Classes extending this class are expected to override the methods parse and formatAsString which do the actual reading/parsing or writing/formating subsequent to generic handling of Alida convention with respect to derived classes and IO form/to file.

Author:
posch

Field Summary
static char DERIVEDCLASS_CHAR
          As a convention this character startes a derived class name, and is terminated by ':'
static char FILEIO_CHAR
          As a convention a parameter value starting with this character indicates that the actual parameter should be read from or writen to a file.
 
Constructor Summary
ALDStandardizedDataIOCmdline()
           
 
Method Summary
abstract  java.lang.String formatAsString(java.lang.Object obj)
          Returns the string representations of this object This method is assumed to directly format the obj into the string return and make no prior interpretation regarding a file to be used.
 java.lang.String formatAsString(java.lang.Object obj, java.lang.String formatString)
          Returns the external representations of this object using a formatString.
static java.lang.String getValueStringFromFile(java.lang.String valueString)
          Checks if the valueString passed starts with FILEIO_CHAR.
abstract  java.lang.Object parse(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.String valueString)
          Returns an object instantiated from valueString.
 java.lang.Object readData(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.String valueString)
          Read an object using valueString.
 java.lang.String writeData(java.lang.Object obj, java.lang.String valueString)
          Return a string representation of given object value or print it to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.unihalle.informatik.Alida.dataio.provider.ALDDataIO
providedClasses
 

Field Detail

DERIVEDCLASS_CHAR

public static final char DERIVEDCLASS_CHAR
As a convention this character startes a derived class name, and is terminated by ':'

See Also:
Constant Field Values

FILEIO_CHAR

public static final char FILEIO_CHAR
As a convention a parameter value starting with this character indicates that the actual parameter should be read from or writen to a file. The filename is the remaining string after removing this character.

See Also:
Constant Field Values
Constructor Detail

ALDStandardizedDataIOCmdline

public ALDStandardizedDataIOCmdline()
Method Detail

formatAsString

public abstract java.lang.String formatAsString(java.lang.Object obj)
Returns the string representations of this object This method is assumed to directly format the obj into the string return and make no prior interpretation regarding a file to be used.

Parameters:
obj - object to format
Returns:
string representations of the object

formatAsString

public java.lang.String formatAsString(java.lang.Object obj,
                                       java.lang.String formatString)
Returns the external representations of this object using a formatString. The formatString may be used define parts of the object to be formated or specify format charateristics. However, formatString should not interpreted in order to decide to output the object directly to a file (as this is handled by writeData).

The default implementation is equivalent to formatAsString(obj).

Parameters:
obj - object to format

getValueStringFromFile

public static java.lang.String getValueStringFromFile(java.lang.String valueString)
Checks if the valueString passed starts with FILEIO_CHAR. This indicated that the value should be read from a file where the name of this file is the remaining string of valueString subsequent to FILEIO_CHAR. If this is case the complete content of the file is return as one string. Otherwise return the valueString unchanged.

Parameters:
valueString -
Returns:
argument or string read from file

parse

public abstract java.lang.Object parse(java.lang.reflect.Field field,
                                       java.lang.Class<?> cl,
                                       java.lang.String valueString)
Returns an object instantiated from valueString. For the class of the object to be read see ALDDataIOManagerCmdline.readData(Field,Class,String). This method is assumed to directly parse the valueString and make no prior interpretation regarding a file to use or derived class to return.

Parameters:
field - Field of object to be returned
cl - Class of object to be returned.
valueString - Source from where to read data (e.g. a filename).
Returns:
Object read from valueString
See Also:
ALDDataIOManagerCmdline

readData

public java.lang.Object readData(java.lang.reflect.Field field,
                                 java.lang.Class<?> cl,
                                 java.lang.String valueString)
Read an object using valueString. For the class of the object to be read see ALDDataIOCmdline.

If valueString starts with FILEIO_CHAR the value is read from a file where the name of this file is the remaining string of valueString. subsequent to FILEIO_CHAR.

The next step in interpreting the value string is scrutinze whether an instance of a class deriving the class defined in field or the class cl is to be returned. This is indicated by starting the value string (either passed directly via valueString or the string read from file) with DERIVEDCLASS_CHAR. by field If this is the case all charaters up, but excluding, the next colon are interpreted as this fully qualified class name. Next it is checked if this class indeed is a proper extension which in turn required this class to be annotated with ALDDerivedClass. If this check passes a dataIO provider of this class is looked up and its readData invoked with the value string after the deliminating colon.

If no deriving class is requested, the parse method of the class defined in field or the class cl is invoked on the value string.

Specified by:
readData in interface ALDDataIOCmdline
Parameters:
field - Field of object to be returned.
cl - Class of object to be returned.
valueString - Source from where to read data (e.g. a filename).
Returns:
Object read from source.

writeData

public java.lang.String writeData(java.lang.Object obj,
                                  java.lang.String valueString)
Return a string representation of given object value or print it to a file.

If the given target location starts with FILEIO_CHAR standard out is used as target location, otherwise the string remaining subsequent to FILEIO_CHAR is interpreted as file name.

Specified by:
writeData in interface ALDDataIOCmdline
Parameters:
obj - Object to be saved.
valueString - String indicated whether to return the value of where to write the value to.
Returns:
String formated from obj
See Also:
ALDDataIOManagerCmdline