|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openadaptor.dostrings.DOStringReaderWriter
org.openadaptor.dostrings.DOStringReader
public abstract class DOStringReader
Abstract base class for transforming strings into DataObjects. Can be
initialised with the following properties.
DateFormat Allows user to specify a date, you can use
YY or YYYY eg: 01 or 2001
MM or MMMM eg: 10 or Oct
DD eg: 2
TZN eg: GMT
hh eg: 10
mm eg: 30
ss eg: 05
NN eg: AM or PM
EmptyStringAsNull If true then empty string String values will be translated
to null values
NullString Occurences of this string will be translated to null
values
AttTrimN Trim the Nth attribute value
When reading multiple types in using the reader, a specific field must
be nominated as containing a distinguishing string for that record.
The field can either be the same for each DOType (the first field for
example) or a different field can be defined for each DOType. If the
field number is different, it is important to note that each record
will be checked against each type matching string in turn, i.e. Type1
first, then Type2 if it is not of type 1, then Type3 etc.
For best performance, The most common record types should be the first
checked; if you have 800 Type A records, and only 100 Type B and
Type C, then make Type A "Type1" in the properties file.
The property required is the "TypeFieldNumber", and can be defined at the component level, for all the DOTypes:
A.Cn.TypeFieldNumber = 1 A.Cn.Type1 = aType A.Cn.Type2 = bTypeor at the DOType level if different fields distinguish different types:
A.Cn.Type1 = aType A.Cn.aType.TypeFieldNumber = 1 A.Cn.Type2 = bType A.Cn.bType.TypeFieldNumber = 2The value matched in the type field can be a DOType attribute (very unlikely unless your DataObjects are not SimpleDataObjects), but is more often the DOType name, or a constant string. The value is defined in the "TypeFieldMatch" property. If the value is a constant string, then it must be enclosed in quotes. If it is the DOType name, the special property value '-typeName-' must be used, or if it is an attribute value, just the attribute name:
A.Cn.aType.TypeFieldMatch = "TYPE_A" A.Cn.aType.TypeFieldMatch = -typeName- A.Cn.aType.TypeFieldMatch = typeIdNote that you may also define the property "AttNameN" where N is the type field number, to define what happens to the contents of the field that was used for the type matching. The value of the property can either be an attribute name, in which case the field value will be stored in that (String) attribute, or it can be "-ignore-" in which case the field value is discarded.
A.Cn.aType.TypeFieldNumber = 3 A.Cn.aType.TypeFieldMatch = "TYPE_A" A.Cn.aType.AttName3 = -ignore- ;; field is discarded A.Cn.aType.AttName3 = TypeID ;; TYPE_A stored in TypeID attrRefer to the base class DOStringReaderWriter for other base properties.
When trying to convert the String into a DataObject, the component will try to match the DOTypes defined in the properties file with any type declarations in the string itself. By default this matching is case sensitive. You can override this by setting:
A.Cn.CaseSensitiveTypeMatching = false
DOStringReaderWriter| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.openadaptor.dostrings.DOStringReaderWriter |
|---|
DOStringReaderWriter.TypeInfo |
| Field Summary | |
|---|---|
protected boolean |
_case_sensitive_types
flag to indicate that DOType matching should be case sensitive |
protected DateFormatter |
_date_formatter
a DateFormatter to parse the date strings |
protected boolean |
_empty_string_as_null
Deprecated. Use isTreatEmptyStringAsNull() instead - this is going private in 1.7.5 |
protected java.lang.String[] |
_last_chop
Contains last string array produced by chop() in getDOTypeForRecord. |
protected java.lang.String |
_null_string
Deprecated. Use getNullString() instead - this is going private in 1.7.5 |
protected java.util.Hashtable |
_trim_flag_arrays
Hashtable of DataObject attribute trim flags keyed on type name, the order of the array is based on order of specification |
(package private) static org.apache.log4j.Logger |
log
|
protected static java.lang.String |
TRIM_PROP
|
| Fields inherited from class org.openadaptor.dostrings.DOStringReaderWriter |
|---|
_numFields, _numFieldsAtt, _single_type_property_defined, _textEncoding, _type, _type_field_number, _typeInfo_array, _typeInfo_count, _typeInfos, ACT_ATTR, ACT_IGNORE, ACT_STRING, ACT_TYPENAME, DEFAULT_ATT_STRING, DEFAULT_TYPE_STRING, KW_IGNORE, KW_TYPENAME |
| Constructor Summary | |
|---|---|
DOStringReader()
|
|
| Method Summary | |
|---|---|
abstract java.lang.String[] |
chop(java.lang.String record,
java.lang.String type_name)
Implement this method to extract attribute value strings from the record string. |
java.lang.String |
chopField(java.lang.String record,
java.lang.String type_name,
int field_num)
Implement this method to make matching against multiple types more efficient. |
DataObject |
createDataObjectForRecord(java.lang.String record)
Returns a SimpleDataObject with a DOType suitable for the supplied record. |
DataObject |
fromString(java.lang.String s)
Convert a string (record) to a DataObject |
DOType |
getDOTypeForRecord(java.lang.String record)
Searches DOTypes for the one which matches the string record. |
java.lang.String |
getNullString()
|
void |
init(java.util.Properties props,
java.lang.String prefix)
Initialise from properties object. |
boolean |
isTreatEmptyStringAsNull()
If true, then subclasses should treat empty (String) fields as containing null rather than as zero-length strings. |
void |
setNullString(java.lang.String s)
Set the value of the string which should be interpreted as (replaced by) null. |
void |
setTreatEmptyStringAsNull(boolean flag)
Sets indicator as to whether empty fields should be returned as nulls or as empty (zero length) strings. |
| Methods inherited from class org.openadaptor.dostrings.DOStringReaderWriter |
|---|
getNumFields, getNumFieldsAtt, getTextEncoding, init, init, requireAttNameOrNumAttributes, setNumFields, setNumFieldsAtt, useDataObjectAttributes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
static org.apache.log4j.Logger log
protected static final java.lang.String TRIM_PROP
protected boolean _empty_string_as_null
protected java.lang.String _null_string
protected java.util.Hashtable _trim_flag_arrays
protected DateFormatter _date_formatter
protected boolean _case_sensitive_types
protected java.lang.String[] _last_chop
| Constructor Detail |
|---|
public DOStringReader()
| Method Detail |
|---|
public void init(java.util.Properties props,
java.lang.String prefix)
throws DOStringException
init in class DOStringReaderWriterprops - Properties objectprefix - Prefix string to search for properties
DOStringException - Thrown if initialisation fails, mandatory
properties are missing or properties cannot
be parsed.
public DataObject fromString(java.lang.String s)
throws DOStringException
s - record string
DOStringException
public abstract java.lang.String[] chop(java.lang.String record,
java.lang.String type_name)
throws DOStringException
record - The record stringtype_name - The type name of the DataObject that will be
created from this record. You can use this to
access internal hashtables
DOStringException
public java.lang.String chopField(java.lang.String record,
java.lang.String type_name,
int field_num)
throws DOStringException
record - The record string.type_name - The type name of the DataObject that will be
created from this record. You can use this to
access internal hashtables.field_num - The index (1..n) of the field to be returned.
starts at one)
DOStringException
public DOType getDOTypeForRecord(java.lang.String record)
throws DOStringException
record - String record for which DOType is required
DOStringException - If no DOType matches record.
public DataObject createDataObjectForRecord(java.lang.String record)
throws DOStringException
record - The record string
DOStringExceptionpublic void setTreatEmptyStringAsNull(boolean flag)
flag - If true all empty fields are returned as nulls, otherwise as
zero-length strings.public boolean isTreatEmptyStringAsNull()
public void setNullString(java.lang.String s)
s - new null String.public java.lang.String getNullString()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||