Package jadex.xml.bean
Class BeanObjectReaderHandler
- java.lang.Object
-
- jadex.xml.bean.BeanObjectReaderHandler
-
- All Implemented Interfaces:
IBulkObjectLinker
,IObjectLinker
,IObjectReaderHandler
public class BeanObjectReaderHandler extends java.lang.Object implements IObjectReaderHandler
Handler for reading XML into Java beans.
-
-
Field Summary
Fields Modifier and Type Field Description protected jadex.commons.transformation.traverser.IBeanIntrospector
introspector
The bean introspector.protected java.util.Set<java.lang.Object>
no_typeinfos
No type infos.protected java.util.Map<IFilter<java.lang.Object>,IPostProcessor>
postprocessors
The filter based post processors.protected TypeInfoTypeManager
titmanager
The type info manager.
-
Constructor Summary
Constructors Constructor Description BeanObjectReaderHandler()
Create a new handler for custom XML formats.BeanObjectReaderHandler(java.util.Set<TypeInfo> typeinfos)
Create a new handler for Java XML supporting on-the-fly type info creation for arrays.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPostProcessor(IFilter<java.lang.Object> filter, IPostProcessor processor)
Add a post processor.void
bulkLinkObjects(java.lang.Object parent, java.util.List<LinkData> children, AReadContext context)
Bulk link chilren to its parent.void
bulkLinkObjects(java.util.List<java.lang.Object> childs, java.lang.Object parent, java.lang.Object linkinfo, QName[] pathname, AReadContext context)
Link an object to its parent.protected java.lang.Object
convertBulkValues(java.util.List<java.lang.Object> vals, java.lang.Class<?> targetclass, java.lang.Object converter, AReadContext context, java.lang.String id)
Convert a list of values into the target format (list, set, collection, array).java.lang.Object
convertContentObject(java.lang.String value, QName tag, AReadContext context)
Convert an object to another type of object.protected java.lang.Object
convertValue(java.lang.Object val, java.lang.Class<?> targetclass, java.lang.Object converter, AReadContext context, java.lang.String id)
Convert a value by using a converter.java.lang.Object
createObject(java.lang.Object type, boolean root, AReadContext context, java.util.Map<java.lang.String,java.lang.String> rawattributes)
Create an object for the current tag.protected java.lang.Class<?>
getCorrectAnonymousInnerClass(java.lang.Class<?> clazz, java.util.Map<java.lang.String,java.lang.String> rawattributes, java.lang.ClassLoader classloader)
Bug with Java compilers that enumerate anonymous inner classes as they like.java.lang.Object
getObjectType(java.lang.Object object, AReadContext context)
Get the object typeIPostProcessor[]
getPostProcessors(java.lang.Object object, java.lang.Object typeinfo)
Get the post-processor.TypeInfo
getTypeInfo(java.lang.Object object, QName[] fullpath, AReadContext context)
Get the most specific mapping info.void
handleAttributeValue(java.lang.Object object, QName xmlattrname, java.util.List<QName> attrpath, java.lang.String attrval, java.lang.Object attrinfo, AReadContext context)
Handle the attribute of an object.protected void
handleBulkLinking(java.util.List<java.lang.Object> childs, java.lang.Object parent, AReadContext context, QName[] pathname, java.util.List<LinkData> linkdatas, int startidx)
Initiate the bulk link calls.protected boolean
invokeBulkSetMethod(java.lang.String[] prefixes, java.lang.String postfix, java.util.List<java.lang.Object> vals, java.lang.Object object, AReadContext context, java.lang.Object converter, java.lang.String idref)
Set a value directly on a Java bean.protected boolean
invokeSetMethod(java.lang.String[] prefixes, java.lang.String postfix, java.lang.Object value, java.lang.Object object, AReadContext context, java.lang.Object converter, java.lang.String idref)
Set a value directly on a Java bean.protected boolean
isCorrectAnonymousInnerClass(java.lang.Class<?> clazz, java.util.Map<java.lang.String,java.lang.String> rawattributes)
Test if a class is the correct inner class.void
linkObject(java.lang.Object object, java.lang.Object parent, java.lang.Object linkinfo, QName[] pathname, AReadContext context)
Link an object to its parent.void
removePostProcessor(IFilter<java.lang.Object> filter)
Remove a post processor.protected boolean
setBulkAttributeValues(java.lang.Object accessinfo, QName xmlattrname, java.lang.Object object, java.util.List<java.lang.Object> vals, java.lang.Object converter, java.lang.String id, AReadContext context)
Set an attribute value.protected boolean
setBulkField(java.lang.String fieldname, java.lang.Object parent, java.util.List<java.lang.Object> objects, java.lang.Object converter, AReadContext context, java.lang.String idref)
Directly access a field for setting the objects.protected boolean
setElementValue(java.lang.Object accessinfo, QName xmlname, java.lang.Object object, java.lang.Object val, java.lang.Object converter, java.lang.String id, AReadContext context)
Set an attribute value.protected boolean
setField(java.lang.String fieldname, java.lang.Object parent, java.lang.Object object, java.lang.Object converter, AReadContext context, java.lang.String idref)
Directly access a field for setting/(adding) the object.
-
-
-
Field Detail
-
titmanager
protected TypeInfoTypeManager titmanager
The type info manager.
-
no_typeinfos
protected java.util.Set<java.lang.Object> no_typeinfos
No type infos.
-
introspector
protected jadex.commons.transformation.traverser.IBeanIntrospector introspector
The bean introspector.
-
postprocessors
protected java.util.Map<IFilter<java.lang.Object>,IPostProcessor> postprocessors
The filter based post processors.
-
-
Constructor Detail
-
BeanObjectReaderHandler
public BeanObjectReaderHandler()
Create a new handler for custom XML formats.
-
BeanObjectReaderHandler
public BeanObjectReaderHandler(java.util.Set<TypeInfo> typeinfos)
Create a new handler for Java XML supporting on-the-fly type info creation for arrays.
-
-
Method Detail
-
getTypeInfo
public TypeInfo getTypeInfo(java.lang.Object object, QName[] fullpath, AReadContext context)
Get the most specific mapping info.- Specified by:
getTypeInfo
in interfaceIObjectReaderHandler
- Parameters:
tag
- The tag.fullpath
- The full path.- Returns:
- The most specific mapping info.
-
createObject
public java.lang.Object createObject(java.lang.Object type, boolean root, AReadContext context, java.util.Map<java.lang.String,java.lang.String> rawattributes) throws java.lang.Exception
Create an object for the current tag.- Specified by:
createObject
in interfaceIObjectReaderHandler
- Parameters:
type
- The object type to create.root
- Flag, if object should be root object.context
- The context.- Returns:
- The created object (or null for none).
- Throws:
java.lang.Exception
-
getCorrectAnonymousInnerClass
protected java.lang.Class<?> getCorrectAnonymousInnerClass(java.lang.Class<?> clazz, java.util.Map<java.lang.String,java.lang.String> rawattributes, java.lang.ClassLoader classloader)
Bug with Java compilers that enumerate anonymous inner classes as they like.
-
isCorrectAnonymousInnerClass
protected boolean isCorrectAnonymousInnerClass(java.lang.Class<?> clazz, java.util.Map<java.lang.String,java.lang.String> rawattributes)
Test if a class is the correct inner class.
-
getObjectType
public java.lang.Object getObjectType(java.lang.Object object, AReadContext context)
Get the object type- Parameters:
object
- The object.- Returns:
- The object type.
-
convertContentObject
public java.lang.Object convertContentObject(java.lang.String value, QName tag, AReadContext context) throws java.lang.Exception
Convert an object to another type of object.- Specified by:
convertContentObject
in interfaceIObjectReaderHandler
- Throws:
java.lang.Exception
-
handleAttributeValue
public void handleAttributeValue(java.lang.Object object, QName xmlattrname, java.util.List<QName> attrpath, java.lang.String attrval, java.lang.Object attrinfo, AReadContext context) throws java.lang.Exception
Handle the attribute of an object.- Specified by:
handleAttributeValue
in interfaceIObjectReaderHandler
- Parameters:
object
- The object.attrname
- The attribute name.attrval
- The attribute value.attrinfo
- The attribute info.context
- The context.- Throws:
java.lang.Exception
-
linkObject
public void linkObject(java.lang.Object object, java.lang.Object parent, java.lang.Object linkinfo, QName[] pathname, AReadContext context) throws java.lang.Exception
Link an object to its parent.- Specified by:
linkObject
in interfaceIObjectLinker
- Parameters:
object
- The object.parent
- The parent object.linkinfo
- The link info.tagname
- The current tagname (for name guessing).context
- The context.- Throws:
java.lang.Exception
-
bulkLinkObjects
public void bulkLinkObjects(java.util.List<java.lang.Object> childs, java.lang.Object parent, java.lang.Object linkinfo, QName[] pathname, AReadContext context) throws java.lang.Exception
Link an object to its parent.- Parameters:
object
- The object.parent
- The parent object.linkinfo
- The link info.tagname
- The current tagname (for name guessing).context
- The context.- Throws:
java.lang.Exception
-
bulkLinkObjects
public void bulkLinkObjects(java.lang.Object parent, java.util.List<LinkData> children, AReadContext context) throws java.lang.Exception
Bulk link chilren to its parent.- Specified by:
bulkLinkObjects
in interfaceIBulkObjectLinker
- Parameters:
parent
- The parent object.children
- The children objects (link datas).context
- The context.classloader
- The classloader.root
- The root object.- Throws:
java.lang.Exception
-
handleBulkLinking
protected void handleBulkLinking(java.util.List<java.lang.Object> childs, java.lang.Object parent, AReadContext context, QName[] pathname, java.util.List<LinkData> linkdatas, int startidx) throws java.lang.Exception
Initiate the bulk link calls.- Throws:
java.lang.Exception
-
setElementValue
protected boolean setElementValue(java.lang.Object accessinfo, QName xmlname, java.lang.Object object, java.lang.Object val, java.lang.Object converter, java.lang.String id, AReadContext context) throws java.lang.Exception
Set an attribute value. Similar to handleAttributValue but allows objects as attribute values (for linking).- Parameters:
attrinfo
- The attribute info.xmlattrname
- The xml attribute name.object
- The object.val
- The attribute value.root
- The root object.classloader
- The classloader.- Throws:
java.lang.Exception
-
setBulkAttributeValues
protected boolean setBulkAttributeValues(java.lang.Object accessinfo, QName xmlattrname, java.lang.Object object, java.util.List<java.lang.Object> vals, java.lang.Object converter, java.lang.String id, AReadContext context) throws java.lang.Exception
Set an attribute value. Similar to handleAttributValue but allows objects as attribute values (for linking).- Parameters:
attrinfo
- The attribute info.xmlattrname
- The xml attribute name.object
- The object.attrval
- The attribute value.root
- The root object.classloader
- The classloader.- Throws:
java.lang.Exception
-
invokeSetMethod
protected boolean invokeSetMethod(java.lang.String[] prefixes, java.lang.String postfix, java.lang.Object value, java.lang.Object object, AReadContext context, java.lang.Object converter, java.lang.String idref) throws java.lang.Exception
Set a value directly on a Java bean.- Parameters:
prefixes
- The method prefixes.postfix
- The method postfix.value
- The attribute value.object
- The object.root
- The root.classloader
- The classloader.converter
- The converter.- Throws:
java.lang.Exception
-
invokeBulkSetMethod
protected boolean invokeBulkSetMethod(java.lang.String[] prefixes, java.lang.String postfix, java.util.List<java.lang.Object> vals, java.lang.Object object, AReadContext context, java.lang.Object converter, java.lang.String idref) throws java.lang.Exception
Set a value directly on a Java bean.- Parameters:
prefixes
- The method prefixes.postfix
- The mothod postfix.attrval
- The attribute value.object
- The object.root
- The root.classloader
- The classloader.converter
- The converter.- Throws:
java.lang.Exception
-
setField
protected boolean setField(java.lang.String fieldname, java.lang.Object parent, java.lang.Object object, java.lang.Object converter, AReadContext context, java.lang.String idref) throws java.lang.Exception
Directly access a field for setting/(adding) the object.- Throws:
java.lang.Exception
-
setBulkField
protected boolean setBulkField(java.lang.String fieldname, java.lang.Object parent, java.util.List<java.lang.Object> objects, java.lang.Object converter, AReadContext context, java.lang.String idref) throws java.lang.Exception
Directly access a field for setting the objects.- Throws:
java.lang.Exception
-
convertValue
protected java.lang.Object convertValue(java.lang.Object val, java.lang.Class<?> targetclass, java.lang.Object converter, AReadContext context, java.lang.String id) throws java.lang.Exception
Convert a value by using a converter.- Parameters:
val
- The attribute value.targetcalss
- The target class.converter
- The converter.root
- The root.classloader
- The classloader.- Throws:
java.lang.Exception
-
convertBulkValues
protected java.lang.Object convertBulkValues(java.util.List<java.lang.Object> vals, java.lang.Class<?> targetclass, java.lang.Object converter, AReadContext context, java.lang.String id) throws java.lang.Exception
Convert a list of values into the target format (list, set, collection, array).- Throws:
java.lang.Exception
-
getPostProcessors
public IPostProcessor[] getPostProcessors(java.lang.Object object, java.lang.Object typeinfo)
Get the post-processor.- Specified by:
getPostProcessors
in interfaceIObjectReaderHandler
- Returns:
- The post-processor
-
addPostProcessor
public void addPostProcessor(IFilter<java.lang.Object> filter, IPostProcessor processor)
Add a post processor.- Parameters:
filter
- The filter.processor
- The post processor.
-
removePostProcessor
public void removePostProcessor(IFilter<java.lang.Object> filter)
Remove a post processor.- Parameters:
filter
- The filter.processor
- The post processor.
-
-