com.ca.commons.datamodel
Class DataModelValue

java.lang.Object
  extended by com.ca.commons.datamodel.DataModelValue

public final class DataModelValue
extends Object

Serves double purpose representing both type and value information.


Nested Class Summary
static class DataModelValue.ConversionSettings
          Struct whose fields can be used to modulate conversions of all sorts of values to and from strings.
 
Field Summary
static int ANY_TYPE
          Deprecated. 
static int BINARY_TYPE
          Deprecated. 
static int BOOL_TYPE
          Deprecated. 
static int DATE_TIME_TYPE
          Deprecated. 
static int DATE_TYPE
          Deprecated. 
static int DBL_TYPE
          Deprecated. 
static int DURATION_TYPE
          Deprecated. 
static int ENUM_TYPE
          Deprecated. 
static int FLEXI_STR_TYPE
          Deprecated. 
static int FLOAT_TYPE
          Deprecated. 
static int INT_TYPE
          Deprecated. 
static Logger logger
           
static int LONG_TYPE
          Deprecated. 
static int MAP_TYPE
          Deprecated. 
static int SEQ_TYPE
          Deprecated. 
static int SET_TYPE
          Deprecated. 
static int STR_TYPE
          Deprecated. 
static int TIME_TYPE
          Deprecated. 
static int UNDEF_TYPE
          Deprecated. 
static TimeZone UTC_TIMEZONE
           
 
Constructor Summary
DataModelValue(DataModelType type)
          For internal use where a typed, but empty, value is required.
DataModelValue(DataModelType type, Object value)
           
DataModelValue(DataModelType type, Object value, boolean isDefault)
           
 
Method Summary
 DataModelValue changeValue(Object newValue)
           
 DataModelValue copy()
           
 boolean equals(Object o)
           
static com.ca.commons.functional.Pred<DataModelValue> fnIsType(DataModelType dmType)
           
static
<T> com.ca.commons.functional.Fn<DataModelValue,com.ca.commons.functional.Option<T>>
fnValue(Class<? extends T> type)
           
static Object fromString(DataModelType type, String str)
          Calls fromString(DataModelType, String, ConversionSettings) with null last argument.
static Object fromString(DataModelType type, String value, DataModelValue.ConversionSettings convSettings)
          Parses a string to find a data model value of a specified type.
static Object fromString(int type, String str)
          Deprecated. Use version taking a DataModelType instead of legacy int.
static Object fromString(int legacyType, String value, DataModelValue.ConversionSettings convSettings)
          Deprecated. Use version taking DataModelType instead of legacy int.
 Object getAny()
           
 String getBaseTypeString()
          Null if type for this value is not compound, otherwise return base type string, eg returns "FLEXI_STR" when "FLEXI_STR:DN" is passed in.
 DataModelBinaryValue getBinary()
           
 boolean getBool()
           
static String getClassRefClass(ClassReference ref)
           
 DataModelCollectionValue getCollection()
           
 ClassReference getCompoundValueClassRef()
           
 String getCompoundValueClassRefClass()
           
 String getCompoundValueClassRefStr()
          Return fully qualified name referencing compound value class.
 Date getDate()
           
 Date getDateTime()
           
 double getDbl()
           
 Duration getDuration()
           
 DataModelEnumValue getEnum()
           
 DataModelFlexiStrValue getFlexiStr()
           
 float getFloat()
           
 int getInt()
           
 long getLong()
           
 DataModelMapValue getMap()
           
 DataModelValue getNestedValue()
          Return "this" for simple (non-collection) values, otherwise return the basetype for the collection.
 Collection<DataModelValue> getSeq()
           
 Collection<DataModelValue> getSet()
           
 String getStr()
           
 Date getTime()
           
 DataModelType getType()
           
 String getTypeString()
          Return full qualified stype for this value, eg "BOOL" or "FLEXI_STR:DN".
 Object getValue()
           
static Object getValue(DataModelType type, String value)
          Deprecated. Use fromString instead.
