org.deduced.xml
Class DeducedXmlUtilities

java.lang.Object
  extended by org.deduced.xml.DeducedXmlUtilities

public class DeducedXmlUtilities
extends java.lang.Object

Deduced Xml Utility methods

Author:
Steve McDuff

Field Summary
static java.util.logging.Logger LOGGER
          logger
 
Constructor Summary
DeducedXmlUtilities()
           
 
Method Summary
private static void appendErrorMessage(java.lang.StringBuilder messageBuilder, int errorIndex, DecodeException currentError)
          append Error Message
private static java.lang.String buildMultipleDecodeExceptionMessage(java.util.List<DecodeException> errorList)
          build the exception message
static java.lang.Object createBasicType(java.lang.String className, java.lang.String value, PropertyCollection<?,?> instance)
          Create a basic object type (such as boolean, float, int) from the Specified class name or property instance.
private static boolean isCalendarClass(java.lang.String className)
          check if a class name is a calendar
private static java.lang.Boolean parseBoolean(java.lang.String value)
          parse a Boolean.
private static java.util.Calendar parseCalendar(java.lang.String value)
          read a Calendar from a string.
private static java.lang.Character parseCharacter(java.lang.String value)
          parse a string containing a single character
private static java.lang.Object parseNumberFromClassName(java.lang.String className, java.lang.String value)
          parse Number From Class Name
private static java.lang.Object parseNumericType(PropertyCollection<?,?> valueType, java.lang.String value)
          parse Numeric Type
static java.lang.Object parseStringValueFromClassName(java.lang.String className, java.lang.String value)
          parse a string to create a basic type based on it's class name
static java.lang.Object parseStringValueFromInstance(PropertyCollection<?,?> instance, java.lang.String value)
          read a basic type value from the property instance description
static java.lang.Object parseStringValueFromType(PropertyCollection<?,?> valueType, java.lang.String value)
          parse a basic type value from the property type description
static PropertyCollection<?,?> readModelLayer(java.lang.String fileName, PropertyCollection<?,?> modelLayerToRead, PropertyCollection<?,?> applicationModel, boolean ignoreErrors)
          Utility method to read a model layer from a XML file.
static DecodeException regroupMultipleDecodeException(java.util.List<DecodeException> errorList)
          create a Decode Exception that regroup many exceptions into one.
static void writeModelLayer(java.lang.String fileName, PropertyCollection<?,?> objectToSave, PropertyCollection<?,?> hub)
          save a Model Layer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

public static final java.util.logging.Logger LOGGER
logger

Constructor Detail

DeducedXmlUtilities

public DeducedXmlUtilities()
Method Detail

readModelLayer

public static PropertyCollection<?,?> readModelLayer(java.lang.String fileName,
                                                     PropertyCollection<?,?> modelLayerToRead,
                                                     PropertyCollection<?,?> applicationModel,
                                                     boolean ignoreErrors)
                                              throws java.lang.Exception
Utility method to read a model layer from a XML file. Note that if any error occurs during the loading process (whether they are ignored or not), the state of the passed model layer isn't guaranteed to be complete. Once error occurs, the program should either accept this incompletely loaded state or reject the modelLayer entirely.

Parameters:
fileName - the file name to load.
modelLayerToRead - the model layer to load. If null is specified, the XML Parser will attempt to create the root object to load. If this parameter isn't null and an error occurs during the load process, it is possible that this model layer will contain a partially loaded model.
applicationModel - the application model used to find dependencies
ignoreErrors - if set to true, non-fatal loading errors will be ignored while parsing the XML file. Otherwise an exception will be thrown when non-fatal errors are encountered
Returns:
the loaded model layer. If the modelLayer parameter is specified, then the return value will be the same instance. If a fatal exception occurs and the ignoreErrors parameter is set to true, a null value will be returned.
Throws:
java.io.IOException - any IO exception encountered while reading the file
DecodeException - any decoding exception encountered. If the flag ignoreErrors is set to true, then only fatal decoding exceptions will be thrown. Non-fatal one will be hidden.
java.lang.Exception - any other decoding exception.

regroupMultipleDecodeException

