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 |
---|---|
private NameMapper |
attributeNameMapper
The strategy used to convert bean type names into attribute names
It will default to the normal nameMapper.
|
private boolean |
attributesForPrimitives
should attributes or elements be used for primitive types
|
private XMLBeanInfoDigester |
digester
Digester used to parse the XML descriptor files
|
private NameMapper |
elementNameMapper
The strategy used to convert bean type names into element names
|
protected Log |
log
Log used for logging (Doh!)
|
private PluralStemmer |
pluralStemmer
The strategy used to detect matching singular and plural properties
|
private XMLBeanInfoRegistry |
registry
Maps classes to
XMLBeanInfo 's |
private boolean |
useBeanInfoSearchPath
Should the existing bean info search path for java.reflect.Introspector be used?
|
private boolean |
wrapCollectionsInElement
should we wrap collections in an extra element?
|
Constructor and Description |
---|
XMLIntrospector()
Base constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
addProperties(BeanInfo beanInfo,
List elements,
List attributes)
Loop through properties and process each one
|
protected void |
addProperty(BeanInfo beanInfo,
PropertyDescriptor propertyDescriptor,
List elements,
List attributes)
Process a property.
|
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(BeanInfo beanInfo)
Factory method to create XMLBeanInfo instances
|
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.
use flushable registry instead
|
NameMapper |
getAttributeNameMapper()
Gets the name mapping strategy used to convert bean names into attributes.
|
NameMapper |
getElementNameMapper()
Gets the name mapping strategy used to convert bean names into elements.
|
Log |
getLog()
Gets the current logging implementation.
|
NameMapper |
getNameMapper()
Deprecated.
getNameMapper is split up in
getElementNameMapper() and getAttributeNameMapper() |
PluralStemmer |
getPluralStemmer()
Get singular and plural matching strategy.
|
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(Object bean)
Create a standard
XMLBeanInfo by introspection
The actual introspection depends only on the BeanInfo
associated with the bean. |
boolean |
isAttributesForPrimitives()
Should attributes (or elements) be used for primitive types.
|
boolean |
isCachingEnabled()
Deprecated.
replaced by XMlBeanInfoRegistry
|
boolean |
isLoopType(Class type)
Is this class a loop?
|
boolean |
isPrimitiveType(Class type)
Is this class a primitive?
|
boolean |
isWrapCollectionsInElement()
Should collections be wrapped in an extra element?
|
void |
setAttributeNameMapper(NameMapper nameMapper)
Sets the strategy used to convert bean type names into attribute names
|
void |
setAttributesForPrimitives(boolean attributesForPrimitives)
Set whether attributes (or elements) should be used for primitive types.
|
void |
setCachingEnabled(boolean cachingEnabled)
Deprecated.
replaced by XMlBeanInfoRegistry
|
void |
setElementNameMapper(NameMapper nameMapper)
Sets the strategy used to convert bean type names into element names
|
void |
setLog(Log log)
Sets the current logging implementation.
|
void |
setNameMapper(NameMapper nameMapper)
Deprecated.
setNameMapper is split up in
setElementNameMapper(NameMapper) and setAttributeNameMapper(NameMapper) |
void |
setPluralStemmer(PluralStemmer pluralStemmer)
Sets the strategy used to detect matching singular and plural properties
|
void |
setRegistry(XMLBeanInfoRegistry registry)
Sets the
XMLBeanInfoRegistry implementation. |
void |
setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath)
Specifies if you want to use the beanInfoSearchPath
|
void |
setWrapCollectionsInElement(boolean wrapCollectionsInElement)
Sets whether we should we wrap collections in an extra element.
|
boolean |
useBeanInfoSearchPath()
Should the original
java.reflect.Introspector bean info search path be used?
By default it will be false. |
protected Log log
private boolean attributesForPrimitives
private boolean wrapCollectionsInElement
private XMLBeanInfoRegistry registry
XMLBeanInfo
'sprivate XMLBeanInfoDigester digester
private PluralStemmer pluralStemmer
private NameMapper elementNameMapper
private NameMapper attributeNameMapper
private boolean useBeanInfoSearchPath
public Log getLog()
Gets the current logging implementation.
public void setLog(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.
registry
- the XMLBeanInfoRegistry to usepublic boolean isCachingEnabled()
XMLBeanInfo
caching enabled?public void setCachingEnabled(boolean cachingEnabled)
XMLBeanInfo
caching should be enabled.cachingEnabled
- ignoredpublic 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(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 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 convertionprotected 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) throws IntrospectionException
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
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 testpublic 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