org.deduced.xml
Class XmlModelDecoder

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

public class XmlModelDecoder
extends java.lang.Object

XmlPropertyDecoder

Author:
Steve McDuff

Nested Class Summary
private static class XmlModelDecoder.CollectionToElementAssociation
          CollectionToElementAssociation : utility class used to store the association between the collection in the DOM and its element.
private static class XmlModelDecoder.PropertyToElementAssociation
          PropertyToElementAssociation : used to store the association between a DOM element representing a property value and the collection that will be modified by this property
 
Field Summary
private  java.util.List<XmlModelDecoder.PropertyToElementAssociation> collectionByValuePropertyCreationList
          list of all the properties that will create collections by value in the order in which they are read in the DOM.
private  java.util.Map<java.lang.Long,XmlModelDecoder.CollectionToElementAssociation> collectionCreationMap
          Map of all the collections that will be created when reading the DOM.
private  org.w3c.dom.Document document
          DOM document created from the XML structure
private  java.util.List<DecodeException> errorList
          list of non-fatal errors that occurred
private  java.io.InputStream inputStream
          input stream from which the XML document is read
private  java.util.Map<java.lang.Long,PropertyCollection<?,?>> instanceMap
          list of all the instances contained in this document.
private  java.util.Map<java.lang.Long,java.lang.Long> lateCreationMap
          Map of all the collections that may not be created first because they will be created later by their parent.
private static java.util.logging.Logger LOGGER
          Logger
private  ModelFactory modelCreationController
          controller that will be used to create the model implementations
private  NameReferenceFinder nameReferenceFinder
          name reference finder
private  java.util.List<XmlModelDecoder.PropertyToElementAssociation> propertyCreationList
          list of all the properties that will be read in the DOM in the order in which they are read in the DOM.
private  PropertyCollection<?,?> readResult
          collection associated with the root ID in the DOM.
private  java.util.Map<java.lang.Long,PropertyCollection<?,?>> referenceCreationMap
          Map of all the collections that will be referenced when reading the DOM.
private  org.w3c.dom.Element referenceListElement
          the children of this element contains the collection held by reference
private  org.w3c.dom.Element rootElement
          root element of the DOM containing the root collection ID
private  java.lang.Long rootID
          root collection ID that will be returned when reading the DOM
private  org.w3c.dom.Element schemaListElement
          the schema list element.
private  java.util.Map<java.lang.Long,XmlModelDecoder.CollectionToElementAssociation> startCreationMap
          map of all the the collections that hold children by value which have no parent.
private  boolean stoppedOnError
          should the decoder stop when it reaches a non-fatal error
private  org.w3c.dom.Element typeListElement
          the children of this element contain the summary of all the types and instances from the document
private  java.util.Map<java.lang.Long,PropertyCollection<?,?>> typeMap
          list of all the types contained in this document.
private  org.w3c.dom.Element valueListElement
          the children of this element contains the collections instances and values that will be read
 
Constructor Summary
XmlModelDecoder()
          create a XML Model Decoder
 
Method Summary
private  void activateAllCreatedCollections()
          activate All Created Collections
private  void addAllReferencedChildren(org.w3c.dom.Element readElement, PropertyCollection<?,?> parentCollection)
          add All Reference Children
private  void addAllSchemaToModelLayerSchemaList(PropertyCollection<?,?> modelLayer, org.w3c.dom.Element setSchemaListElement)
          add All Schema To Model Layer Schema List
private  void addAllSubPropertiesCollections(XmlModelDecoder.CollectionToElementAssociation collection)
          add All Sub Properties Collections
private  void addInstance(org.w3c.dom.Element instanceElement, PropertyCollection<?,?> currentType)
          add Instance to a type
private  void addInstances(PropertyCollection<?,?> currentType, org.w3c.dom.Element typeElement)
          add Instances to a type
private  void addPackage(java.util.List<PropertyCollection<?,?>> currentPackages, org.w3c.dom.Element packageElement)
          read a package object from the xml document
private  void addPackageSubPackages(java.util.List<PropertyCollection<?,?>> currentPackages, org.w3c.dom.Element packagePackageListElement)
          read the list of sub package on a package element