static Object getValue(int legacyType, String value)
          Deprecated. Use fromString instead.
 String getValueAsString()
          Calls getValueAsString(com.ca.commons.datamodel.DataModelValue.ConversionSettings) with null argument.
 String getValueAsString(DataModelValue.ConversionSettings convSettings)
          Return string representation of contained value, or null for collections, where convSettings will default to DEFAULT_CONVERSION_SETTINGS if null.
 int hashCode()
           
 void initTypeString()
          String signifying logical type for value contained, eg for validation purposes.
 boolean isDefault()
          Does the contained value (for primitives) act as a default?
 boolean isType(DataModelType type)
           
static DataModelValue newBooleanValue(boolean b)
           
static DataModelValue newIntValue(int i)
           
static DataModelValue newStringValue(String s)
           
static DateFormat newXsdDateFormat()
           
static DateFormat newXsdDateTimeFormat()
           
static DateFormat newXsdDateTimeMillisFormat()
           
static DateFormat newXsdTimeFormat()
           
static DateFormat newXsdTimeMillisFormat()
           
 String stringValue(String defaultValue)
           
 String toString()
           
static String toString(DataModelType type, Object obj, DataModelValue.ConversionSettings convSettings)
          Return string representation of obj based on chosen type allowing for simple conversions between numeric types as required, such as converting an Integer obj to DBL_TYPE and the reverse.
static String toString(int type, Object obj)
          Return result of calling toString(int, Object, com.ca.commons.datamodel.DataModelValue.ConversionSettings) with a null last argument.
static String toString(int legacyType, Object obj, DataModelValue.ConversionSettings convSettings)
          Deprecated. This method takes legacy int values for the type and throws a runtime exception for unparsable strings, which is bad. Use the getValue(DataModelType, String) or toString(DataModelType, Object, ConversionSettings) methods instead.
 String toTypeString()
          Deprecated. Use getTypeString() instead.
<T> T
value(Class<? extends T> type)
           
<T> T
value(T defaultValue)
           
<T> T
value(T defaultValue, Class<? extends T> type)
           
static com.ca.commons.functional.Fn<Object,DataModelValue> valueMaker(DataModelType dataModelType)
           
<T> com.ca.commons.functional.Option<T>
valueOpt(Class<? extends T> type)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final Logger logger

UTC_TIMEZONE

public static final TimeZone UTC_TIMEZONE

UNDEF_TYPE

@Deprecated
public static final int UNDEF_TYPE
Deprecated. 
See Also:
Constant Field Values

BOOL_TYPE

@Deprecated
public static final int BOOL_TYPE
Deprecated. 
See Also:
Constant Field Values

INT_TYPE

@Deprecated
public static final int INT_TYPE
Deprecated. 
See Also:
Constant Field Values

DBL_TYPE

@Deprecated
public static final int DBL_TYPE
Deprecated. 
See Also:
Constant Field Values

STR_TYPE

@Deprecated
public static final int STR_TYPE
Deprecated. 
See Also:
Constant Field Values

DATE_TYPE

@Deprecated
public static final int DATE_TYPE
Deprecated. 
See Also:
Constant Field Values

TIME_TYPE

@Deprecated
public static final int TIME_TYPE
Deprecated. 
See Also:
Constant Field Values

ENUM_TYPE

@Deprecated
public static final int ENUM_TYPE
Deprecated. 
See Also:
Constant Field Values

FLEXI_STR_TYPE

@Deprecated
public static final int FLEXI_STR_TYPE
Deprecated. 
See Also:
Constant Field Values

SEQ_TYPE

@Deprecated
public static final int SEQ_TYPE
Deprecated. 
See Also:
Constant Field Values

SET_TYPE

@Deprecated
public static final int SET_TYPE
Deprecated. 
See Also:
Constant Field Values

LONG_TYPE

@Deprecated
public static final int LONG_TYPE
Deprecated. 
See Also:
Constant Field Values

DATE_TIME_TYPE

@Deprecated
public static final int DATE_TIME_TYPE
Deprecated. 
See Also:
Constant Field Values

FLOAT_TYPE

@Deprecated
public static final int FLOAT_TYPE
Deprecated. 
See Also:
Constant Field Values

DURATION_TYPE

@Deprecated
public static final int DURATION_TYPE
Deprecated. 
See Also:
Constant Field Values

BINARY_TYPE

