public class XMLIntrospector extends Object
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
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
log
Deprecated.
0.6 use the
getLog() property instead |
Constructor and Description |
---|
XMLIntrospector()
Base constructor
|
XMLIntrospector(IntrospectionConfiguration configuration)
Construct allows a custom configuration to be set on construction.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addProperties(BeanInfo beanInfo,
List elements,
List attributes)
Deprecated.
0.5 this method does not support mixed content.
Use
addProperties(BeanInfo, List, List, List) instead. |
protected void |
addProperties(BeanInfo beanInfo,
List elements,
List attributes,
List contents)
Deprecated.
|
protected void |
addProperties(BeanProperty[] beanProperties,
List elements,
List attributes,
List contents)
Loop through properties and process each one
|
protected void |
addProperty(BeanInfo beanInfo,
PropertyDescriptor propertyDescriptor,
List elements,
List attributes)
Deprecated.
0.5 this method does not support mixed content.
Use
addProperty(BeanInfo, PropertyDescriptor, List, List, List) instead. |
protected void |
addProperty(BeanInfo beanInfo,
PropertyDescriptor propertyDescriptor,
List elements,
List attributes,
List contents)
Deprecated.
0.5 BeanInfo is no longer required.
Use
addProperty(PropertyDescriptor, List, List, List) instead. |
protected void |
addProperty(BeanProperty beanProperty,
List elements,
List attributes,
List contents)
Process a property.
|
protected void |
addProperty(PropertyDescriptor propertyDescriptor,
List elements,
List attributes,
List contents)
Deprecated.
0.5 use
addProperty(BeanProperty, List, List, List) instead |
void |
assignAdder(Method twinParameterAdderMethod,
ElementDescriptor matchingDescriptor)
Assigns the given method as an adder method to the given descriptor.
|
Descriptor |
createDescriptor(PropertyDescriptor propertyDescriptor,
boolean useAttributesForPrimitives)
Deprecated.
|
protected NameMapper |
createNameMapper()
Deprecated.
0.6 this method has been moved into IntrospectionConfiguration.
Those who need to vary this should subclass that class instead
|
protected PluralStemmer |
createPluralStemmer()
Deprecated.
0.6 this method has been moved into IntrospectionConfiguration.
Those who need to vary this should subclass that class instead
|
protected XMLBeanInfo |
createXMLBeanInfo(BeanInfo beanInfo)
Factory method to create XMLBeanInfo instances
|
protected XMLBeanInfo |
createXMLBeanInfo(org.apache.commons.beanutils.DynaClass dynaClass)
Creates XMLBeanInfo for the given DynaClass.
|
Descriptor |
createXMLDescriptor(BeanProperty beanProperty)
Create a XML descriptor from a bean one.
|
void |
defaultAddMethods(ElementDescriptor rootDescriptor,
Class beanClass)
Add any addPropety(PropertyType) methods as Updaters
which are often used for 1-N relationships in beans.
|
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.
|
protected XMLBeanInfo |
findByXMLDescriptor(Class aClass)
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
|
void |
flushCache()
Deprecated.
0.5 use flushable registry instead
|
NameMapper |
getAttributeNameMapper()
Deprecated.
0.6 getConfiguration().getAttributeNameMapper
|
ClassNormalizer |
getClassNormalizer()
Deprecated.
0.6 use getConfiguration().getClassNormalizer
|
IntrospectionConfiguration |
getConfiguration()
Gets the configuration to be used for introspection.
|
NameMapper |
getElementNameMapper()
Deprecated.
0.6 use getConfiguration().getElementNameMapper
|
org.apache.commons.logging.Log |
getLog()
Gets the current logging implementation.
|
NameMapper |
getNameMapper()
Deprecated.
0.5 getNameMapper is split up in
getElementNameMapper() and getAttributeNameMapper() |
PluralStemmer |
getPluralStemmer()
Deprecated.
0.6 use getConfiguration().getPluralStemmer
|
PolymorphicReferenceResolver |
getPolymorphicReferenceResolver()
Gets the resolver for polymorphic references.
|
XMLBeanInfoRegistry |
getRegistry()
Gets the current registry implementation.
|
XMLBeanInfo |
introspect(BeanInfo beanInfo)
Create a standard
XMLBeanInfo by introspection. |
XMLBeanInfo |
introspect(Class aClass)
Create a standard
XMLBeanInfo by introspection. |
XMLBeanInfo |
introspect(Class aClass,
org.xml.sax.InputSource source)
Introspects the given
Class using the dot betwixt
document in the given InputSource . |
XMLBeanInfo |
introspect(org.apache.commons.beanutils.DynaClass dynaClass)
Creates XMLBeanInfo by reading the DynaProperties of a DynaBean.
|
XMLBeanInfo |
introspect(Object bean)
Create a standard
XMLBeanInfo by introspection
The actual introspection depends only on the BeanInfo
associated with the bean. |
boolean |
isAttributesForPrimitives()
Deprecated.
0.6 use getConfiguration().isAttributesForPrimitives
|
boolean |
isCachingEnabled()
Deprecated.
0.5 replaced by XMlBeanInfoRegistry
|
boolean |
isLoopType(Class type)
Is this class a loop?
|
boolean |
isPrimitiveType(Class type)
Is this class a primitive?
|
boolean |
isWrapCollectionsInElement()
Deprecated.
0.6 use getConfiguration().isWrapCollectionsInElement
|
void |
register(Class aClass,
org.xml.sax.InputSource source)
Registers the class mapping specified in the standard dot-betwixt file.
|
Class[] |
register(org.xml.sax.InputSource source)
Registers the class mappings specified in the multi-class document
given by the
InputSource . |
void |
setAttributeNameMapper(NameMapper nameMapper)
Deprecated.
0.6 use getConfiguration().setAttributeNameMapper
|
void |
setAttributesForPrimitives(boolean attributesForPrimitives)
Deprecated.
0.6 use getConfiguration().setAttributesForPrimitives
|
void |
setCachingEnabled(boolean cachingEnabled)
Deprecated.
0.5 replaced by XMlBeanInfoRegistry
|
void |
setClassNormalizer(ClassNormalizer classNormalizer)
Deprecated.
0.6 use getConfiguration().setClassNormalizer
|
void |
setConfiguration(IntrospectionConfiguration configuration)
Sets the configuration to be used for introspection.
|
void |
setElementNameMapper(NameMapper nameMapper)
Deprecated.
0.6 use getConfiguration().setElementNameMapper
|
void |
setLog(org.apache.commons.logging.Log log)
Sets the current logging implementation.
|
void |
setNameMapper(NameMapper nameMapper)
Deprecated.
0.5 setNameMapper is split up in
setElementNameMapper(NameMapper) and setAttributeNameMapper(NameMapper) |
void |
setPluralStemmer(PluralStemmer pluralStemmer)
Deprecated.
0.6 use getConfiguration().setPluralStemmer
|
void |
setPolymorphicReferenceResolver(PolymorphicReferenceResolver polymorphicReferenceResolver)
Sets the resolver for polymorphic references.
|
void |
setRegistry(XMLBeanInfoRegistry registry)
Sets the
XMLBeanInfoRegistry implementation. |
void |
setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath)
Deprecated.
0.6 use getConfiguration().setUseBeanInfoSearchPath
|
void |
setWrapCollectionsInElement(boolean wrapCollectionsInElement)
Deprecated.
0.6 use getConfiguration().setWrapCollectionsInElement
|
boolean |
useBeanInfoSearchPath()
Deprecated.
0.6 use getConfiguration().useBeanInfoSearchPath
|
protected org.apache.commons.logging.Log log
getLog()
property insteadpublic XMLIntrospector()
public XMLIntrospector(IntrospectionConfiguration configuration)
IntrospectionConfiguration
subclasses
to be easily used.configuration
- IntrospectionConfiguration, not nullpublic org.apache.commons.logging.Log getLog()
Gets the current logging implementation.
public void setLog(org.apache.commons.logging.Log log)
Sets the current logging implementation.
log
- the Log implementation to use for loggingpublic XMLBeanInfoRegistry getRegistry()
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.
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.
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
setPolymorphicReferenceResolver(PolymorphicReferenceResolver)
may be necessary.
registry
- the XMLBeanInfoRegistry to usepublic IntrospectionConfiguration getConfiguration()
public void setConfiguration(IntrospectionConfiguration configuration)
configuration
- IntrospectionConfiguration, not nullpublic ClassNormalizer getClassNormalizer()
ClassNormalizer
strategy.
This is used to determine the Class to be introspected
(the normalized Class).ClassNormalizer
used to determine the Class to be introspected
for a given Object.public void setClassNormalizer(ClassNormalizer classNormalizer)
ClassNormalizer
strategy.
This is used to determine the Class to be introspected
(the normalized Class).classNormalizer
- the ClassNormalizer
to be used to determine
the Class to be introspected for a given Object.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. It is therefore convenient to keep both references together.
Note: though the implementation is
set initially to the default registry,
this reference is not updated when setRegistry(XMLBeanInfoRegistry)
is called. Therefore, a call to setPolymorphicReferenceResolver(PolymorphicReferenceResolver)
with the instance may be necessary.
PolymorphicReferenceResolver
, not nullpublic 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. It is therefore convenient to keep both references together.
Note: though the implementation is
set initially to the default registry,
this reference is not updated when setRegistry(XMLBeanInfoRegistry)
is called. Therefore, a call to setPolymorphicReferenceResolver(PolymorphicReferenceResolver)
with the instance may be necessary.
polymorphicReferenceResolver
- The polymorphicReferenceResolver to set.public boolean isCachingEnabled()
XMLBeanInfo
caching enabled?public void setCachingEnabled(boolean cachingEnabled)
XMLBeanInfo
caching should be enabled.cachingEnabled
- ignoredpublic boolean isAttributesForPrimitives()
public void setAttributesForPrimitives(boolean attributesForPrimitives)
attributesForPrimitives
- pass trus to map primitives to attributes,
pass false to map primitives to elementspublic boolean isWrapCollectionsInElement()
public void setWrapCollectionsInElement(boolean wrapCollectionsInElement)
wrapCollectionsInElement
- pass true if collections should be wrapped in a
parent elementpublic PluralStemmer getPluralStemmer()
public void setPluralStemmer(PluralStemmer pluralStemmer)
pluralStemmer
- the PluralStemmer used to match singular and pluralpublic NameMapper getNameMapper()
public void setNameMapper(NameMapper nameMapper)
setElementNameMapper(NameMapper)
and setAttributeNameMapper(NameMapper)
nameMapper
- the NameMapper strategy to be usedpublic NameMapper getElementNameMapper()
public void setElementNameMapper(NameMapper nameMapper)
nameMapper
- the NameMapper to use for the conversionpublic NameMapper getAttributeNameMapper()
public void setAttributeNameMapper(NameMapper nameMapper)
nameMapper
- the NameMapper to use for the convertionpublic boolean useBeanInfoSearchPath()
java.reflect.Introspector
bean info search path be used?
By default it will be false.public void setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath)
useBeanInfoSearchPath
- for more details
public void flushCache()
XMLBeanInfo
's.public XMLBeanInfo introspect(Object bean) throws IntrospectionException
XMLBeanInfo
by introspection
The actual introspection depends only on the BeanInfo
associated with the bean.bean
- introspect this beanIntrospectionException
- when the bean introspection failspublic XMLBeanInfo introspect(org.apache.commons.beanutils.DynaClass dynaClass)
dynaClass
- the DynaBean to introspectpublic XMLBeanInfo introspect(Class aClass, org.xml.sax.InputSource source) throws IOException, org.xml.sax.SAXException
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. Use register(Class, InputSource)
instead.
aClass
- Class
, not nullsource
- InputSource
, not nullXMLBeanInfo
describing the mapping.org.xml.sax.SAXException
- when the input source cannot be parsedIOException
public XMLBeanInfo introspect(Class aClass) throws IntrospectionException
XMLBeanInfo
by introspection.
The actual introspection depends only on the BeanInfo
associated with the bean.aClass
- introspect this classIntrospectionException
- when the bean introspection failspublic XMLBeanInfo introspect(BeanInfo beanInfo) throws IntrospectionException
XMLBeanInfo
by introspection.
The actual introspection depends only on the BeanInfo
associated with the bean.beanInfo
- the BeanInfo the xml-bean mapping is based onIntrospectionException
- when the bean introspection failspublic Class[] register(org.xml.sax.InputSource source) throws IntrospectionException, IOException, org.xml.sax.SAXException
Registers the class mappings specified in the multi-class document
given by the InputSource
.
Note: that this method will override any existing mapping for the speficied classes.
source
- InputSource
, not nullClass
array containing all mapped classesIntrospectionException
org.xml.sax.SAXException
IOException
public void register(Class aClass, org.xml.sax.InputSource source) throws IOException, org.xml.sax.SAXException
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.
aClass
- Class
, not nullsource
- InputSource
, not nullorg.xml.sax.SAXException
- when the source cannot be parsedIOException
protected XMLBeanInfo createXMLBeanInfo(org.apache.commons.beanutils.DynaClass dynaClass)
dynaClass
- the class describing a DynaBeanpublic Descriptor createDescriptor(PropertyDescriptor propertyDescriptor, boolean useAttributesForPrimitives) throws IntrospectionException
createXMLDescriptor(org.apache.commons.betwixt.BeanProperty)
.propertyDescriptor
- create a NodeDescriptor
for this propertyuseAttributesForPrimitives
- write primitives as attributes (rather than elements)NodeDescriptor
for the propertyIntrospectionException
- when bean introspection failspublic Descriptor createXMLDescriptor(BeanProperty beanProperty)
beanProperty
- the BeanProperty specifying the propertyNodeDescriptor
for the propertypublic void defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass)
rootDescriptor
- add defaults to this descriptorbeanClass
- the Class
to which descriptor correspondspublic void defaultAddMethods(ElementDescriptor rootDescriptor, Class beanClass, boolean preservePropertyName)
rootDescriptor
- add defaults to this descriptorbeanClass
- the Class
to which descriptor correspondspublic void assignAdder(Method twinParameterAdderMethod, ElementDescriptor matchingDescriptor)
twinParameterAdderMethod
- adder Method
, not nullmatchingDescriptor
- ElementDescriptor
describing the elementprotected PluralStemmer createPluralStemmer()
protected NameMapper createNameMapper()
protected XMLBeanInfo findByXMLDescriptor(Class aClass)
aClass
- digester .betwixt file for this classprotected void addProperties(BeanInfo beanInfo, List elements, List attributes, List contents) throws IntrospectionException
addProperties(BeanProperty[], List, List,List)
beanInfo
- the BeanInfo whose properties will be processedelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedcontents
- Descriptor list to which mixed content will be addedIntrospectionException
- if the bean introspection failsprotected void addProperties(BeanProperty[] beanProperties, List elements, List attributes, List contents)
beanProperties
- the properties to be processedelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedcontents
- Descriptor list to which mixed content will be addedprotected void addProperty(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) throws IntrospectionException
addProperty(PropertyDescriptor, List, List, List)
instead.beanInfo
- the BeanInfo whose property is being processedpropertyDescriptor
- the PropertyDescriptor to processelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedcontents
- Descriptor list to which mixed content will be addedIntrospectionException
- if the bean introspection failsprotected void addProperty(PropertyDescriptor propertyDescriptor, List elements, List attributes, List contents) throws IntrospectionException
addProperty(BeanProperty, List, List, List)
insteadpropertyDescriptor
- the PropertyDescriptor to processelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedcontents
- Descriptor list to which mixed content will be addedIntrospectionException
- if the bean introspection failsprotected void addProperty(BeanProperty beanProperty, List elements, List attributes, List contents)
beanProperty
- the bean property to processelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedcontents
- Descriptor list to which mixed content will be addedprotected void addProperties(BeanInfo beanInfo, List elements, List attributes) throws IntrospectionException
addProperties(BeanInfo, List, List, List)
instead.beanInfo
- the BeanInfo whose properties will be processedelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedIntrospectionException
- if the bean introspection failsprotected void addProperty(BeanInfo beanInfo, PropertyDescriptor propertyDescriptor, List elements, List attributes) throws IntrospectionException
addProperty(BeanInfo, PropertyDescriptor, List, List, List)
instead.beanInfo
- the BeanInfo whose property is being processedpropertyDescriptor
- the PropertyDescriptor to processelements
- ElementDescriptor list to which elements will be addedattributes
- AttributeDescriptor list to which attributes will be addedIntrospectionException
- if the bean introspection failsprotected XMLBeanInfo createXMLBeanInfo(BeanInfo beanInfo)
beanInfo
- the BeanInfo from which the XMLBeanInfo will be createdpublic boolean isLoopType(Class type)
type
- the Class to testpublic boolean isPrimitiveType(Class type)
type
- the Class to testCopyright © 2002-2013 Apache Software Foundation. All Rights Reserved.