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

java.lang.Object
  extended by de.unihalle.informatik.Alida.dataio.provider.cmdline.ALDStandardizedDataIOCmdline
      extended by de.unihalle.informatik.Alida.dataio.provider.cmdline.ALDParametrizedClassDataIOCmdline
All Implemented Interfaces:
ALDDataIO, ALDDataIOCmdline

@ALDDataIOProvider
public class ALDParametrizedClassDataIOCmdline
extends ALDStandardizedDataIOCmdline

DataIO provider for parametrized classes and operators from command line. As this provider extends ALDStandardizedDataIOCmdline it implements the Alida syntax conventions.

For parametrized classes reading is done only for parameters annotated with ALDClassParameter. Either all annotated parameters are written/formated or a subset as specified by a format string.

For oeprators reading is done only for IN and INOUT parameters. Either all OUT and INPUT parameters are written/formated or a subset as specified by a format string.

Author:
posch

Field Summary
private  boolean debug
          debug messages
 
Fields inherited from class de.unihalle.informatik.Alida.dataio.provider.cmdline.ALDStandardizedDataIOCmdline
DERIVEDCLASS_CHAR, FILEIO_CHAR
 
Constructor Summary
ALDParametrizedClassDataIOCmdline()
           
 
Method Summary
private  void addParameter(java.lang.String name, java.lang.Object obj, java.lang.reflect.Field field, java.lang.String formatString, java.lang.StringBuffer bufstr)
          Format the parameter name of the object obj into the buffer bufstr using formatString to determine formating.
 java.lang.String formatAsString(java.lang.Object obj)
          Generic formatter to string of parametrized classes.
 java.lang.String formatAsString(java.lang.Object obj, java.lang.String formatString)
          Format all parameters of this parametrized class annotated with ALDClassParameter into a string.
static java.util.LinkedList<java.lang.String> lookupParameternames(ALDOperator op, java.lang.String pre)
          Lookup all parameter names of the operator with prefix pre.
 java.lang.Object parse(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.String valueString)
          Parser for parametrized classes and ALDOperators.
 java.lang.Object parse(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.String valueString, ALDOperator op)
          Generic Parser for parametrized classes and ALDOperators.
 java.util.Collection<java.lang.Class<?>> providedClasses()
          Interface method to announce class for which IO is provided for
 
Methods inherited from class de.unihalle.informatik.Alida.dataio.provider.cmdline.ALDStandardizedDataIOCmdline
readData, writeData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

private boolean debug
debug messages

Constructor Detail

ALDParametrizedClassDataIOCmdline

public ALDParametrizedClassDataIOCmdline()
Method Detail

addParameter

private void addParameter(java.lang.String name,
                          java.lang.Object obj,
                          java.lang.reflect.Field field,
                          java.lang.String formatString,
                          java.lang.StringBuffer bufstr)
                   throws ALDDataIOProviderException,
                          ALDDataIOManagerException
Format the parameter name of the object obj into the buffer bufstr using formatString to determine formating.

Parameters:
name - parameter to be formated
obj - object for which to format parameter
field - field of parameter to be formated
bufstr - String buffer to append formated parameter
Throws:
ALDDataIOProviderException
ALDDataIOManagerException

formatAsString

public java.lang.String formatAsString(java.lang.Object obj)
                                throws ALDDataIOProviderException,
                                       ALDDataIOManagerException
Generic formatter to string of parametrized classes. Output all annotated members of the class annotated with ALDClassParameter.

Specified by:
formatAsString in class ALDStandardizedDataIOCmdline
Parameters:
obj - object to format
Returns:
string representations of the object
Throws:
ALDDataIOProviderException
ALDDataIOManagerException

formatAsString

public java.lang.String formatAsString(java.lang.Object obj,
                                       java.lang.String formatString)
                                throws ALDDataIOProviderException,
                                       ALDDataIOManagerException
Format all parameters of this parametrized class annotated with ALDClassParameter into a string. If formatString starts with a curly bracket it is assume to contained a comma seprated list of name=value pairs enclosed in a matching curly brackets. In this case, only the (annotated) members named in this list are formated where the value is passed to the writeData of the dataIO provider handling the parameter's type. In extension, is a name equals * all members non listed in the formatString are formated using the value of this pair.

If formatString does not start with a curly bracket all annotated members are formated.

Overrides:
formatAsString in class ALDStandardizedDataIOCmdline
Parameters:
obj - parametrized class to be formated
formatString -
Throws:
ALDDataIOProviderException
ALDDataIOManagerException

lookupParameternames

public static java.util.LinkedList<java.lang.String> lookupParameternames(ALDOperator op,
                                                                          java.lang.String pre)
Lookup all parameter names of the operator with prefix pre. If one of the parameters exactly matches pre only this single parameter name is returned.

Returns:
All parameter names with prefix pre or the single parameter exactly matching pre

parse

public java.lang.Object parse(java.lang.reflect.Field field,
                              java.lang.Class<?> cl,
                              java.lang.String valueString)
                       throws ALDDataIOProviderException,
                              ALDDataIOManagerException
Parser for parametrized classes and ALDOperators. Expects a comma separated list of name=value pairs enclosed in curly brackets. For the class of the object to be read see ALDDataIOCmdline.

For parametrized classes each name has to be an annotated parameter.

For operators each name has to be an IN or INOUT parameter name of the operator and receives its value from the valueString.

If the list of name=value pairs is empty, i.e. no parameters are to be parsed, the empty string is accepted, too.

Specified by:
parse in class ALDStandardizedDataIOCmdline
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
Throws:
ALDDataIOProviderException
ALDDataIOManagerException
See Also:
ALDDataIOManagerCmdline

parse

public java.lang.Object parse(java.lang.reflect.Field field,
                              java.lang.Class<?> cl,
                              java.lang.String valueString,
                              ALDOperator op)
                       throws ALDDataIOProviderException,
                              ALDDataIOManagerException
Generic Parser for parametrized classes and ALDOperators. Expects a comma separated list of name=value pairs enclosed in curly brackets. For the class of the object to be read see ALDDataIOCmdline.

For parametrized classes each name has to be an annotated parameter.

For operators each name has to be an IN or INOUT parameter name of the operator and receives its value from the valueString.

If the list of name=value pairs is empty, i.e. no parameters are to be parsed, the empty string is accepted, too.

For the class of the object to be read see ALDDataIOCmdline. As a valueString a comma separated list of name=value pairs enclosed in curly brackets is expected. Each name has to be a member of the class or a super class which is annotated with ALDClassParameter. The readData method of the provider for the class of the member variable is used to read the objects value from value.

Parameters:
field -
cl -
valueString -
op - if a ALDOperator is to be parse this is an instance of this class. Ignored when parsing a parametrized class
Returns:
Throws:
ALDDataIOProviderException
ALDDataIOManagerException

providedClasses

public java.util.Collection<java.lang.Class<?>> providedClasses()
Interface method to announce class for which IO is provided for

Returns:
Collection of classes provided