org.apache.commons.clazz
Class Clazz

java.lang.Object
  extended by org.apache.commons.clazz.common.ClazzElementSupport
      extended by org.apache.commons.clazz.Clazz
All Implemented Interfaces:
ClazzElement
Direct Known Subclasses:
BeanClazz, ReflectedClazz

public abstract class Clazz
extends ClazzElementSupport
implements ClazzElement

Version:
$Id: Clazz.java 155436 2005-02-26 13:17:48Z dirkv $
Author:
Stephen Colebourne, Dmitri Plotnikov

Field Summary
static String EXTENDED_CLAZZ_MODEL
          The name of the extended clazz model.
static String STANDARD_CLAZZ_MODEL
          The name of the standard clazz model.
 
Constructor Summary
protected Clazz(ClazzLoader modelClazzLoader, String name)
          Keep the constructor protected or private, we want Clazzes to be created by the ClazzLoaders only.
 
Method Summary
 void addClazzChangeListener(ClazzChangeListener listener)
           
static void addClazzLoaderFactory(ClazzLoaderFactory factory)
          Register a clazz loader factory, which manages ClazzLoaders, which manage Clazzes.
static String constructSignature(String name, Class[] arguments)
          Creates a signature string out of an operation or instance factory name and parameter types.
static String constructSignature(String name, Clazz[] arguments)
          Creates a signature string out of an operation or instance factory name and parameter types.
protected  void fireInstanceFactoryAdded(ClazzInstanceFactory factory)
           
protected  void fireInstanceFactoryRemoved(ClazzInstanceFactory factory)
           
protected  void fireOperationAdded(ClazzOperation operation)
           
protected  void fireOperationRemoved(ClazzOperation operation)
           
protected  void firePropertyAdded(ClazzProperty property)
           
protected  void firePropertyRemoved(ClazzProperty property)
           
static String getCanonicalClassName(Class javaClass)
          Produces a nice type name for a classes representing an array, e.g.
static Clazz getClazz(Object instance)
          Uses the default clazz loader to obtain the Clazz for the supplied object.
static Clazz getClazz(Object instance, String model)
          Uses the clazz loader for the specified model to obtain the Clazz for the supplied object.
 ClazzLoader getClazzLoader()
          Every Clazz belongs to one and only one ClazzLoader.
static ClazzLoader getClazzLoader(String model, ClassLoader classLoader)
          Returns a clazz loader for the specified model.
static ClazzLoaderFactory getClazzLoaderFactory(String model)
          Returns a ClazzLoaderFactory registered for the supplied model.
abstract  List getDeclaredOperations()
          Returns all Operations declared by this clazz, not its superclazzes.
abstract  List getDeclaredProperties()
          Returns properties declared by this Clazz, not its superclazzes
static ClazzLoader getDefaultClazzLoader(ClassLoader classLoader)
          Returns the ClazzLoader for the default clazz model.
static String getDefaultClazzModel()
          Returns the name of the default clazz model.
abstract  Class getInstanceClass()
          Returns the class of instances created by the newInstance() method.
abstract  List getInstanceFactories()
          Returns all InstanceFactories for this clazz.
abstract  ClazzInstanceFactory getInstanceFactory(String signature)
          Returns ClazzInstanceFactory for the given signature.
 String getName()
          Returns the name of the Clazz.
abstract  ClazzOperation getOperation(String signature)
          Returns the Operation for the given signature.
abstract  List getOperations()
          Returns all Operations for this clazz.
 String getPackageName()
          Gets the package name.
abstract  List getProperties()
          Returns all properties for this clazz, including those declared by superclazzes.
abstract  ClazzProperty getProperty(String name)
          Returns a ClazzProperty for the given name
 String getShortClassName()
          Gets the class name (without the package).
abstract  Clazz getSuperclazz()
          Returns the superclazz for this Clazz, or null if there is none.
 boolean isAssignableFrom(Clazz clazz)
          Returns true if the supplied clazz is either the same or a subclazz of this clazz.
 Object newInstance()
          Creates a new instance of this Clazz using the InstanceFactory that takes no parameters.
 Object newInstance(String signature, Object[] parameters)
          Creates a new instance of this Clazz using the InstanceFactory with the specified signature.
 void removeClazzChangeListener(ClazzChangeListener listener)
           
static void setDefaultClazzModel(String defaultClazzModel)
          Select the default clazz model.
 
Methods inherited from class org.apache.commons.clazz.common.ClazzElementSupport
getAttribute, getAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.clazz.ClazzElement
getAttribute, getAttributes
 

Field Detail

STANDARD_CLAZZ_MODEL

public static final String STANDARD_CLAZZ_MODEL
The name of the standard clazz model. The value of the constant is "Standard".

See Also:
Constant Field Values

EXTENDED_CLAZZ_MODEL

public static final String EXTENDED_CLAZZ_MODEL
The name of the extended clazz model. The value of the constant is "Extended".

See Also:
Constant Field Values
Constructor Detail

Clazz

protected Clazz(ClazzLoader modelClazzLoader,
                String name)