private  void addPackageSubTypes(java.util.List<PropertyCollection<?,?>> currentPackages, org.w3c.dom.Element packageTypeListElement)
          read all the types in a package
private  void addPackageWithName(java.util.List<PropertyCollection<?,?>> currentPackages, org.w3c.dom.Element subPackageElement)
          read packages based on name
private  void addProperty(org.w3c.dom.Element propertyElement, XmlModelDecoder.CollectionToElementAssociation collection)
          add a Property to a collection
private  void addPropertyValueCollections(org.w3c.dom.Element propertyElement)
          add a property value linked to a collection
private  void addSchema(PropertyCollection modelSchemaList, org.w3c.dom.Element schemaElement)
          read a schema element from the xml document
private  void addType(java.util.List<PropertyCollection<?,?>> currentPackages, org.w3c.dom.Element typeElement)
          read a type definition
private  void analyzeOrder(XmlModelDecoder.PropertyToElementAssociation property)
          analyze the order in which a property needs to be built
private  XmlModelDecoder.CollectionToElementAssociation assignPropertyValueHandleNonFatalErrors(XmlModelDecoder.PropertyToElementAssociation property)
          Assign Property Value and handle all the non fatal errors
private
<K,V> XmlModelDecoder.CollectionToElementAssociation
assignPropertyValueThrowOnError(XmlModelDecoder.PropertyToElementAssociation property)
          assign Property Value.
private  void assignReturnValue()
          assign Return Value
private  void buildAllSubChildren(XmlModelDecoder.CollectionToElementAssociation parent)
          build All Sub Children
private  void cleanupTemporaryObjects()
          clear any temporary object lists
private  void createCollectionElement(org.w3c.dom.Element readElement)
          create Collection Element
private  java.lang.String createExtractSchemaListIDXPath()
          create Extract Schema List ID XPath
private  void createNamedReferenceFinder(PropertyCollection<?,?> modelLayer, PropertyCollection<?,?> applicationModel)
          create Named Reference Finder
private  void createProperties(XmlModelDecoder.CollectionToElementAssociation collection)
          create Properties
private  void createReferencedElement(org.w3c.dom.Element readElement, PropertyCollection<?,?> parentCollection)
          create a referenced element
 boolean didErrorsOccur()
          test to see if any errors were encountered while reading a property collection.
static java.lang.Object executeXPath(java.lang.String xpathExpression, javax.xml.namespace.QName resultType, org.w3c.dom.Document document)
          execute XPath
private  void extractModelFactory(PropertyCollection<?,?> modelLayer)
          extract Model Factory from the model layer
private  void extractSchemaListElement(PropertyCollection<?,?> modelLayer, java.lang.String schemaListID, org.w3c.dom.NodeList instanceChildNodes)
          extract Schema List Element
private  org.w3c.dom.NodeList extractSchemaNodeList(org.w3c.dom.Element setSchemaListElement)
          extract Schema Node List
private  java.lang.String fetchChildCollectionID(org.w3c.dom.Element propertyElement)
          fetch a child collection ID from the XML document
private  java.lang.String fetchCollectionValueString(org.w3c.dom.Element propertyElement)
          fetch Collection Value String from a DOM element
private  void fillByValueProperties()
          fillByValueProperties to prevent multiple cloning of objects, create them in the right order ( starting from the parents and going down to the last child )
private  void fillProperties()
          fillByValueProperties
private static PropertyCollection<?,?> findInstanceByNameInListInstanceList(java.lang.String name, PropertyCollection currentTypeInstanceList)
          find Instance By Name In List Instance List
private static PropertyCollection<?,?> findInstanceByNameInParentTypeList(PropertyCollection<?,?> currentType, java.lang.String name, java.util.IdentityHashMap<PropertyCollection<?,?>,PropertyCollection<?,?>> parsedTypes)
          find Instance By Name In Parent Type List
protected static PropertyCollection<?,?> findPropertyInstance(PropertyCollection<?,?> currentType, java.lang.String name)
          find Property Instance in a type
private
<K> K
findPropertyKey(XmlModelDecoder.PropertyToElementAssociation property)
          find Property Key
