jodd.introspector
Class ClassDescriptor

java.lang.Object
  extended by jodd.introspector.ClassDescriptor

public class ClassDescriptor
extends Object

A descriptor class for all methods/fields/constructors of a class. Static methods/fields are ignored. Hash table is pre-built to speed up query.

Descriptors are 'lazy': various internal caches are created only on request.

Throughout this class, public members are defined as members defined with "public" keyword and declared in a public type. Public members declared by a non-public class is considered non-public because access to it from outside is prohibited by the java access control anyway.

Public members defined in public classes are always preferred even when we allow private/protected members and types to be visible. So if a non-public subtype and a public super type both have a field with the same name, the field in the public super type is always used.


Field Summary
protected  boolean accessibleOnly
           
protected  jodd.introspector.Ctors allCtors
           
protected  jodd.introspector.Fields allFields
           
protected  jodd.introspector.Methods allMethods
           
protected  jodd.introspector.Properties allProperties
           
protected  jodd.introspector.Ctors publicCtors
           
protected  jodd.introspector.Fields publicFields
           
protected  jodd.introspector.Methods publicMethods
           
protected  jodd.introspector.Properties publicProperties
           
protected  Class type
           
protected  int usageCount
           
 
Constructor Summary
ClassDescriptor(Class type, boolean accessibleOnly)
           
 
Method Summary
 String[] getAllBeanGetterNames()
          Returns all public bean getters names.
 String[] getAllBeanGetterNames(boolean suppressSecurity)
          Returns all bean getters names.
 Method[] getAllBeanGetters()
          Returns all public bean getters.
 Method[] getAllBeanGetters(boolean suppressSecurity)
          Returns all bean getters.
 String[] getAllBeanSetterNames()
          Returns an array of all public bean setters names.
 String[] getAllBeanSetterNames(boolean suppressSecurity)
          Returns an array of all bean setters names.
 Method[] getAllBeanSetters()
          Returns an array of all public bean setters.
 Method[] getAllBeanSetters(boolean suppressSecurity)
          Returns an array of all bean setters.
 Constructor[] getAllCtors()
          Returns an array of all public ctors.
 Constructor[] getAllCtors(boolean suppressSecurity)
          Returns an array of all ctors.
 Field[] getAllFields()
          Returns an array of all public fields.
 Field[] getAllFields(boolean suppressSecurity)
          Returns an array of all fields.
 Method[] getAllMethods()
          Returns an array of all public methods.
 Method[] getAllMethods(boolean supressSecurity)
          Returns an array of all methods.
 Method[] getAllMethods(String name)
          Returns an array of all public methods with the same name.
 Method[] getAllMethods(String name, boolean supressSecurity)
          Returns an array of all methods with the same name.
 Method getBeanGetter(String name)
          Returns public bean getter identified by name.
 Method getBeanGetter(String name, boolean suppressSecurity)
          Returns bean getter identified by name.
 Method getBeanSetter(String name)
          Returns public bean setter identified by name.
 Method getBeanSetter(String name, boolean suppressSecurity)
          Returns bean setter identified by name.
 Constructor getCtor(Class[] args)
          Returns the public ctor identified by arguments or null if not found.
 Constructor getCtor(Class[] args, boolean suppressSecurity)
          Returns the constructor identified by arguments or null if not found.
 int getCtorCount()
          Returns the total number of public constructors.
 int getCtorCount(boolean suppressSecurity)
          Returns the total number of constructors.
 Constructor getDefaultCtor()
          Returns the public default ctor or null if not found.
 Constructor getDefaultCtor(boolean suppressSecurity)
          Returns the default ctor or null if not found.
 Field getField(String name)
          Returns the public field identified by name or null if not found.
 Field getField(String name, boolean suppressSecurity)
          Returns the field identified by name or null if not found.
 int getFieldCount()
          Returns the total number of public fields.
 int getFieldCount(boolean suppressSecurity)
          Returns the total number of fields.
 Method getMethod(String name)
          Returns the public method identified by name or null if not found.
 Method getMethod(String name, boolean suppressSecurity)
          Returns the method identified by name or null if not found.
 Method getMethod(String name, Class[] params)
          Returns the public method identified by name and parameters.
 Method getMethod(String name, Class[] params, boolean suppressSecurity)
          Returns the method identified by name and parameters.
 Class getType()
          Get the class object that this descriptor describes.
 int getUsageCount()
          Returns number of class description usages.
protected  void increaseUsageCount()
          Increases descriptor usage.
protected  void inspectCtors()
          Inspect class ctors and create ctors cache.
protected  void inspectFields()
          Inspect class fields and create fields cache.
protected  void inspectMethods()
          Inspect methods and create methods cache.
protected  void inspectProperties()
          Inspect methods and create properties cache.
 boolean isArray()
          Returns true if class is an array.
 boolean isCollection()
           
 boolean isList()
          Returns true if class is a List.
 boolean isMap()
          Returns true if class is a Map.
 boolean isSet()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

protected final Class type

accessibleOnly

protected final boolean accessibleOnly

usageCount

protected int usageCount

publicFields

protected jodd.introspector.Fields publicFields

allFields