Keep the constructor protected or private, we want Clazzes to be created by the ClazzLoaders only.

Parameters:
loader - is the owning model clazz loader
name - must be unique within the model
Method Detail

addClazzLoaderFactory

public static void addClazzLoaderFactory(ClazzLoaderFactory factory)
Register a clazz loader factory, which manages ClazzLoaders, which manage Clazzes.

Parameters:
clazzLoaderFactory -

getClazzLoaderFactory

public static ClazzLoaderFactory getClazzLoaderFactory(String model)
Returns a ClazzLoaderFactory registered for the supplied model. We can have multiple clazz loader factories implementing different models (e.g. Standard JavaBeans, Extended JavaBeans etc).

Parameters:
model - is the type of the model we need
Returns:
ClazzLoaderFactory

setDefaultClazzModel

public static void setDefaultClazzModel(String defaultClazzModel)
Select the default clazz model.

Parameters:
defaultClazzModel -

getDefaultClazzModel

public static String getDefaultClazzModel()
Returns the name of the default clazz model.


getClazzLoader

public static ClazzLoader getClazzLoader(String model,
                                         ClassLoader classLoader)
Returns a clazz loader for the specified model. The provided ClassLoader can be used by the ClazzLoader for reflection.

Parameters:
model -
classLoader -
Returns:
ClazzLoader

getDefaultClazzLoader

public static ClazzLoader getDefaultClazzLoader(ClassLoader classLoader)
Returns the ClazzLoader for the default clazz model.


getClazz

public static Clazz getClazz(Object instance,
                             String model)
Uses the clazz loader for the specified model to obtain the Clazz for the supplied object.


getClazz

public static Clazz getClazz(Object instance)
Uses the default clazz loader to obtain the Clazz for the supplied object.


getClazzLoader

public ClazzLoader getClazzLoader()
Every Clazz belongs to one and only one ClazzLoader. Its name is unique within that loader.


getName

public String getName()
Returns the name of the Clazz. It is ok for the same name to be present in different ClazzLoaders, except CachingClazzLoaders.


getPackageName

public String getPackageName()
Gets the package name.

Returns:
the package name

getShortClassName

public String getShortClassName()
Gets the class name (without the package).

Returns:
the class name (without the package)

getInstanceClass

public abstract Class getInstanceClass()
Returns the class of instances created by the newInstance() method.


getSuperclazz

public abstract Clazz getSuperclazz()
Returns the superclazz for this Clazz, or null if there is none.


isAssignableFrom

public boolean isAssignableFrom(Clazz clazz)
Returns true if the supplied clazz is either the same or a subclazz of this clazz.


getDeclaredProperties

public abstract List getDeclaredProperties()
Returns properties declared by this Clazz, not its superclazzes


getProperties

public abstract List getProperties()
Returns all properties for this clazz, including those declared by superclazzes.


getProperty

public abstract ClazzProperty getProperty(String name)
Returns a ClazzProperty for the given name


getOperations

public abstract List getOperations()
Returns all Operations for this clazz.


getDeclaredOperations

public abstract List getDeclaredOperations()
Returns all Operations declared by this clazz, not its superclazzes.


getOperation

public abstract ClazzOperation getOperation(String signature)
Returns the Operation for the given signature. The signature should be formatted as follows: "name(paramClazzName1,...)"


getInstanceFactories

public abstract List getInstanceFactories()
Returns all InstanceFactories for this clazz.


getInstanceFactory

public abstract ClazzInstanceFactory getInstanceFactory(String signature)
Returns ClazzInstanceFactory for the given signature. The signature should be formatted as follows: "(paramClazzName1,...)". You can pass null in place of "()".


newInstance

public Object newInstance()
Creates a new instance of this Clazz using the InstanceFactory that takes no parameters.


newInstance

public Object newInstance(String signature,
                          Object[] parameters)
Creates a new instance of this Clazz using the InstanceFactory with the specified signature.


addClazzChangeListener

public void addClazzChangeListener(ClazzChangeListener listener)

removeClazzChangeListener

public void removeClazzChangeListener(ClazzChangeListener listener)

firePropertyAdded

protected void firePropertyAdded(ClazzProperty property)

firePropertyRemoved

protected void firePropertyRemoved(ClazzProperty property)

fireOperationAdded

protected void fireOperationAdded(ClazzOperation operation)

fireOperationRemoved

protected void fireOperationRemoved(ClazzOperation operation)

fireInstanceFactoryAdded

protected void fireInstanceFactoryAdded(ClazzInstanceFactory factory)

fireInstanceFactoryRemoved

protected void fireInstanceFactoryRemoved(ClazzInstanceFactory factory)

constructSignature

public static String constructSignature(String name,
                                        Class[] arguments)
Creates a signature string out of an operation or instance factory name and parameter types.


constructSignature

public static String constructSignature(String name,
                                        Clazz[] arguments)
Creates a signature string out of an operation or instance factory name and parameter types.


getCanonicalClassName

public static String getCanonicalClassName(Class javaClass)
Produces a nice type name for a classes representing an array, e.g. "[I" is shown as "int[]". For non-array types returns the regular type name.



Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.