private  PropertyCollection<?,?> findTypeByNameFromPackageList(java.util.List<PropertyCollection<?,?>> currentPackages, java.lang.String name)
          find Type By Name From Package List
 java.util.List<DecodeException> getErrorList()
           
 java.io.InputStream getInputStream()
           
private  org.w3c.dom.Element getNamedChild(org.w3c.dom.Element parentElement, java.lang.String tagName)
          find a named child element
private  java.util.List<org.w3c.dom.Element> getNamedChildList(org.w3c.dom.Element packageElement, java.lang.String tagName)
          fetch the list of all the xml children of element type that match a specified name
private  DecodeException handleFatalError(DecodeException exception)
          handle Fatal Error
private  void handleNonFatalError(DecodeException exception)
          handle Non Fatal Error
 boolean isStoppedOnError()
           
private  void logSchemeListIdStatus(java.lang.String schemaListID)
          log Scheme List Id Status
private  void parseAllProperties()
          parse All Properties
private  boolean parseBooleanFlag(java.lang.String booleanFlag, boolean defaultValue)
          parse Is Null Flag
private  void parseCollections()
          parse property collections
private  void parseDocument()
          parse the xml document
protected static org.w3c.dom.Document parseDocumentFromFactory(javax.xml.parsers.DocumentBuilderFactory factory, java.io.InputStream in)
          parse Document From Factory
private  boolean parseIsNullFlag(java.lang.String isNullString)
          parse Is Null Flag
private  void parseModelSchemaList(PropertyCollection<?,?> modelLayer)
          parse Model Schema List
private  void parseReference()
          parse the list of references
private  void parseTypeAndInstanceMap(PropertyCollection<?,?> modelLayer)
          build Type And Instance Map
 PropertyCollection<?,?> readObject(PropertyCollection<?,?> rootResult)
          read the object in this decoder and specify the property collection that should be used as the root of the decoding operation
 PropertyCollection<?,?> readObject(PropertyCollection<?,?> modelLayer, PropertyCollection<?,?> rootResult, PropertyCollection<?,?> applicationModel)
          read a property collection.
protected static PropertyCollection<?,?> recursiveFindPropertyInstance(PropertyCollection<?,?> currentType, java.lang.String name, java.util.IdentityHashMap<PropertyCollection<?,?>,PropertyCollection<?,?>> parsedTypes)
          recursively Find a Property Instance by name on a type
private  void replaceRootCollection(PropertyCollection<?,?> rootResult)
          replace Root Collection
 void setInputStream(java.io.InputStream setStream)
           
private
<K,V> void
setPropertyOnCollectionAndDeletePreviousValueIfRequired(PropertyCollection<K,V> collectionToSet, K key, PropertyCollection<?,?> instance, V value)
          set Property On Collection And Delete Previous Value If Required
 void setStoppedOnError(boolean isStoppedOnError)
           
private
<K,V> void
setValueOnCollection(PropertyCollection<K,V> collectionToSet, K key, PropertyCollection<?,?> instance, V value)
          set Value On Collection
private
<V> void
updateMapFixedInstance(V value, PropertyCollection<?,?> instance)
          update Map Fixed Instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER
Logger


inputStream

private java.io.InputStream inputStream
input stream from which the XML document is read


document

private org.w3c.dom.Document document
DOM document created from the XML structure


rootElement

private org.w3c.dom.Element rootElement
root element of the DOM containing the root collection ID


typeListElement

private org.w3c.dom.Element typeListElement
the children of this element contain the summary of all the types and instances from the document


valueListElement

private org.w3c.dom.Element valueListElement
the children of this element contains the collections instances and values that will be read


referenceListElement

private org.w3c.dom.Element referenceListElement
the children of this element contains the collection held by reference


schemaListElement

private org.w3c.dom.Element schemaListElement
the schema list element. Only used when parsing a DeducedModelLayer as the root


rootID

private java.lang.Long rootID
root collection ID that will be returned when reading the DOM


typeMap

private java.util.Map<java.lang.Long,PropertyCollection<?,?>> typeMap
list of all the types contained in this document. Stores PropertyType objects in reference to the Long ID assigned in the DOM