@Deprecated
public static final int BINARY_TYPE
Deprecated. 
See Also:
Constant Field Values

ANY_TYPE

@Deprecated
public static final int ANY_TYPE
Deprecated. 
See Also:
Constant Field Values

MAP_TYPE

@Deprecated
public static final int MAP_TYPE
Deprecated. 
See Also:
Constant Field Values
Constructor Detail

DataModelValue

public DataModelValue(@NotNull
                      DataModelType type,
                      @NotNull
                      Object value,
                      boolean isDefault)

DataModelValue

public DataModelValue(@NotNull
                      DataModelType type,
                      @NotNull
                      Object value)

DataModelValue

public DataModelValue(@NotNull
                      DataModelType type)
For internal use where a typed, but empty, value is required.

Method Detail

newXsdDateFormat

public static DateFormat newXsdDateFormat()

newXsdDateTimeFormat

public static DateFormat newXsdDateTimeFormat()

newXsdDateTimeMillisFormat

public static DateFormat newXsdDateTimeMillisFormat()

newXsdTimeFormat

public static DateFormat newXsdTimeFormat()

newXsdTimeMillisFormat

public static DateFormat newXsdTimeMillisFormat()

newStringValue

@NotNull
public static DataModelValue newStringValue(@NotNull
                                                    String s)

newIntValue

@NotNull
public static DataModelValue newIntValue(int i)

newBooleanValue

@NotNull
public static DataModelValue newBooleanValue(boolean b)

fnValue

@NotNull
public static <T> com.ca.commons.functional.Fn<DataModelValue,com.ca.commons.functional.Option<T>> fnValue(@NotNull
                                                                                                                   Class<? extends T> type)

valueMaker

@NotNull
public static com.ca.commons.functional.Fn<Object,DataModelValue> valueMaker(@NotNull
                                                                                     DataModelType dataModelType)

fnIsType

public static com.ca.commons.functional.Pred<DataModelValue> fnIsType(DataModelType dmType)

copy

public DataModelValue copy()

changeValue

@NotNull
public DataModelValue changeValue(@NotNull
                                          Object newValue)

getType

@NotNull
public final DataModelType getType()

isType

public final boolean isType(@Nullable
                            DataModelType type)

getValue