public static DecodeException regroupMultipleDecodeException(java.util.List<DecodeException> errorList)
create a Decode Exception that regroup many exceptions into one.

Parameters:
errorList - the error list
Returns:
the regrouped exception

buildMultipleDecodeExceptionMessage

private static java.lang.String buildMultipleDecodeExceptionMessage(java.util.List<DecodeException> errorList)
build the exception message

Parameters:
errorList - the error list to use
Returns:
the error message that regroup all the errors in the list

appendErrorMessage

private static void appendErrorMessage(java.lang.StringBuilder messageBuilder,
                                       int errorIndex,
                                       DecodeException currentError)
append Error Message

Parameters:
messageBuilder - the message builder to append to
errorIndex - the error index, starting in range 1..*
currentError - the error to append

writeModelLayer

public static void writeModelLayer(java.lang.String fileName,
                                   PropertyCollection<?,?> objectToSave,
                                   PropertyCollection<?,?> hub)
                            throws java.lang.Exception
save a Model Layer

Parameters:
fileName - the file name to save to
objectToSave - the model to save
hub - the application hub used to extract references
Throws:
java.lang.Exception - any error encountered while writing the XML File. Typical errors include @ encoding or IO exception occurs

createBasicType

public static java.lang.Object createBasicType(java.lang.String className,
                                               java.lang.String value,
                                               PropertyCollection<?,?> instance)
                                        throws DecodeException
Create a basic object type (such as boolean, float, int) from the Specified class name or property instance. If both are supplied, the class name will be used to read the value.

Parameters:
className - the class name of the type
value - the string value
instance - the property instance that describes this value
Returns:
the created basic type object
Throws:
DecodeException - any error that occurred during the value decoding

parseStringValueFromClassName

public static java.lang.Object parseStringValueFromClassName(java.lang.String className,
                                                             java.lang.String value)
                                                      throws DecodeException
parse a string to create a basic type based on it's class name

Parameters:
className - the class name
value - the string value of the object
Returns:
the created basic type
Throws:
DecodeException - if the parse operation fails

parseNumberFromClassName

private static java.lang.Object parseNumberFromClassName(java.lang.String className,
                                                         java.lang.String value)
parse Number From Class Name

Parameters:
className - the class name
value - the value to parse
Returns:
the parsed value

parseBoolean

private static java.lang.Boolean parseBoolean(java.lang.String value)
parse a Boolean. Fail if the value is anything but the true or false string value.

Parameters:
value - the string value
Returns:
the boolean value
Throws:
java.lang.IllegalArgumentException - if the value doesn't contain the right boolean value string.

parseCharacter

private static java.lang.Character parseCharacter(java.lang.String value)
parse a string containing a single character

Parameters:
value - the string value
Returns:
the character in the string

isCalendarClass

private static boolean isCalendarClass(java.lang.String className)
check if a class name is a calendar

Parameters:
className - the class name
Returns:
true if the class name is a calendar

parseStringValueFromInstance

public static java.lang.Object parseStringValueFromInstance(PropertyCollection<?,?> instance,
                                                            java.lang.String value)
                                                     throws DecodeException
read a basic type value from the property instance description

Parameters:
instance - the property instance
value - the string value
Returns:
the created basic type. Returns null if the creation failed.
Throws:
DecodeException - if the parse operation failed

parseStringValueFromType

public static java.lang.Object parseStringValueFromType(PropertyCollection<?,?> valueType,
                                                        java.lang.String value)
                                                 throws DecodeException
parse a basic type value from the property type description

Parameters:
valueType - the property type
value - the string value
Returns:
the created basic type. Returns null if the creation failed.
Throws:
DecodeException - if the parse operation failed

parseNumericType

private static java.lang.Object parseNumericType(PropertyCollection<?,?> valueType,
                                                 java.lang.String value)
parse Numeric Type

Parameters:
valueType - the value type
value - the actual value
Returns:
the parsed object

parseCalendar

private static java.util.Calendar parseCalendar(java.lang.String value)
read a Calendar from a string. It is assumed that the string contains a number representing the number of milliseconds required to create a Calendar object.

Parameters:
value - the string value
Returns:
the read calendar