instanceMap

private java.util.Map<java.lang.Long,PropertyCollection<?,?>> instanceMap
list of all the instances contained in this document. Stores PropertyInstance objects in reference to the Long ID assigned in the DOM


collectionCreationMap

private java.util.Map<java.lang.Long,XmlModelDecoder.CollectionToElementAssociation> collectionCreationMap
Map of all the collections that will be created when reading the DOM. Stores CollectionToElementAssociation in reference to the unique ID assigned to the collection in the DOM


referenceCreationMap

private java.util.Map<java.lang.Long,PropertyCollection<?,?>> referenceCreationMap
Map of all the collections that will be referenced when reading the DOM. Stores PropertyCollection in reference to the unique ID assigned to the collection in the DOM


propertyCreationList

private java.util.List<XmlModelDecoder.PropertyToElementAssociation> propertyCreationList
list of all the properties that will be read in the DOM in the order in which they are read in the DOM. stores PropertyToElementAssociation. This list doesn't hold properties that create collections by value since they will be created earlier in the process to keep references correctly.


collectionByValuePropertyCreationList

private java.util.List<XmlModelDecoder.PropertyToElementAssociation> collectionByValuePropertyCreationList
list of all the properties that will create collections by value in the order in which they are read in the DOM. those properties are ordered in creation order so that construction will start from the root parent and build its way up.


startCreationMap

private java.util.Map<java.lang.Long,XmlModelDecoder.CollectionToElementAssociation> startCreationMap
map of all the the collections that hold children by value which have no parent. The creation of children by value starts with the collections held in this map. Stores CollectionToElementAssociation and keys them by the collection ID they hold.


lateCreationMap

private java.util.Map<java.lang.Long,java.lang.Long> lateCreationMap
Map of all the collections that may not be created first because they will be created later by their parent. This map stores and keys the unique ID of collections that can't be created first.


readResult

private PropertyCollection<?,?> readResult
collection associated with the root ID in the DOM. This collection will be returned when the DOM is entirely decoded.


stoppedOnError

private boolean stoppedOnError
should the decoder stop when it reaches a non-fatal error


errorList

private java.util.List<DecodeException> errorList
list of non-fatal errors that occurred


modelCreationController

private ModelFactory modelCreationController
controller that will be used to create the model implementations


nameReferenceFinder

private NameReferenceFinder nameReferenceFinder
name reference finder

Constructor Detail

XmlModelDecoder

public XmlModelDecoder()
create a XML Model Decoder

Method Detail

isStoppedOnError

public boolean isStoppedOnError()
Returns:
Returns the stoppedOnError.

setStoppedOnError

public void setStoppedOnError(boolean isStoppedOnError)
Parameters:
isStoppedOnError - The stoppedOnError to set.

getErrorList

public java.util.List<DecodeException> getErrorList()
Returns:
Returns the errorList.

didErrorsOccur

public boolean didErrorsOccur()
test to see if any errors were encountered while reading a property collection.

Returns:
true if any error was encountered.

readObject

public PropertyCollection<?,?> readObject(PropertyCollection<?,?> rootResult)
                                   throws DecodeException
read the object in this decoder and specify the property collection that should be used as the root of the decoding operation

Parameters:
rootResult - the root collection that will be read
Returns:
a the read object
Throws:
DecodeException - any error that occurred during the decoding

readObject

public PropertyCollection<?,?> readObject(PropertyCollection<?,?> modelLayer,
                                          PropertyCollection<?,?> rootResult,
                                          PropertyCollection<?,?> applicationModel)
                                   throws DecodeException
read a property collection. The root result is expected to reside within the model layer. The model layer is expected to have the required model factory to create all the types contained in the XML file. The application hub will be used to associate any required dependency and schema to the model layer. Note that this method will throw a DecodeException only if a fatal error is encountered. Other errors will be captured. It is strongly recommended to read the error list after reading a XML file.

Parameters:
modelLayer - the model layer containing the result. If Null, then it is assumed that we are reading a model layer that is self contained.
rootResult - the root result that will be read. This parameter can be the same as the model layer.
applicationModel - the application model will be used to find any references required to read the XML file.
Returns:
the property collection that was read from the XML file
Throws:
DecodeException - any fatal error encountered while reading the XML file.

