raccoon.core.bean.descriptor
Class BeanAnalyzer

java.lang.Object
  extended by raccoon.core.bean.descriptor.BeanAnalyzer
All Implemented Interfaces:
IBeanAnalyzer, ILogable

public class BeanAnalyzer
extends java.lang.Object
implements IBeanAnalyzer, ILogable

The default bean analyzer offered by the Raccoon Framework.

This Bean Analyzer component uses the reflexion service of the JDK to extract from any given Class the valid Castor bean properties (get<Property>/set<Property>) and the valid Raccoon bean properties (get<Property>/set<Property>/add<Property>).

Furthermore the result of the introspection is cached for improoved acces time and if necessary lazy introspection can be applied.
Lazy introspection means that the class is introspected when required. If lazy introspection is deactivated than the class is fully introspected, including the classes that this class contains.

Since:
Raccoon v0.1, refactored in Raccoon v0.4, v0.5 & v0.8
Version:
$Id: BeanAnalyzer.java,v 1.1 2004/08/08 20:19:16 crouvrais Exp $
Author:
Cedric ROUVRAIS

Field Summary
static java.lang.Class[] ATOMIC_CLASSES
          The official class types that are considered atomic by the Raccoon Framework.
 
Constructor Summary
BeanAnalyzer()
           
 
Method Summary
 IBeanDescriptor introspect(java.lang.Class pJavaBean)
          Introspects the class and returns the description of the class.
 boolean isArray(java.lang.Class pClass)
          Checks if this provided class is an array element.
 boolean isAtomic(java.lang.Class pClass)
          Checks if this provided class is an atomic element.
 boolean isCollection(java.lang.Class pClass)
          Checks if this provided class is a collection element.
 boolean isLazyIntrospect()
          Is lazy introspection activated, default is true.
protected  void logDroppedMethod(java.lang.String pReason, java.lang.reflect.Method pMethod)
          Sends to the log file of this instance information regarding a bean method that is unused.
protected  IBeanDescriptor parseBean(java.lang.Class pClassToIntrospect)
          Introspects the bean in order to determine all bean methods that are available.
protected  java.util.ArrayList retainAssociatedAccessors(java.util.ArrayList pSetters, java.util.ArrayList pGetters)
          For each getter method, searches for a corresponding setter with the same type.
protected  java.util.ArrayList searchForAdders(java.util.ArrayList pPropertyDesc, java.util.ArrayList pAdders)
          For each get/set property see if we can locate an associated adder.
 void setLazyIntrospect(boolean pLazyIntrospect)
          Define the introspection mode.
 void setLogger(ILogger pLogger)
          Assigns the logger to the component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATOMIC_CLASSES

public static final java.lang.Class[] ATOMIC_CLASSES
The official class types that are considered atomic by the Raccoon Framework.

Constructor Detail

BeanAnalyzer

public BeanAnalyzer()
Method Detail

setLogger

public void setLogger(ILogger pLogger)
               throws java.lang.IllegalStateException
Assigns the logger to the component.

Specified by:
setLogger in interface ILogable
Parameters:
pLogger - the logging instance to use.
Throws:
java.lang.IllegalStateException - if the component is already loaded, valid only if the component implements the ILoadable interface.

isLazyIntrospect

public boolean isLazyIntrospect()
Is lazy introspection activated, default is true.

Returns:
the introspection mode

setLazyIntrospect

public void setLazyIntrospect(boolean pLazyIntrospect)
Define the introspection mode.

Parameters:
pLazyIntrospect - the mode of introspection

isAtomic

public boolean isAtomic(java.lang.Class pClass)
Checks if this provided class is an atomic element.

Specified by:
isAtomic in interface IBeanAnalyzer
Parameters:
pClass - the class to analyse.
Returns:
true if this class is atomic

isArray

public boolean isArray(java.lang.Class pClass)
Checks if this provided class is an array element.

Specified by:
isArray in interface IBeanAnalyzer
Parameters:
pClass - the class to analyse.
Returns:
true if this class is an array

isCollection

public boolean isCollection(java.lang.Class pClass)
Checks if this provided class is a collection element.

Specified by:
isCollection in interface IBeanAnalyzer
Parameters:
pClass - the class to analyse.
Returns:
true if this class is a collection
See Also:
Collection

introspect

public IBeanDescriptor introspect(java.lang.Class pJavaBean)
                           throws RaccoonException
Introspects the class and returns the description of the class. If the class was previously introspected than the cached introspection is sent back.

The class passed must comply to the Raccoon specification of a java bean.

Specified by:
introspect in interface IBeanAnalyzer
Parameters:
pJavaBean - the class that is to be introspected, should be a Java Bean.
Returns:
the descriptor of the provided class.
Throws:
RaccoonException - if the service isn't running.
RaccoonException - if the class can't be analyzed

parseBean

protected IBeanDescriptor parseBean(java.lang.Class pClassToIntrospect)
                             throws IntrospectionException
Introspects the bean in order to determine all bean methods that are available.

A Bean method is recognized by the fact that is starts with one of the following strings:

Any methods that respect these conditions are declared as beans, for more information one should refer to the methods found in the see section

Parameters:
pClassToIntrospect - the java bean that is to be introspected.
Returns:
the bean descriptor that corresponds to the given class, this should be a new instance.
Throws:
IntrospectionException - if the introspection fails for some reason (java security exception for example).

searchForAdders

protected java.util.ArrayList searchForAdders(java.util.ArrayList pPropertyDesc,
                                              java.util.ArrayList pAdders)
                                       throws IntrospectionException
For each get/set property see if we can locate an associated adder.

Parameters:
pPropertyDesc - the list of current BeanProperty instances that only have the defined setters and getters.
pAdders - the list of methods whose name starts with add
Returns:
array list of BeanProperty where the understandable adders have been appended.
Throws:
IntrospectionException - if the associated getter/setter and adder of a given set are invalid (should be considered as a bug)

retainAssociatedAccessors

protected java.util.ArrayList retainAssociatedAccessors(java.util.ArrayList pSetters,
                                                        java.util.ArrayList pGetters)
                                                 throws IntrospectionException
For each getter method, searches for a corresponding setter with the same type. Discards the methods that are matched, in other words the remaining elements of pSetters and pGetters are those that are unmatched.

Parameters:
pSetters - the array of methods that are possible setter methods.
pGetters - the array of methods that are possible getter methods.
Returns:
an array of BeanProperty elements containing the get/set pair only.
Throws:
IntrospectionException - if the PropertyDescriptor refuses and instanciation (should be a bug though)

logDroppedMethod

protected final void logDroppedMethod(java.lang.String pReason,
                                      java.lang.reflect.Method pMethod)
Sends to the log file of this instance information regarding a bean method that is unused.

Parameters:
pReason - the reason for which the method is being ignored
pMethod - the method that is ignored.


Copyright null null. All Rights Reserved.