| java.lang.Object org.apache.commons.betwixt.XMLIntrospector
XMLIntrospector | public class XMLIntrospector (Code) | | XMLIntrospector an introspector of beans to create a
XMLBeanInfo instance.
By default, XMLBeanInfo caching is switched on.
This means that the first time that a request is made for a XMLBeanInfo
for a particular class, the XMLBeanInfo is cached.
Later requests for the same class will return the cached value.
Note :
This class makes use of the java.bean.Introspector
class, which contains a BeanInfoSearchPath. To make sure betwixt can
do his work correctly, this searchpath is completely ignored during
processing. The original values will be restored after processing finished
author: James Strachan author: Martin van den Bemt |
Field Summary | |
protected Log | log |
Method Summary | |
protected void | addProperties(BeanInfo beanInfo, List elements, List attributes, List contents) | protected void | addProperties(BeanProperty[] beanProperties, List elements, List attributes, List contents) | protected void | addProperties(BeanInfo beanInfo, List elements, List attributes) | protected void | addProperty(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) Process a property. | protected void | addProperty(PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) Process a property. | protected void | addProperty(BeanProperty beanProperty, List elements, List attributes, List contents) Process a property. | protected void | addProperty(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor, List elements, List attributes) Process a property. | public void | assignAdder(Method twinParameterAdderMethod, ElementDescriptor matchingDescriptor) Assigns the given method as an adder method to the given descriptor. | public Descriptor | createDescriptor(PropertyDescriptor propertyDescriptor, boolean useAttributesForPrimitives) Create a XML descriptor from a bean one. | protected NameMapper | createNameMapper() A Factory method to lazily create a strategy
used to convert bean type names into element names. | protected PluralStemmer | createPluralStemmer() A Factory method to lazily create a new strategy
to detect matching singular and plural properties. | protected XMLBeanInfo | createXMLBeanInfo(DynaClass dynaClass) Creates XMLBeanInfo for the given DynaClass. | protected XMLBeanInfo | createXMLBeanInfo(BeanInfo beanInfo) | public Descriptor | createXMLDescriptor(BeanProperty beanProperty) Create a XML descriptor from a bean one. | public void | defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass) Add any addPropety(PropertyType) methods as Updaters
which are often used for 1-N relationships in beans.
This method does not preserve null property names.
The tricky part here is finding which ElementDescriptor corresponds
to the method. | public void | defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass, boolean preservePropertyName) Add any addPropety(PropertyType) methods as Updaters
which are often used for 1-N relationships in beans.
The tricky part here is finding which ElementDescriptor corresponds
to the method. | protected synchronized XMLBeanInfo | findByXMLDescriptor(Class aClass) | public void | flushCache() Flush existing cached XMLBeanInfo 's. | public NameMapper | getAttributeNameMapper() Gets the name mapping strategy used to convert bean names into attributes.
the strategy used to convert bean type names into attributenames. | public ClassNormalizer | getClassNormalizer() Gets the ClassNormalizer strategy.
This is used to determine the Class to be introspected
(the normalized Class). | public IntrospectionConfiguration | getConfiguration() Gets the configuration to be used for introspection. | public NameMapper | getElementNameMapper() Gets the name mapping strategy used to convert bean names into elements.
the strategy used to convert bean type names into element names. | public Log | getLog() Gets the current logging implementation. | public NameMapper | getNameMapper() Gets the name mapper strategy. | public PluralStemmer | getPluralStemmer() Get singular and plural matching strategy. | public PolymorphicReferenceResolver | getPolymorphicReferenceResolver() Gets the resolver for polymorphic references.
Though this is used only at bind time,
it is typically tightly couple to the xml registry. | public XMLBeanInfoRegistry | getRegistry() Gets the current registry implementation.
The registry is checked to see if it has an XMLBeanInfo for a class
before introspecting. | public XMLBeanInfo | introspect(Object bean) Create a standard XMLBeanInfo by introspection
The actual introspection depends only on the BeanInfo
associated with the bean. | public XMLBeanInfo | introspect(DynaClass dynaClass) Creates XMLBeanInfo by reading the DynaProperties of a DynaBean. | public synchronized XMLBeanInfo | introspect(Class aClass, InputSource source) Introspects the given Class using the dot betwixt
document in the given InputSource .
Note: that the given mapping will not
be registered by this method. | public XMLBeanInfo | introspect(Class aClass) Create a standard XMLBeanInfo by introspection.
The actual introspection depends only on the BeanInfo
associated with the bean. | public XMLBeanInfo | introspect(BeanInfo beanInfo) Create a standard XMLBeanInfo by introspection. | public boolean | isAttributesForPrimitives() Should attributes (or elements) be used for primitive types. | public boolean | isCachingEnabled() | public boolean | isLoopType(Class type) | public boolean | isPrimitiveType(Class type) | public boolean | isWrapCollectionsInElement() | public synchronized Class[] | register(InputSource source) Registers the class mappings specified in the multi-class document
given by the InputSource . | public void | register(Class aClass, InputSource source) Registers the class mapping specified in the standard dot-betwixt file. | public void | setAttributeNameMapper(NameMapper nameMapper) | public void | setAttributesForPrimitives(boolean attributesForPrimitives) Set whether attributes (or elements) should be used for primitive types. | public void | setCachingEnabled(boolean cachingEnabled) Set whether XMLBeanInfo caching should be enabled. | public void | setClassNormalizer(ClassNormalizer classNormalizer) Sets the ClassNormalizer strategy.
This is used to determine the Class to be introspected
(the normalized Class). | public void | setConfiguration(IntrospectionConfiguration configuration) Sets the configuration to be used for introspection. | public void | setElementNameMapper(NameMapper nameMapper) | public void | setLog(Log log) | public void | setNameMapper(NameMapper nameMapper) | public void | setPluralStemmer(PluralStemmer pluralStemmer) | public void | setPolymorphicReferenceResolver(PolymorphicReferenceResolver polymorphicReferenceResolver) Sets the resolver for polymorphic references.
Though this is used only at bind time,
it is typically tightly couple to the xml registry. | public void | setRegistry(XMLBeanInfoRegistry registry) Sets the XMLBeanInfoRegistry implementation.
The registry is checked to see if it has an XMLBeanInfo for a class
before introspecting. | public void | setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath) | public void | setWrapCollectionsInElement(boolean wrapCollectionsInElement) Sets whether we should we wrap collections in an extra element. | public boolean | useBeanInfoSearchPath() Should the original java.reflect.Introspector bean info search path be used?
By default it will be false. |
XMLIntrospector | public XMLIntrospector()(Code) | | Base constructor
|
XMLIntrospector | public XMLIntrospector(IntrospectionConfiguration configuration)(Code) | | Construct allows a custom configuration to be set on construction.
This allows IntrospectionConfiguration subclasses
to be easily used.
Parameters: configuration - IntrospectionConfiguration, not null |
addProperties | protected void addProperties(BeanProperty[] beanProperties, List elements, List attributes, List contents)(Code) | | Loop through properties and process each one
Parameters: beanProperties - the properties to be processed Parameters: elements - ElementDescriptor list to which elements will be added Parameters: attributes - AttributeDescriptor list to which attributes will be added Parameters: contents - Descriptor list to which mixed content will be added since: 0.5 |
addProperty | protected void addProperty(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) throws IntrospectionException(Code) | | Process a property.
Go through and work out whether it's a loop property, a primitive or a standard.
The class property is ignored.
Parameters: beanInfo - the BeanInfo whose property is being processed Parameters: propertyDescriptor - the PropertyDescriptor to process Parameters: elements - ElementDescriptor list to which elements will be added Parameters: attributes - AttributeDescriptor list to which attributes will be added Parameters: contents - Descriptor list to which mixed content will be added throws: IntrospectionException - if the bean introspection failsXMLIntrospector.addProperty(PropertyDescriptor,List,List,List) |
addProperty | protected void addProperty(PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) throws IntrospectionException(Code) | | Process a property.
Go through and work out whether it's a loop property, a primitive or a standard.
The class property is ignored.
Parameters: propertyDescriptor - the PropertyDescriptor to process Parameters: elements - ElementDescriptor list to which elements will be added Parameters: attributes - AttributeDescriptor list to which attributes will be added Parameters: contents - Descriptor list to which mixed content will be added throws: IntrospectionException - if the bean introspection failsXMLIntrospector.addProperty(BeanProperty,List,List,List) |
addProperty | protected void addProperty(BeanProperty beanProperty, List elements, List attributes, List contents)(Code) | | Process a property.
Go through and work out whether it's a loop property, a primitive or a standard.
The class property is ignored.
Parameters: beanProperty - the bean property to process Parameters: elements - ElementDescriptor list to which elements will be added Parameters: attributes - AttributeDescriptor list to which attributes will be added Parameters: contents - Descriptor list to which mixed content will be added since: 0.5 |
assignAdder | public void assignAdder(Method twinParameterAdderMethod, ElementDescriptor matchingDescriptor)(Code) | | Assigns the given method as an adder method to the given descriptor.
Parameters: twinParameterAdderMethod - adder Method , not null Parameters: matchingDescriptor - ElementDescriptor describing the element since: 0.8 |
createDescriptor | public Descriptor createDescriptor(PropertyDescriptor propertyDescriptor, boolean useAttributesForPrimitives) throws IntrospectionException(Code) | | Create a XML descriptor from a bean one.
Go through and work out whether it's a loop property, a primitive or a standard.
The class property is ignored.
Parameters: propertyDescriptor - create a NodeDescriptor for this property Parameters: useAttributesForPrimitives - write primitives as attributes (rather than elements) a correctly configured NodeDescriptor for the property throws: IntrospectionException - when bean introspection failsXMLIntrospector.createXMLDescriptor |
createNameMapper | protected NameMapper createNameMapper()(Code) | | A Factory method to lazily create a strategy
used to convert bean type names into element names.
new default NameMapper implementation |
createPluralStemmer | protected PluralStemmer createPluralStemmer()(Code) | | A Factory method to lazily create a new strategy
to detect matching singular and plural properties.
new defualt PluralStemmer implementation |
createXMLBeanInfo | protected XMLBeanInfo createXMLBeanInfo(DynaClass dynaClass)(Code) | | Creates XMLBeanInfo for the given DynaClass.
Parameters: dynaClass - the class describing a DynaBean XMLBeanInfo that describes the properties of the given DynaClass |
createXMLBeanInfo | protected XMLBeanInfo createXMLBeanInfo(BeanInfo beanInfo)(Code) | | Factory method to create XMLBeanInfo instances
Parameters: beanInfo - the BeanInfo from which the XMLBeanInfo will be created XMLBeanInfo describing the bean-xml mapping |
createXMLDescriptor | public Descriptor createXMLDescriptor(BeanProperty beanProperty)(Code) | | Create a XML descriptor from a bean one.
Go through and work out whether it's a loop property, a primitive or a standard.
The class property is ignored.
Parameters: beanProperty - the BeanProperty specifying the property a correctly configured NodeDescriptor for the property since: 0.5 |
defaultAddMethods | public void defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass)(Code) | | Add any addPropety(PropertyType) methods as Updaters
which are often used for 1-N relationships in beans.
This method does not preserve null property names.
The tricky part here is finding which ElementDescriptor corresponds
to the method. e.g. a property 'items' might have an Element descriptor
which the method addItem() should match to.
So the algorithm we'll use
by default is to take the decapitalized name of the property being added
and find the first ElementDescriptor that matches the property starting with
the string. This should work for most use cases.
e.g. addChild() would match the children property.
TODO this probably needs refactoring. It probably belongs in the bean wrapper
(so that it'll work properly with dyna-beans) and so that the operations can
be optimized by caching. Multiple hash maps are created and getMethods is
called multiple times. This is relatively expensive and so it'd be better
to push into a proper class and cache.
Parameters: rootDescriptor - add defaults to this descriptor Parameters: beanClass - the Class to which descriptor corresponds |
defaultAddMethods | public void defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass, boolean preservePropertyName)(Code) | | Add any addPropety(PropertyType) methods as Updaters
which are often used for 1-N relationships in beans.
The tricky part here is finding which ElementDescriptor corresponds
to the method. e.g. a property 'items' might have an Element descriptor
which the method addItem() should match to.
So the algorithm we'll use
by default is to take the decapitalized name of the property being added
and find the first ElementDescriptor that matches the property starting with
the string. This should work for most use cases.
e.g. addChild() would match the children property.
TODO this probably needs refactoring. It probably belongs in the bean wrapper
(so that it'll work properly with dyna-beans) and so that the operations can
be optimized by caching. Multiple hash maps are created and getMethods is
called multiple times. This is relatively expensive and so it'd be better
to push into a proper class and cache.
Parameters: rootDescriptor - add defaults to this descriptor Parameters: beanClass - the Class to which descriptor corresponds since: 0.8 |
findByXMLDescriptor | protected synchronized XMLBeanInfo findByXMLDescriptor(Class aClass)(Code) | | Attempt to lookup the XML descriptor for the given class using the
classname + ".betwixt" using the same ClassLoader used to load the class
or return null if it could not be loaded
Parameters: aClass - digester .betwixt file for this class XMLBeanInfo digested from the .betwixt file if one can be found.Otherwise null. |
flushCache | public void flushCache()(Code) | | Flush existing cached XMLBeanInfo 's.
|
getAttributeNameMapper | public NameMapper getAttributeNameMapper()(Code) | | Gets the name mapping strategy used to convert bean names into attributes.
the strategy used to convert bean type names into attributenames. If no attributeNamemapper is known, it will default to the ElementNameMapper |
getClassNormalizer | public ClassNormalizer getClassNormalizer()(Code) | | Gets the ClassNormalizer strategy.
This is used to determine the Class to be introspected
(the normalized Class).
the ClassNormalizer used to determine the Class to be introspectedfor a given Object. since: 0.5 |
getConfiguration | public IntrospectionConfiguration getConfiguration()(Code) | | Gets the configuration to be used for introspection.
The various introspection-time strategies
and configuration variables have been consolidated as properties
of this bean.
This allows the configuration to be more easily shared.
IntrospectionConfiguration, not null |
getElementNameMapper | public NameMapper getElementNameMapper()(Code) | | Gets the name mapping strategy used to convert bean names into elements.
the strategy used to convert bean type names into element names. If no element mapper is currently defined then a default one is created. |
getLog | public Log getLog()(Code) | | Gets the current logging implementation.
the Log implementation which this class logs to |
getPluralStemmer | public PluralStemmer getPluralStemmer()(Code) | | Get singular and plural matching strategy.
the strategy used to detect matching singular and plural properties |
getRegistry | public XMLBeanInfoRegistry getRegistry()(Code) | | Gets the current registry implementation.
The registry is checked to see if it has an XMLBeanInfo for a class
before introspecting.
After standard introspection is complete, the instance will be passed to the registry.
This allows finely grained control over the caching strategy.
It also allows the standard introspection mechanism
to be overridden on a per class basis.
the XMLBeanInfoRegistry currently used |
introspect | public XMLBeanInfo introspect(Object bean) throws IntrospectionException(Code) | | Create a standard XMLBeanInfo by introspection
The actual introspection depends only on the BeanInfo
associated with the bean.
Parameters: bean - introspect this bean XMLBeanInfo describing bean-xml mapping throws: IntrospectionException - when the bean introspection fails |
introspect | public XMLBeanInfo introspect(DynaClass dynaClass)(Code) | | Creates XMLBeanInfo by reading the DynaProperties of a DynaBean.
Customizing DynaBeans using betwixt is not supported.
Parameters: dynaClass - the DynaBean to introspect XMLBeanInfo for the DynaClass |
introspect | public XMLBeanInfo introspect(Class aClass) throws IntrospectionException(Code) | | Create a standard XMLBeanInfo by introspection.
The actual introspection depends only on the BeanInfo
associated with the bean.
Parameters: aClass - introspect this class XMLBeanInfo describing bean-xml mapping throws: IntrospectionException - when the bean introspection fails |
introspect | public XMLBeanInfo introspect(BeanInfo beanInfo) throws IntrospectionException(Code) | | Create a standard XMLBeanInfo by introspection.
The actual introspection depends only on the BeanInfo
associated with the bean.
Parameters: beanInfo - the BeanInfo the xml-bean mapping is based on XMLBeanInfo describing bean-xml mapping throws: IntrospectionException - when the bean introspection fails |
isAttributesForPrimitives | public boolean isAttributesForPrimitives()(Code) | | Should attributes (or elements) be used for primitive types.
true if primitive types will be mapped to attributes in the introspection |
isCachingEnabled | public boolean isCachingEnabled()(Code) | | Is XMLBeanInfo caching enabled?
true if caching is enabled |
isLoopType | public boolean isLoopType(Class type)(Code) | | Is this class a loop?
Parameters: type - the Class to test true if the type is a loop type |
isPrimitiveType | public boolean isPrimitiveType(Class type)(Code) | | Is this class a primitive?
Parameters: type - the Class to test true for primitive types |
isWrapCollectionsInElement | public boolean isWrapCollectionsInElement()(Code) | | Should collections be wrapped in an extra element?
whether we should we wrap collections in an extra element? |
register | public void register(Class aClass, InputSource source) throws IOException, SAXException(Code) | | Registers the class mapping specified in the standard dot-betwixt file.
Subsequent introspections will use this registered mapping for the class.
Note: that this method will override any existing mapping
for this class.
since: 0.7 Parameters: aClass - Class , not null Parameters: source - InputSource , not null throws: SAXException - when the source cannot be parsed throws: IOException - |
setAttributeNameMapper | public void setAttributeNameMapper(NameMapper nameMapper)(Code) | | Sets the strategy used to convert bean type names into attribute names
Parameters: nameMapper - the NameMapper to use for the convertion |
setAttributesForPrimitives | public void setAttributesForPrimitives(boolean attributesForPrimitives)(Code) | | Set whether attributes (or elements) should be used for primitive types.
Parameters: attributesForPrimitives - pass trus to map primitives to attributes,pass false to map primitives to elements |
setCachingEnabled | public void setCachingEnabled(boolean cachingEnabled)(Code) | | Set whether XMLBeanInfo caching should be enabled.
Parameters: cachingEnabled - ignored |
setClassNormalizer | public void setClassNormalizer(ClassNormalizer classNormalizer)(Code) | | Sets the ClassNormalizer strategy.
This is used to determine the Class to be introspected
(the normalized Class).
Parameters: classNormalizer - the ClassNormalizer to be used to determine the Class to be introspected for a given Object. since: 0.5 |
setConfiguration | public void setConfiguration(IntrospectionConfiguration configuration)(Code) | | Sets the configuration to be used for introspection.
The various introspection-time strategies
and configuration variables have been consolidated as properties
of this bean.
This allows the configuration to be more easily shared.
Parameters: configuration - IntrospectionConfiguration, not null |
setElementNameMapper | public void setElementNameMapper(NameMapper nameMapper)(Code) | | Sets the strategy used to convert bean type names into element names
Parameters: nameMapper - the NameMapper to use for the conversion |
setLog | public void setLog(Log log)(Code) | | Sets the current logging implementation.
Parameters: log - the Log implementation to use for logging |
setPluralStemmer | public void setPluralStemmer(PluralStemmer pluralStemmer)(Code) | | Sets the strategy used to detect matching singular and plural properties
Parameters: pluralStemmer - the PluralStemmer used to match singular and plural |
setRegistry | public void setRegistry(XMLBeanInfoRegistry registry)(Code) | | Sets the XMLBeanInfoRegistry implementation.
The registry is checked to see if it has an XMLBeanInfo for a class
before introspecting.
After standard introspection is complete, the instance will be passed to the registry.
This allows finely grained control over the caching strategy.
It also allows the standard introspection mechanism
to be overridden on a per class basis.
Note when using polymophic mapping with a custom
registry, a call to
XMLIntrospector.setPolymorphicReferenceResolver(PolymorphicReferenceResolver) may be necessary.
Parameters: registry - the XMLBeanInfoRegistry to use |
setUseBeanInfoSearchPath | public void setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath)(Code) | | Specifies if you want to use the beanInfoSearchPath
See Also: java.beans.Introspector See Also: for more details Parameters: useBeanInfoSearchPath - |
setWrapCollectionsInElement | public void setWrapCollectionsInElement(boolean wrapCollectionsInElement)(Code) | | Sets whether we should we wrap collections in an extra element.
Parameters: wrapCollectionsInElement - pass true if collections should be wrapped in aparent element |
useBeanInfoSearchPath | public boolean useBeanInfoSearchPath()(Code) | | Should the original java.reflect.Introspector bean info search path be used?
By default it will be false.
boolean if the beanInfoSearchPath should be used. |
|
|