parseModelSchemaList

private void parseModelSchemaList(PropertyCollection<?,?> modelLayer)
                           throws DecodeException
parse Model Schema List

Parameters:
modelLayer - the model layer
Throws:
DecodeException - unexpected decoding exceptions

extractSchemaListElement

private void extractSchemaListElement(PropertyCollection<?,?> modelLayer,
                                      java.lang.String schemaListID,
                                      org.w3c.dom.NodeList instanceChildNodes)
                               throws DecodeException
extract Schema List Element

Parameters:
modelLayer - the model layer in which to fill the list of schema
schemaListID - the schema list ID
instanceChildNodes - the list of possible child nodes for the schema list
Throws:
DecodeException - if decoding the schema list fails

logSchemeListIdStatus

private void logSchemeListIdStatus(java.lang.String schemaListID)
log Scheme List Id Status

Parameters:
schemaListID - the schema list ID

createExtractSchemaListIDXPath

private java.lang.String createExtractSchemaListIDXPath()
create Extract Schema List ID XPath

Returns:
the XPath expression

executeXPath

public static java.lang.Object executeXPath(java.lang.String xpathExpression,
                                            javax.xml.namespace.QName resultType,
                                            org.w3c.dom.Document document)
                                     throws DecodeException
execute XPath

Parameters:
xpathExpression - the XPath expression to use
resultType - the type of result expected
document - the document to parse
Returns:
the XPath result
Throws:
DecodeException - for any error encountered

addAllSchemaToModelLayerSchemaList

private void addAllSchemaToModelLayerSchemaList(PropertyCollection<?,?> modelLayer,
                                                org.w3c.dom.Element setSchemaListElement)
                                         throws DecodeException
add All Schema To Model Layer Schema List

Parameters:
modelLayer - the model layer
setSchemaListElement - the schema list element
Throws:
DecodeException - if decoding fails

extractSchemaNodeList

private org.w3c.dom.NodeList extractSchemaNodeList(org.w3c.dom.Element setSchemaListElement)
extract Schema Node List

Parameters:
setSchemaListElement - the schema list element
Returns:
the schema node list

extractModelFactory

private void extractModelFactory(PropertyCollection<?,?> modelLayer)
                          throws DecodeException
extract Model Factory from the model layer

Parameters:
modelLayer - the model factory
Throws:
DecodeException - unexpected decoding exceptions

createNamedReferenceFinder

private void createNamedReferenceFinder(PropertyCollection<?,?> modelLayer,
                                        PropertyCollection<?,?> applicationModel)
                                 throws DecodeException
create Named Reference Finder

Parameters:
modelLayer - the model layer being used
applicationModel - the application model
Throws:
DecodeException - if the name reference finder creation fails.

activateAllCreatedCollections

private void activateAllCreatedCollections()
activate All Created Collections


parseReference

private void parseReference()
                     throws DecodeException
parse the list of references

Throws:
DecodeException - when references can't be found

addAllReferencedChildren

private void addAllReferencedChildren(org.w3c.dom.Element readElement,
                                      PropertyCollection<?,?> parentCollection)
                               throws DecodeException
add All Reference Children

Parameters:
readElement - the reference element to read
parentCollection - the parent collection
Throws:
DecodeException - when references can't be found

createReferencedElement

private void createReferencedElement(org.w3c.dom.Element readElement,
                                     PropertyCollection<?,?> parentCollection)
                              throws DecodeException
create a referenced element

Parameters:
readElement - the xml element
parentCollection - the parent collection
Throws:
DecodeException - when references can't be found

cleanupTemporaryObjects

private void cleanupTemporaryObjects()
clear any temporary object lists


replaceRootCollection

private void replaceRootCollection(PropertyCollection<?,?> rootResult)
                            throws DecodeException
replace Root Collection

Parameters:
rootResult - the root result to replace
Throws:
DecodeException - when the root collection and the read type don't match

fillByValueProperties

private void fillByValueProperties()
                            throws DecodeException
fillByValueProperties to prevent multiple cloning of objects, create them in the right order ( starting from the parents and going down to the last child )