@Nullable
public final Object getValue()
Returns:
Value matching one of *_TYPE constants (primitive types will be wrapped.

getValueAsString

@Nullable
public String getValueAsString(DataModelValue.ConversionSettings convSettings)
Return string representation of contained value, or null for collections, where convSettings will default to DEFAULT_CONVERSION_SETTINGS if null.


getValueAsString

@Nullable
public String getValueAsString()
Calls getValueAsString(com.ca.commons.datamodel.DataModelValue.ConversionSettings) with null argument.


isDefault

public boolean isDefault()
Does the contained value (for primitives) act as a default? True if "ignoreValue" isn't provided in the XML.


getNestedValue

public DataModelValue getNestedValue()
Return "this" for simple (non-collection) values, otherwise return the basetype for the collection.


getCompoundValueClassRef

public ClassReference getCompoundValueClassRef()

getCompoundValueClassRefClass

public String getCompoundValueClassRefClass()

getClassRefClass

public static String getClassRefClass(ClassReference ref)

getCompoundValueClassRefStr

public String getCompoundValueClassRefStr()
Return fully qualified name referencing compound value class.


getBool

public boolean getBool()

getInt

public int getInt()

getDbl

public double getDbl()

getStr

public String getStr()

getDate

public Date getDate()

getDateTime

public Date getDateTime()

getLong

public long getLong()

getTime

public Date getTime()

getFloat

public float getFloat()

getEnum

public DataModelEnumValue getEnum()

getFlexiStr

public DataModelFlexiStrValue getFlexiStr()

getCollection

public DataModelCollectionValue getCollection()

getSeq

public Collection<DataModelValue> getSeq()

getSet

public Collection<DataModelValue> getSet()

getMap

public DataModelMapValue getMap()

getBinary

public DataModelBinaryValue getBinary()

getDuration

public Duration getDuration()

getAny

public Object getAny()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

initTypeString

public void initTypeString()
String signifying logical type for value contained, eg for validation purposes.


getTypeString

public String getTypeString()
Return full qualified stype for this value, eg "BOOL" or "FLEXI_STR:DN".


toTypeString

@Deprecated
public String toTypeString()
Deprecated. Use getTypeString() instead.


getBaseTypeString

public String getBaseTypeString()
Null if type for this value is not compound, otherwise return base type string, eg returns "FLEXI_STR" when "FLEXI_STR:DN" is passed in.


toString

public static String toString(DataModelType type,
                              Object obj,
                              DataModelValue.ConversionSettings convSettings)
                       throws ParseException
Return string representation of obj based on chosen type allowing for simple conversions between numeric types as required, such as converting an Integer obj to DBL_TYPE and the reverse.

Parameters:
type - Chosen from *_TYPE constants defined in this class.
obj - Object to be converted to a string.
convSettings - Settings to modulate conversion behaviour, if null then DEFAULT_CONVERSION_SETTINGS will be used.
Returns:
The value found by parsing the string. The class of the returned object will correspond to the type passed. Primitive types will be wrapped.
Throws:
IllegalArgumentException - if the provided value could not be parsed according to the specified data model type.
ParseException

toString

@Deprecated
public static String toString(int legacyType,
                                         Object obj,
                                         DataModelValue.ConversionSettings convSettings)
Deprecated. This method takes legacy int values for the type and throws a runtime exception for unparsable strings, which is bad. Use the getValue(DataModelType, String) or toString(DataModelType, Object, ConversionSettings) methods instead.

Parses a string to find a data model value of a specified type.

Parameters:
legacyType - The data type to parse the string for.
obj - The string to parse.
convSettings - Settings to modulate conversion behaviour, if null then DEFAULT_CONVERSION_SETTINGS will be used.
Returns:
The value found by parsing the string. The class of the returned object will correspond to the type passed. Primitive types will be wrapped.
Throws:
IllegalArgumentException - if the provided value could not be parsed according to the specified data model type.

toString

public static String toString(int type,
                              Object obj)
Return result of calling toString(int, Object, com.ca.commons.datamodel.DataModelValue.ConversionSettings) with a null last argument.


fromString

public static Object fromString(DataModelType type,
                                String value,
                                DataModelValue.ConversionSettings convSettings)
                         throws ParseException
Parses a string to find a data model value of a specified type.

Parameters:
type - The data type to parse the string for.
value - The string to parse.
convSettings - Settings offering fine-grain control of conversion behaviour, if null then DEFAULT_CONVERSION_SETTINGS will be used.
Returns:
The value found by parsing the string. The class of the returned object will correspond to the type passed. Primitive types will be wrapped.
Throws:
ParseException - if the string value provided could not be parsed according to the specified data model type.

stringValue

@Nullable
public String stringValue(@Nullable
                                   String defaultValue)

value

@NotNull
public <T> T value(@NotNull
                           T defaultValue)

value

@Nullable
public <T> T value(@Nullable
                            T defaultValue,
                            @NotNull
                            Class<? extends T> type)

value

@Nullable
public <T> T value(@NotNull
                            Class<? extends T> type)

valueOpt

@NotNull
public <T> com.ca.commons.functional.Option<T> valueOpt(@NotNull
                                                                Class<? extends T> type)

fromString

public static Object fromString(DataModelType type,
                                String str)
                         throws ParseException
Calls fromString(DataModelType, String, ConversionSettings) with null last argument.

Throws:
ParseException

fromString

@Deprecated
public static Object fromString(int type,
                                           String str)
Deprecated. Use version taking a DataModelType instead of legacy int.

Calls fromString(int, String, ConversionSettings) with null last argument.


fromString

@Deprecated
public static Object fromString(int legacyType,
                                           String value,
                                           DataModelValue.ConversionSettings convSettings)
Deprecated. Use version taking DataModelType instead of legacy int.


getValue

@Deprecated
public static Object getValue(int legacyType,
                                         String value)
Deprecated. Use fromString instead.

Just calls fromString(int, String).


getValue

@Deprecated
public static Object getValue(DataModelType type,
                                         String value)
Deprecated. Use fromString instead.

Just calls fromString(DataModelType, String).



Created 2011-07-14 13:27 EST