Save This Page
Home » commons-betwixt-0.8-src » org.apache.commons » betwixt » [javadoc | source]
org.apache.commons.betwixt
public class: XMLIntrospector [javadoc | source]
java.lang.Object
   org.apache.commons.betwixt.XMLIntrospector

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

Field Summary
protected  Log log    Log used for logging (Doh!)
     
    Constructor:
     public XMLIntrospector() 
     public XMLIntrospector(IntrospectionConfiguration configuration) 
      Construct allows a custom configuration to be set on construction. This allows IntrospectionConfiguration subclasses to be easily used.
      Parameters:
      configuration - IntrospectionConfiguration, not null
    Method from org.apache.commons.betwixt.XMLIntrospector Summary:
    addProperties,   addProperties,   addProperties,   addProperty,   addProperty,   addProperty,   addProperty,   assignAdder,   createDescriptor,   createNameMapper,   createPluralStemmer,   createXMLBeanInfo,   createXMLBeanInfo,   createXMLDescriptor,   defaultAddMethods,   defaultAddMethods,   findByXMLDescriptor,   flushCache,   getAttributeNameMapper,   getClassNormalizer,   getConfiguration,   getElementNameMapper,   getLog,   getNameMapper,   getPluralStemmer,   getPolymorphicReferenceResolver,   getRegistry,   introspect,   introspect,   introspect,   introspect,   introspect,   isAttributesForPrimitives,   isCachingEnabled,   isLoopType,   isPrimitiveType,   isWrapCollectionsInElement,   register,   register,   setAttributeNameMapper,   setAttributesForPrimitives,   setCachingEnabled,   setClassNormalizer,   setConfiguration,   setElementNameMapper,   setLog,   setNameMapper,   setPluralStemmer,   setPolymorphicReferenceResolver,   setRegistry,   setUseBeanInfoSearchPath,   setWrapCollectionsInElement,   useBeanInfoSearchPath
    Methods from java.lang.Object:
    equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
    Method from org.apache.commons.betwixt.XMLIntrospector Detail:
     protected  void addProperties(BeanInfo beanInfo,
        List elements,
        List attributes) throws IntrospectionException 
    Deprecated! 0.5 - this method does not support mixed content. Use #addProperties(BeanInfo, List, List, List) instead.

      Loop through properties and process each one
     protected  void addProperties(BeanInfo beanInfo,
        List elements,
        List attributes,
        List contents) throws IntrospectionException 
    Deprecated! 0.5 - use #addProperties(BeanProperty[], List, List,List)

      Loop through properties and process each one
     protected  void addProperties(BeanProperty[] beanProperties,
        List elements,
        List attributes,
        List contents) 
      Loop through properties and process each one
     protected  void addProperty(PropertyDescriptor propertyDescriptor,
        List elements,
        List attributes,
        List contents) throws IntrospectionException 
    Deprecated! 0.5 - use #addProperty(BeanProperty, List, List, List) instead

      Process a property. Go through and work out whether it's a loop property, a primitive or a standard. The class property is ignored.
     protected  void addProperty(BeanProperty beanProperty,
        List elements,
        List attributes,
        List contents) 
      Process a property. Go through and work out whether it's a loop property, a primitive or a standard. The class property is ignored.
     protected  void addProperty(BeanInfo beanInfo,
        PropertyDescriptor propertyDescriptor,
        List elements,
        List attributes) throws IntrospectionException 
    Deprecated! 0.5 - this method does not support mixed content. Use #addProperty(BeanInfo, PropertyDescriptor, List, List, List) instead.

      Process a property. Go through and work out whether it's a loop property, a primitive or a standard. The class property is ignored.
     protected  void addProperty(BeanInfo beanInfo,
        PropertyDescriptor propertyDescriptor,
        List elements,
        List attributes,
        List contents) throws IntrospectionException 
    Deprecated! 0.5 - BeanInfo is no longer required. Use #addProperty(PropertyDescriptor, List, List, List) instead.

      Process a property. Go through and work out whether it's a loop property, a primitive or a standard. The class property is ignored.
     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) throws IntrospectionException 
    Deprecated! 0.5 - use #createXMLDescriptor .

      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.
     protected NameMapper createNameMapper() 
    Deprecated! 0.6 - this method has been moved into IntrospectionConfiguration. Those who need to vary this should subclass that class instead

      A Factory method to lazily create a strategy used to convert bean type names into element names.
     protected PluralStemmer createPluralStemmer() 
    Deprecated! 0.6 - this method has been moved into IntrospectionConfiguration. Those who need to vary this should subclass that class instead

      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) 
      Factory method to create XMLBeanInfo instances
     public Descriptor createXMLDescriptor(BeanProperty beanProperty) 
      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.
     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. 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.
     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. 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.
     protected synchronized 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
     public  void flushCache() 
    Deprecated! 0.5 - use flushable registry instead

      Flush existing cached XMLBeanInfo's.
     public NameMapper getAttributeNameMapper() 
    Deprecated! 0.6 - getConfiguration().getAttributeNameMapper

      Gets the name mapping strategy used to convert bean names into attributes.
     public ClassNormalizer getClassNormalizer() 
    Deprecated! 0.6 - use getConfiguration().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. 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.
     public NameMapper getElementNameMapper() 
    Deprecated! 0.6 - use getConfiguration().getElementNameMapper

      Gets the name mapping strategy used to convert bean names into elements.
     public Log getLog() 

      Gets the current logging implementation.

     public NameMapper getNameMapper() 
    Deprecated! 0.5 - getNameMapper is split up in #getElementNameMapper() and #getAttributeNameMapper()

      Gets the name mapper strategy.
     public PluralStemmer getPluralStemmer() 
    Deprecated! 0.6 - use getConfiguration().getPluralStemmer

      Get singular and plural matching strategy.
     public PolymorphicReferenceResolver getPolymorphicReferenceResolver() 
     public 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 XMLBeanInfo introspect(Object bean) throws IntrospectionException 
      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. Customizing DynaBeans using betwixt is not supported.
     public XMLBeanInfo introspect(Class aClass) throws IntrospectionException 
      Create a standard XMLBeanInfo by introspection. The actual introspection depends only on the BeanInfo associated with the bean.
     public XMLBeanInfo introspect(BeanInfo beanInfo) throws IntrospectionException 
      Create a standard XMLBeanInfo by introspection. The actual introspection depends only on the BeanInfo associated with the bean.
     public synchronized XMLBeanInfo introspect(Class aClass,
        InputSource source) throws IOException, 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.

     public boolean isAttributesForPrimitives() 
    Deprecated! 0.6 - use getConfiguration().isAttributesForPrimitives

      Should attributes (or elements) be used for primitive types.
     public boolean isCachingEnabled() 
    Deprecated! 0.5 - replaced by XMlBeanInfoRegistry

      Is XMLBeanInfo caching enabled?
     public boolean isLoopType(Class type) 
      Is this class a loop?
     public boolean isPrimitiveType(Class type) 
      Is this class a primitive?
     public boolean isWrapCollectionsInElement() 
    Deprecated! 0.6 - use getConfiguration().isWrapCollectionsInElement

      Should collections be wrapped in an extra element?
     public synchronized Class[] register(InputSource source) throws IntrospectionException, IOException, 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.

     public  void register(Class aClass,
        InputSource source) throws IOException, 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.

     public  void setAttributeNameMapper(NameMapper nameMapper) 
    Deprecated! 0.6 - use getConfiguration().setAttributeNameMapper

      Sets the strategy used to convert bean type names into attribute names
     public  void setAttributesForPrimitives(boolean attributesForPrimitives) 
    Deprecated! 0.6 - use getConfiguration().setAttributesForPrimitives

      Set whether attributes (or elements) should be used for primitive types.
     public  void setCachingEnabled(boolean cachingEnabled) 
    Deprecated! 0.5 - replaced by XMlBeanInfoRegistry

      Set whether XMLBeanInfo caching should be enabled.
     public  void setClassNormalizer(ClassNormalizer classNormalizer) 
    Deprecated! 0.6 - use getConfiguration().setClassNormalizer

      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. 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.
     public  void setElementNameMapper(NameMapper nameMapper) 
    Deprecated! 0.6 - use getConfiguration().setElementNameMapper

      Sets the strategy used to convert bean type names into element names
     public  void setLog(Log log) 

      Sets the current logging implementation.

     public  void setNameMapper(NameMapper nameMapper) 
    Deprecated! 0.5 - setNameMapper is split up in #setElementNameMapper(NameMapper) and #setAttributeNameMapper(NameMapper)

      Sets the strategy used to convert bean type names into element names
     public  void setPluralStemmer(PluralStemmer pluralStemmer) 
    Deprecated! 0.6 - use getConfiguration().setPluralStemmer

      Sets the strategy used to detect matching singular and plural properties
     public  void setPolymorphicReferenceResolver(PolymorphicReferenceResolver polymorphicReferenceResolver) 
     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.

     public  void setUseBeanInfoSearchPath(boolean useBeanInfoSearchPath) 
    Deprecated! 0.6 - use getConfiguration().setUseBeanInfoSearchPath

      Specifies if you want to use the beanInfoSearchPath
     public  void setWrapCollectionsInElement(boolean wrapCollectionsInElement) 
    Deprecated! 0.6 - use getConfiguration().setWrapCollectionsInElement

      Sets whether we should we wrap collections in an extra element.
     public boolean useBeanInfoSearchPath() 
    Deprecated! 0.6 - use getConfiguration().useBeanInfoSearchPath

      Should the original java.reflect.Introspector bean info search path be used? By default it will be false.