Throws:
DecodeException - when decoding a property fails

buildAllSubChildren

private void buildAllSubChildren(XmlModelDecoder.CollectionToElementAssociation parent)
                          throws DecodeException
build All Sub Children

Parameters:
parent - the parent collection
Throws:
DecodeException - when decoding a property fails

analyzeOrder

private void analyzeOrder(XmlModelDecoder.PropertyToElementAssociation property)
                   throws DecodeException
analyze the order in which a property needs to be built

Parameters:
property - the property to analyze
Throws:
DecodeException - when decoding a property fails

fetchChildCollectionID

private java.lang.String fetchChildCollectionID(org.w3c.dom.Element propertyElement)
fetch a child collection ID from the XML document

Parameters:
propertyElement - the xml element
Returns:
the child collection ID

assignReturnValue

private void assignReturnValue()
assign Return Value


parseAllProperties

private void parseAllProperties()
                         throws DecodeException
parse All Properties

Throws:
DecodeException - when decoding a property fails

createProperties

private void createProperties(XmlModelDecoder.CollectionToElementAssociation collection)
                       throws DecodeException
create Properties

Parameters:
collection - the collection to element association on which to create properties
Throws:
DecodeException - when decoding a property fails

addProperty

private void addProperty(org.w3c.dom.Element propertyElement,
                         XmlModelDecoder.CollectionToElementAssociation collection)
                  throws DecodeException
add a Property to a collection

Parameters:
propertyElement - the xml property element
collection - the collection to associate
Throws:
DecodeException - when decoding a property fails

fillProperties

private void fillProperties()
                     throws DecodeException
fillByValueProperties

Throws:
DecodeException - when decoding a property fails

assignPropertyValueHandleNonFatalErrors

private XmlModelDecoder.CollectionToElementAssociation assignPropertyValueHandleNonFatalErrors(XmlModelDecoder.PropertyToElementAssociation property)
                                                                                        throws DecodeException
Assign Property Value and handle all the non fatal errors

Parameters:
property - the property to assign
Returns:
the property to element association
Throws:
DecodeException - when decoding a property fails

fetchCollectionValueString

private java.lang.String fetchCollectionValueString(org.w3c.dom.Element propertyElement)
fetch Collection Value String from a DOM element

Parameters:
propertyElement - the element to read
Returns:
the collection value string

assignPropertyValueThrowOnError

private <K,V> XmlModelDecoder.CollectionToElementAssociation assignPropertyValueThrowOnError(XmlModelDecoder.PropertyToElementAssociation property)
                                                                                throws DecodeException
assign Property Value. If this method detects errors, it should always throw the error directly and not call handleNonFatalError. The method internal

Type Parameters:
K - the type of key being read
V - the type of value being read
Parameters:
property - the property to element association
Returns:
the association
Throws:
DecodeException - when decoding a property fails

setValueOnCollection

private <K,V> void setValueOnCollection(PropertyCollection<K,V> collectionToSet,
                                        K key,
                                        PropertyCollection<?,?> instance,
                                        V value)
set Value On Collection

Type Parameters:
K - the current key type
V - the current value type
Parameters:
collectionToSet - the collection on which to set the value
key - the value key
instance - the instance to set
value - the value to set

setPropertyOnCollectionAndDeletePreviousValueIfRequired

private <K,V> void setPropertyOnCollectionAndDeletePreviousValueIfRequired(PropertyCollection<K,V> collectionToSet,
                                                                           K key,
                                                                           PropertyCollection<?,?> instance,
                                                                           V value)
set Property On Collection And Delete Previous Value If Required

Type Parameters:
K - the current key type
V - the current value type
Parameters:
collectionToSet - the collection on which to set the value
key - the value key
instance - the instance to set
value - the value to set

updateMapFixedInstance

private <V> void updateMapFixedInstance(V value,
                                        PropertyCollection<?,?> instance)
update Map Fixed Instance

Type Parameters:
V - the current value type
Parameters:
value - the value on which to update the fixed instance, if applicable
instance - the instance that might be a list instance with a fixed instance value.

parseIsNullFlag

