public abstract class ALDStandardizedDataIOCmdline extends Object implements ALDDataIOCmdline
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.
Modifier and Type | Field and Description |
---|---|
private boolean |
debug
debugging output
|
static char |
DERIVEDCLASS_CHAR
As a convention this character starts 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 and Description |
---|
ALDStandardizedDataIOCmdline() |
Modifier and Type | Method and Description |
---|---|
abstract String |
formatAsString(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. |
String |
formatAsString(Object obj,
String formatString)
Returns the external representations of this object using a formatString.
|
private String |
getValueStringFromFile(String filename)
The complete content of the given file is returned as one string.
|
abstract Object |
parse(Field field,
Class<?> cl,
String valueString)
Returns an object instantiated from valueString.
|
Object |
readData(Field field,
Class<?> cl,
String valueString)
Read an object using
valueString . |
protected boolean |
requiresNewlines()
Method to indicate if provider relies on newlines in format string.
|
String |
writeData(Object obj,
String formatString)
Return a string representation of given object value or print it to a file.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
providedClasses
public static final char FILEIO_CHAR
public static final char DERIVEDCLASS_CHAR
private boolean debug
public abstract Object parse(Field field, Class<?> cl, String valueString) throws ALDDataIOProviderException, ALDDataIOManagerException
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.field
- Field of object to be returnedcl
- Class of object to be returned.valueString
- Source from where to read data (e.g. a filename).ALDDataIOProviderException
ALDDataIOManagerException
ALDDataIOManagerCmdline
public abstract String formatAsString(Object obj) throws ALDDataIOManagerException, ALDDataIOProviderException
obj
into the string return and make no
prior interpretation regarding a file to be used.obj
- object to formatALDDataIOManagerException
ALDDataIOProviderException
public String formatAsString(Object obj, String formatString) throws ALDDataIOManagerException, ALDDataIOProviderException
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)
.
obj
- object to formatALDDataIOManagerException
ALDDataIOProviderException
protected boolean requiresNewlines()
This method is called by getValueStringFromFile(String)
upon
reading an input file to figure out if a derived provider requires
newlines in the file to be preserved in the returned format string.
If a provider requires newlines this methods needs to be overwritten and
'true' be returned.
public Object readData(Field field, Class<?> cl, String valueString) throws ALDDataIOProviderException, ALDDataIOManagerException
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.
readData
in interface ALDDataIOCmdline
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).ALDDataIOProviderException
ALDDataIOManagerException
public String writeData(Object obj, String formatString) throws ALDDataIOManagerException, ALDDataIOProviderException
If the given formatString
starts with FILEIO_CHAR
standard out is used as
target location, otherwise the string remaining subsequent to FILEIO_CHAR
is interpreted as file name.
In turn, if the remaining string starts with +
the output is apended to the file (with +
removed as filename).
writeData
in interface ALDDataIOCmdline
obj
- Object to be saved.formatString
- String indicated whether to return the value of where to write the value to.ALDDataIOManagerException
ALDDataIOProviderException
ALDDataIOManagerCmdline
private String getValueStringFromFile(String filename) throws ALDDataIOProviderException
filename
- Input file to be read.ALDDataIOProviderException
- Thrown in case of failure.Copyright © 2010–2021 Martin Luther University Halle-Wittenberg, Institute of Computer Science, Pattern Recognition and Bioinformatics. All rights reserved.