Package org.jfree.xml.util
Class ObjectFactoryLoader
- java.lang.Object
-
- org.jfree.xml.util.AbstractModelReader
-
- org.jfree.xml.util.ObjectFactoryLoader
-
- All Implemented Interfaces:
ObjectFactory
public class ObjectFactoryLoader extends AbstractModelReader implements ObjectFactory
The object factory loader loads the xml specification for the generic handlers. The specification may be distributed over multiple files.This class provides the model management for the reader and writer. The instantiation of the handlers is done elsewhere.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList
attributeDefinition
The attribute definition.private java.lang.String
attributeName
The attribute name.private java.lang.String
baseClass
The base class.private java.util.ArrayList
constructorDefinition
The constructor definition.private java.util.ArrayList
lookupDefinitions
The lookup definitions.private java.util.HashMap
manualMappings
Manual mappings.private java.util.ArrayList
multiplexEntries
The multiplex entries.private java.util.HashMap
multiplexMappings
Multiplex mappings.private java.util.HashMap
objectMappings
Maps classes to GenericObjectFactory instances.private java.util.ArrayList
orderedNames
The ordered names.private java.util.ArrayList
propertyDefinition
The property definition.private java.lang.String
registerName
The register name.private java.lang.Class
target
The target class.
-
Constructor Summary
Constructors Constructor Description ObjectFactoryLoader(java.net.URL resourceName)
Creates a new object factory loader for the given base file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
endMultiplexMapping()
Finializes the multiplexer mapping.protected void
endObjectDefinition()
Finializes the object definition.GenericObjectFactory
getFactoryForClass(java.lang.Class c)
Returns a factory instance for the given class.ManualMappingDefinition
getManualMappingDefinition(java.lang.Class c)
Returns the manual mapping definition for the given class, or null, if not manual definition exists.MultiplexMappingDefinition
getMultiplexDefinition(java.lang.Class c)
Returns the multiplex definition for the given class, or null, if no such definition exists.protected void
handleAttributeDefinition(java.lang.String name, java.lang.String attribName, java.lang.String handlerClass)
Handles an attribute definition.protected void
handleConstructorDefinition(java.lang.String propertyName, java.lang.String parameterClass)
Handles a constructor definition.protected void
handleElementDefinition(java.lang.String name, java.lang.String element)
Handles an element definition.protected void
handleLookupDefinition(java.lang.String name, java.lang.String lookupKey)
Handles an lookup definition.protected boolean
handleManualMapping(java.lang.String className, java.lang.String readHandler, java.lang.String writeHandler)
Handles a manual mapping definition.protected void
handleMultiplexMapping(java.lang.String typeName, java.lang.String className)
Defines an entry for the multiplex mapping.boolean
isGenericHandler(java.lang.Class c)
Checks, whether the factory has a description for the given class.private AttributeHandler
loadAttributeHandler(java.lang.String attribute)
Loads an instantiates the attribute handler specified by the given class name.private void
performSuperClassUpdate(GenericObjectFactory gef)
private void
rebuildSuperClasses()
protected void
startMultiplexMapping(java.lang.String className, java.lang.String typeAttr)
Starts a multiplex mapping.protected boolean
startObjectDefinition(java.lang.String className, java.lang.String register, boolean ignore)
Starts a object definition.-
Methods inherited from class org.jfree.xml.util.AbstractModelReader
endIncludeHandling, endRootDocument, getCloseComment, getCommentHandler, getOpenComment, handleIgnoredProperty, loadClass, parseXml, parseXmlDocument, setCloseComment, setOpenComment, startIncludeHandling, startRootDocument
-
-
-
-
Field Detail
-
objectMappings
private java.util.HashMap objectMappings
Maps classes to GenericObjectFactory instances.
-
manualMappings
private java.util.HashMap manualMappings
Manual mappings.
-
multiplexMappings
private java.util.HashMap multiplexMappings
Multiplex mappings.
-
target
private java.lang.Class target
The target class.
-
registerName
private java.lang.String registerName
The register name.
-
propertyDefinition
private java.util.ArrayList propertyDefinition
The property definition.
-
attributeDefinition
private java.util.ArrayList attributeDefinition
The attribute definition.
-
constructorDefinition
private java.util.ArrayList constructorDefinition
The constructor definition.
-
lookupDefinitions
private java.util.ArrayList lookupDefinitions
The lookup definitions.
-
orderedNames
private java.util.ArrayList orderedNames
The ordered names.
-
baseClass
private java.lang.String baseClass
The base class.
-
attributeName
private java.lang.String attributeName
The attribute name.
-
multiplexEntries
private java.util.ArrayList multiplexEntries
The multiplex entries.
-
-
Constructor Detail
-
ObjectFactoryLoader
public ObjectFactoryLoader(java.net.URL resourceName) throws ObjectDescriptionException
Creates a new object factory loader for the given base file.- Parameters:
resourceName
- the URL of the initial specification file.- Throws:
ObjectDescriptionException
- if the file could not be parsed.
-
-
Method Detail
-
rebuildSuperClasses
private void rebuildSuperClasses() throws ObjectDescriptionException
- Throws:
ObjectDescriptionException
-
performSuperClassUpdate
private void performSuperClassUpdate(GenericObjectFactory gef)
-
startObjectDefinition
protected boolean startObjectDefinition(java.lang.String className, java.lang.String register, boolean ignore) throws ObjectDescriptionException
Starts a object definition. The object definition collects all properties of an bean-class and defines, which constructor should be used when creating the class.- Specified by:
startObjectDefinition
in classAbstractModelReader
- Parameters:
className
- the class name of the defined objectregister
- the (optional) register name, to lookup and reference the object later.ignore
- ignore?- Returns:
- true, if the definition was accepted, false otherwise.
- Throws:
ObjectDescriptionException
- if an unexpected error occured.
-
handleAttributeDefinition
protected void handleAttributeDefinition(java.lang.String name, java.lang.String attribName, java.lang.String handlerClass) throws ObjectDescriptionException
Handles an attribute definition. This method gets called after the object definition was started. The method will be called for every defined attribute property.- Specified by:
handleAttributeDefinition
in classAbstractModelReader
- Parameters:
name
- the name of the propertyattribName
- the xml-attribute name to use later.handlerClass
- the attribute handler class.- Throws:
ObjectDescriptionException
- if an error occured.
-
handleElementDefinition
protected void handleElementDefinition(java.lang.String name, java.lang.String element) throws ObjectDescriptionException
Handles an element definition. This method gets called after the object definition was started. The method will be called for every defined element property. Element properties are used to describe complex objects.- Specified by:
handleElementDefinition
in classAbstractModelReader
- Parameters:
name
- the name of the propertyelement
- the xml-tag name for the child element.- Throws:
ObjectDescriptionException
- if an error occurs.
-
handleLookupDefinition
protected void handleLookupDefinition(java.lang.String name, java.lang.String lookupKey) throws ObjectDescriptionException
Handles an lookup definition. This method gets called after the object definition was started. The method will be called for every defined lookup property. Lookup properties reference previously created object using the object's registry name.- Specified by:
handleLookupDefinition
in classAbstractModelReader
- Parameters:
name
- the property name of the base objectlookupKey
- the register key of the referenced object- Throws:
ObjectDescriptionException
- if an error occured.
-
endObjectDefinition
protected void endObjectDefinition() throws ObjectDescriptionException
Finializes the object definition.- Specified by:
endObjectDefinition
in classAbstractModelReader
- Throws:
ObjectDescriptionException
- if an error occures.
-
handleConstructorDefinition
protected void handleConstructorDefinition(java.lang.String propertyName, java.lang.String parameterClass)
Handles a constructor definition. Only one constructor can be defined for a certain object type. The constructor will be filled using the given properties.- Specified by:
handleConstructorDefinition
in classAbstractModelReader
- Parameters:
propertyName
- the property name of the referenced local propertyparameterClass
- the parameter class for the parameter.
-
handleManualMapping
protected boolean handleManualMapping(java.lang.String className, java.lang.String readHandler, java.lang.String writeHandler) throws ObjectDescriptionException
Handles a manual mapping definition. The manual mapping maps specific read and write handlers to a given base class. Manual mappings always override any other definition.- Specified by:
handleManualMapping
in classAbstractModelReader
- Parameters:
className
- the base class namereadHandler
- the class name of the read handlerwriteHandler
- the class name of the write handler- Returns:
- true, if the mapping was accepted, false otherwise.
- Throws:
ObjectDescriptionException
- if an unexpected error occured.
-
startMultiplexMapping
protected void startMultiplexMapping(java.lang.String className, java.lang.String typeAttr)
Starts a multiplex mapping. Multiplex mappings are used to define polymorphic argument handlers. The mapper will collect all derived classes of the given base class and will select the corresponding mapping based on the given type attribute.- Specified by:
startMultiplexMapping
in classAbstractModelReader
- Parameters:
className
- the base class nametypeAttr
- the xml-attribute name containing the mapping key
-
handleMultiplexMapping
protected void handleMultiplexMapping(java.lang.String typeName, java.lang.String className) throws ObjectDescriptionException
Defines an entry for the multiplex mapping. The new entry will be activated when the base mappers type attribute contains thistypename
and will resolve to the handler for the given classname.- Specified by:
handleMultiplexMapping
in classAbstractModelReader
- Parameters:
typeName
- the type value for this mapping.className
- the class name to which this mapping resolves.- Throws:
ObjectDescriptionException
- if an error occurs.
-
endMultiplexMapping
protected void endMultiplexMapping() throws ObjectDescriptionException
Finializes the multiplexer mapping.- Specified by:
endMultiplexMapping
in classAbstractModelReader
- Throws:
ObjectDescriptionException
- if an error occurs.
-
loadAttributeHandler
private AttributeHandler loadAttributeHandler(java.lang.String attribute) throws ObjectDescriptionException
Loads an instantiates the attribute handler specified by the given class name.- Parameters:
attribute
- the attribute handlers classname.- Returns:
- the created attribute handler instance
- Throws:
ObjectDescriptionException
- if the handler could not be loaded.
-
isGenericHandler
public boolean isGenericHandler(java.lang.Class c)
Checks, whether the factory has a description for the given class.- Specified by:
isGenericHandler
in interfaceObjectFactory
- Parameters:
c
- the class to be handled by the factory.- Returns:
- true, if an description exists for the given class, false otherwise.
-
getFactoryForClass
public GenericObjectFactory getFactoryForClass(java.lang.Class c)
Returns a factory instance for the given class. The factory is independent from all previously generated instances.- Specified by:
getFactoryForClass
in interfaceObjectFactory
- Parameters:
c
- the class- Returns:
- the object factory.
-
getManualMappingDefinition
public ManualMappingDefinition getManualMappingDefinition(java.lang.Class c)
Returns the manual mapping definition for the given class, or null, if not manual definition exists.- Specified by:
getManualMappingDefinition
in interfaceObjectFactory
- Parameters:
c
- the class for which to check the existence of the definition- Returns:
- the manual mapping definition or null.
-
getMultiplexDefinition
public MultiplexMappingDefinition getMultiplexDefinition(java.lang.Class c)
Returns the multiplex definition for the given class, or null, if no such definition exists.- Specified by:
getMultiplexDefinition
in interfaceObjectFactory
- Parameters:
c
- the class for which to check the existence of the multiplexer- Returns:
- the multiplexer for the class, or null if no multiplexer exists.
-
-