private boolean parseIsNullFlag(java.lang.String isNullString)
parse Is Null Flag

Parameters:
isNullString - the is null string
Returns:
true if the null flag is set

parseBooleanFlag

private boolean parseBooleanFlag(java.lang.String booleanFlag,
                                 boolean defaultValue)
parse Is Null Flag

Parameters:
booleanFlag - the null flag string
defaultValue - the default value if the flag is empty
Returns:
true if the null flag is set or if the default value is true and the flag is empty

findPropertyKey

private <K> K findPropertyKey(XmlModelDecoder.PropertyToElementAssociation property)
                   throws DecodeException
find Property Key

Type Parameters:
K - the type of key to read
Parameters:
property - the property association
Returns:
the created key
Throws:
DecodeException - when decoding a property fails

parseTypeAndInstanceMap

private void parseTypeAndInstanceMap(PropertyCollection<?,?> modelLayer)
                              throws DecodeException
build Type And Instance Map

Parameters:
modelLayer - the model layer to parse
Throws:
DecodeException - when decoding a property fails

addSchema

private void addSchema(PropertyCollection modelSchemaList,
                       org.w3c.dom.Element schemaElement)
                throws DecodeException
read a schema element from the xml document

Parameters:
modelSchemaList - the model schema list
schemaElement - the schema element to read
Throws:
DecodeException - when a schema can't be found

addPackage

private void addPackage(java.util.List<PropertyCollection<?,?>> currentPackages,
                        org.w3c.dom.Element packageElement)
                 throws DecodeException
read a package object from the xml document

Parameters:
currentPackages - the current package list
packageElement - the package xml element
Throws:
DecodeException - when decoding a package fails

getNamedChildList

private java.util.List<org.w3c.dom.Element> getNamedChildList(org.w3c.dom.Element packageElement,
                                                              java.lang.String tagName)
fetch the list of all the xml children of element type that match a specified name

Parameters:
packageElement - the package element
tagName - the name we are looking for
Returns:
the list of all children elements that match the specified name

getNamedChild

private org.w3c.dom.Element getNamedChild(org.w3c.dom.Element parentElement,
                                          java.lang.String tagName)
find a named child element

Parameters:
parentElement - the parent element
tagName - the child name to look for
Returns:
the found child. Null if none were found.

addPackageSubPackages

private void addPackageSubPackages(java.util.List<PropertyCollection<?,?>> currentPackages,
                                   org.w3c.dom.Element packagePackageListElement)
                            throws DecodeException
read the list of sub package on a package element

Parameters:
currentPackages - the list of packages
packagePackageListElement - the package list element
Throws:
DecodeException - when decoding a package fails

addPackageWithName

private void addPackageWithName(java.util.List<PropertyCollection<?,?>> currentPackages,
                                org.w3c.dom.Element subPackageElement)
                         throws DecodeException
read packages based on name

Parameters:
currentPackages - current list of child package
subPackageElement - the package element
Throws:
DecodeException - when decoding a package fails

addPackageSubTypes

private void addPackageSubTypes(java.util.List<PropertyCollection<?,?>> currentPackages,
                                org.w3c.dom.Element packageTypeListElement)
                         throws DecodeException
read all the types in a package

Parameters:
currentPackages - the packages being read
packageTypeListElement - the package type list element
Throws:
DecodeException - when decoding a package fails

addInstances

private void addInstances(PropertyCollection<?,?> currentType,
                          org.w3c.dom.Element typeElement)
                   throws DecodeException
add Instances to a type

Parameters:
currentType - the type being read
typeElement - the element representing the type
Throws:
DecodeException - when decoding a property fails

addInstance

private void addInstance(org.w3c.dom.Element instanceElement,
                         PropertyCollection<?,?> currentType)
                  throws DecodeException
add Instance to a type

Parameters:
instanceElement - the instance element to read
currentType - the type being read
Throws:
DecodeException - when decoding a property fails

findPropertyInstance

protected static PropertyCollection<?,?> findPropertyInstance(PropertyCollection<?,?> currentType,
                                                              java.lang.String name)
find Property Instance in a type

Parameters:
currentType - the type to search
name - the name of the instance to look for
Returns:
the instance matching the name. Null if the instance wasn't found.