protected jodd.introspector.Fields allFields

publicMethods

protected jodd.introspector.Methods publicMethods

allMethods

protected jodd.introspector.Methods allMethods

publicProperties

protected jodd.introspector.Properties publicProperties

allProperties

protected jodd.introspector.Properties allProperties

publicCtors

protected jodd.introspector.Ctors publicCtors

allCtors

protected jodd.introspector.Ctors allCtors
Constructor Detail

ClassDescriptor

public ClassDescriptor(Class type,
                       boolean accessibleOnly)
Method Detail

getType

public Class getType()
Get the class object that this descriptor describes.


increaseUsageCount

protected void increaseUsageCount()
Increases descriptor usage.


getUsageCount

public int getUsageCount()
Returns number of class description usages.


isArray

public boolean isArray()
Returns true if class is an array.


isMap

public boolean isMap()
Returns true if class is a Map.


isList

public boolean isList()
Returns true if class is a List.


isSet

public boolean isSet()

isCollection

public boolean isCollection()

inspectFields

protected void inspectFields()
Inspect class fields and create fields cache.


getField

public Field getField(String name,
                      boolean suppressSecurity)
Returns the field identified by name or null if not found.

Parameters:
name - field name
suppressSecurity - whether to look at non-public ones.

getField

public Field getField(String name)
Returns the public field identified by name or null if not found.


getFieldCount

public int getFieldCount(boolean suppressSecurity)
Returns the total number of fields.


getFieldCount

public int getFieldCount()
Returns the total number of public fields.


getAllFields

public Field[] getAllFields(boolean suppressSecurity)
Returns an array of all fields.


getAllFields

public Field[] getAllFields()
Returns an array of all public fields.


inspectMethods

protected void inspectMethods()
Inspect methods and create methods cache.


getMethod

public Method getMethod(String name,
                        boolean suppressSecurity)
Returns the method identified by name or null if not found.

Parameters:
name - method name
suppressSecurity - whether to look at non-public ones.

getMethod

public Method getMethod(String name)
Returns the public method identified by name or null if not found.


getMethod

public Method getMethod(String name,
                        Class[] params,
                        boolean suppressSecurity)
Returns the method identified by name and parameters.


getMethod

public Method getMethod(String name,
                        Class[] params)
Returns the public method identified by name and parameters.


getAllMethods

public Method[] getAllMethods(String name,
                              boolean supressSecurity)
Returns an array of all methods with the same name.


getAllMethods

public Method[] getAllMethods(String name)
Returns an array of all public methods with the same name.


getAllMethods

public Method[] getAllMethods(boolean supressSecurity)
Returns an array of all methods.


getAllMethods

public Method[] getAllMethods()
Returns an array of all public methods.


inspectProperties

protected void inspectProperties()
Inspect methods and create properties cache.


getBeanSetter

public Method getBeanSetter(String name,
                            boolean suppressSecurity)
Returns bean setter identified by name.


getBeanSetter

public Method getBeanSetter(String name)
Returns public bean setter identified by name.


getAllBeanSetters

public Method[] getAllBeanSetters(boolean suppressSecurity)
Returns an array of all bean setters.


getAllBeanSetters

public Method[] getAllBeanSetters()
Returns an array of all public bean setters.


getAllBeanSetterNames

public String[] getAllBeanSetterNames(boolean suppressSecurity)
Returns an array of all bean setters names.


getAllBeanSetterNames

public String[] getAllBeanSetterNames()
Returns an array of all public bean setters names.


getBeanGetter

public Method getBeanGetter(String name,
                            boolean suppressSecurity)
Returns bean getter identified by name.


getBeanGetter

public Method getBeanGetter(String name)
Returns public bean getter identified by name.


getAllBeanGetters

public Method[] getAllBeanGetters(boolean suppressSecurity)
Returns all bean getters.


getAllBeanGetters

public Method[] getAllBeanGetters()
Returns all public bean getters.


getAllBeanGetterNames

public String[] getAllBeanGetterNames(boolean suppressSecurity)
Returns all bean getters names.


getAllBeanGetterNames

public String[] getAllBeanGetterNames()
Returns all public bean getters names.


inspectCtors

protected void inspectCtors()
Inspect class ctors and create ctors cache.


getDefaultCtor

public Constructor getDefaultCtor(boolean suppressSecurity)
Returns the default ctor or null if not found.


getCtor

public Constructor getCtor(Class[] args,
                           boolean suppressSecurity)
Returns the constructor identified by arguments or null if not found.

Parameters:
args - ctor arguments
suppressSecurity - whether to look at non-public ones.

getCtor

public Constructor getCtor(Class[] args)
Returns the public ctor identified by arguments or null if not found.


getDefaultCtor

public Constructor getDefaultCtor()
Returns the public default ctor or null if not found.


getCtorCount

public int getCtorCount(boolean suppressSecurity)
Returns the total number of constructors.


getCtorCount

public int getCtorCount()
Returns the total number of public constructors.


getAllCtors

public Constructor[] getAllCtors(boolean suppressSecurity)
Returns an array of all ctors.


getAllCtors

public Constructor[] getAllCtors()
Returns an array of all public ctors.