recursiveFindPropertyInstance

protected static PropertyCollection<?,?> recursiveFindPropertyInstance(PropertyCollection<?,?> currentType,
                                                                       java.lang.String name,
                                                                       java.util.IdentityHashMap<PropertyCollection<?,?>,PropertyCollection<?,?>> parsedTypes)
recursively Find a Property Instance by name on a type

Parameters:
currentType - the type being read
name - the instance name
parsedTypes - the list of types already parsed
Returns:
the found property instance. Null if not found.

findInstanceByNameInParentTypeList

private static PropertyCollection<?,?> findInstanceByNameInParentTypeList(PropertyCollection<?,?> currentType,
                                                                          java.lang.String name,
                                                                          java.util.IdentityHashMap<PropertyCollection<?,?>,PropertyCollection<?,?>> parsedTypes)
find Instance By Name In Parent Type List

Parameters:
currentType - the current type to verify
name - the name of the instance to look for
parsedTypes - the list of types that were already parsed
Returns:
the matched instance, null otherwise

findInstanceByNameInListInstanceList

private static PropertyCollection<?,?> findInstanceByNameInListInstanceList(java.lang.String name,
                                                                            PropertyCollection currentTypeInstanceList)
find Instance By Name In List Instance List

Parameters:
name - the name to look for
currentTypeInstanceList - the instance list
Returns:
the instance matching the required name

handleFatalError

private DecodeException handleFatalError(DecodeException exception)
handle Fatal Error

Parameters:
exception - the fatal error detected
Returns:
DecodeException the exception to throw

handleNonFatalError

private void handleNonFatalError(DecodeException exception)
                          throws DecodeException
handle Non Fatal Error

Parameters:
exception - the non fatal error detected
Throws:
DecodeException - throws a decode exception when the decoder is configured to stop as soon as a problem occurs.

addType

private void addType(java.util.List<PropertyCollection<?,?>> currentPackages,
                     org.w3c.dom.Element typeElement)
              throws DecodeException
read a type definition

Parameters:
currentPackages - the packages that might contain the type
typeElement - the xml element for the type
Throws:
DecodeException - when decoding a type fails

findTypeByNameFromPackageList

private PropertyCollection<?,?> findTypeByNameFromPackageList(java.util.List<PropertyCollection<?,?>> currentPackages,
                                                              java.lang.String name)
find Type By Name From Package List

Parameters:
currentPackages - the package list
name - the type name
Returns:
the identified type

parseCollections

private void parseCollections()
                       throws DecodeException
parse property collections

Throws:
DecodeException - when decoding a property fails

createCollectionElement

private void createCollectionElement(org.w3c.dom.Element readElement)
                              throws DecodeException
create Collection Element

Parameters:
readElement - the xml element being read
Throws:
DecodeException - when decoding a property fails

addAllSubPropertiesCollections

private void addAllSubPropertiesCollections(XmlModelDecoder.CollectionToElementAssociation collection)
                                     throws DecodeException
add All Sub Properties Collections

Parameters:
collection - the collection to element association being read
Throws:
DecodeException - when decoding a property fails

addPropertyValueCollections

private void addPropertyValueCollections(org.w3c.dom.Element propertyElement)
                                  throws DecodeException
add a property value linked to a collection

Parameters:
propertyElement - the xml element representing the property
Throws:
DecodeException - when decoding a property fails

parseDocument

private void parseDocument()
                    throws DecodeException
parse the xml document

Throws:
DecodeException - any error encountered while reading the document

parseDocumentFromFactory

protected static org.w3c.dom.Document parseDocumentFromFactory(javax.xml.parsers.DocumentBuilderFactory factory,
                                                               java.io.InputStream in)
                                                        throws DecodeException
parse Document From Factory

Parameters:
factory - the document factory to use
in - the input stream from which to read the document
Returns:
the read document.
Throws:
DecodeException - any error that occurred while attempting to read the document

getInputStream

public java.io.InputStream getInputStream()
Returns:
Returns the in.

setInputStream

public void setInputStream(java.io.InputStream setStream)
Parameters:
setStream - The input stream to read from.