JBoss Reflection 2.2.1.SP1

org.jboss.reflect.plugins.javassist
Class JavassistTypeInfoFactoryImpl

java.lang.Object
  extended by org.jboss.util.collection.WeakClassCache<TypeInfo>
      extended by org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl
All Implemented Interfaces:
AnnotationHelper, MutableTypeInfoFactory, TypeInfoFactory

public class JavassistTypeInfoFactoryImpl
extends org.jboss.util.collection.WeakClassCache<TypeInfo>
implements MutableTypeInfoFactory, AnnotationHelper

A javassist type factory. TODO: need to fix the cl stuff

Version:
$Revision: 110312 $
Author:
Adrian Brock, Ales Justin

Nested Class Summary
protected static class JavassistTypeInfoFactoryImpl.ModifiableArrayType
          Wrapper around SignatureAttribute.ArrayType to make it easier to create the name used to look up the array type infos in the cache
 
Field Summary
 
Fields inherited from class org.jboss.util.collection.WeakClassCache
cache
 
Method Summary
protected static String convertName(javassist.CtClass clazz)
          Convert name
 AnnotationValue createAnnotationValue(AnnotationInfo info, Object ann)
          Create an annotation from the underlying implementation and its info type
 MutableClassInfo createNewMutableClass(String name)
          Creates a new MutableClass.
 MutableClassInfo createNewMutableClass(String name, ClassInfo superClass)
          Creates a new MutableClass.
 MutableClassInfo createNewMutableInterface(String name)
          Creates a new mutable interface.
 MutableClassInfo createNewMutableInterface(String name, ClassInfo superClass)
          Creates a new mutable interface.
protected  TypeInfo createTypeInfoForTypeArgument(javassist.bytecode.SignatureAttribute.TypeArgument arg, ClassLoader loader, org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
          Gets the type info for a javassist type argument
protected  void generate(Class clazz, TypeInfo result)
           
 TypeInfo get(Class clazz)
          Get the information for a class
protected  TypeInfo get(javassist.CtClass ctClass)
          Get the information for a class
protected  TypeInfo get(javassist.CtClass ctClass, Class<?> clazz, String name, ClassLoader cl, boolean delegateToReflectIfNotFound)
          Get the information for a class
 TypeInfo get(String name, ClassLoader cl)
          Get the information for a class
protected  TypeInfo get(String name, ClassLoader cl, Class<?> clazz)
          Get the information for a class
 AnnotationValue[] getAnnotations(Object obj)
          Get the annotations for the annotated object
protected  Map<String,WeakReference<TypeInfo>> getClassLoaderCache(ClassLoader cl)
          Gets the classloader cache for the passed in classloader.
protected  javassist.CtClass getCtClass(String name)
          Gets the CtClass corresponding to name by using the bootstrap class pool.
protected  javassist.CtClass getCtClass(String name, ClassLoader classLoader)
          Gets the CtClass corresponding to name.
protected  ArrayInfo getGenericArrayType(ClassLoader cl, JavassistTypeInfoFactoryImpl.ModifiableArrayType type, org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
          Recursively get the type info for a javassist array type
protected  ArrayInfo getGenericArrayType(ClassLoader cl, javassist.bytecode.SignatureAttribute.ArrayType type, org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
          Get the type info for a javassist array type
protected  TypeInfo getGenericArrayType(GenericArrayType type)
          Get the type info for a reflect generic array type
 MutableClassInfo getMutable(String name, ClassLoader cl)
          Gets the information for a MutableClass.
protected  TypeInfo getParameterizedType(ParameterizedType type)
          Creates a type info from a reflect generic paramemeterized type
static ClassPoolFactory getPoolFactory()
           
 TypeInfo getTypeInfo(Class<?> clazz)
          Get a type info
protected  TypeInfo getTypeInfo(ClassLoader loader, javassist.bytecode.SignatureAttribute.ClassType type, org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
          Gets the type info for a javassist generic class type
protected  TypeInfo getTypeInfo(ClassLoader loader, javassist.bytecode.SignatureAttribute.Type type, org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
          Gets the type info for a javassist type
protected  TypeInfo getTypeInfo(javassist.CtClass ctClass)
          Get the type info
 TypeInfo getTypeInfo(String name, ClassLoader cl)
          Gets the type info for a class
 TypeInfo getTypeInfo(Type type)
          Gets the type info for a reflect type
protected  TypeInfo getTypeVariable(TypeVariable<?> type)
          Get the type info for a reflect TypeVariable
protected  TypeInfo getWildcardType(WildcardType type)
          Gets the type info for a reflect wildcard type
protected  TypeInfo instantiate(Class clazz)
           
protected  TypeInfo instantiate(javassist.CtClass ctClass, Class<?> clazz)
           
static NoClassDefFoundError raiseClassNotFound(String name, ClassNotFoundException e)
          Raise NoClassDefFoundError for javassist not found
static NoClassDefFoundError raiseClassNotFound(String name, javassist.NotFoundException e)
          Raise NoClassDefFoundError for javassist not found
static NoClassDefFoundError raiseFieldNotFound(String name, javassist.NotFoundException e)
          Raise NoClassDefFoundError for javassist not found
static NoClassDefFoundError raiseMethodNotFound(String name, javassist.NotFoundException e)
          Raise NoClassDefFoundError for javassist not found
static void setPoolFactory(ClassPoolFactory classPoolFactory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPoolFactory

public static ClassPoolFactory getPoolFactory()

setPoolFactory

public static void setPoolFactory(ClassPoolFactory classPoolFactory)

raiseClassNotFound

public static NoClassDefFoundError raiseClassNotFound(String name,
                                                      javassist.NotFoundException e)
                                               throws NoClassDefFoundError
Raise NoClassDefFoundError for javassist not found

Parameters:
name - the name
e - the not found error
Returns:
never
Throws:
NoClassDefFoundError - always

raiseClassNotFound

public static NoClassDefFoundError raiseClassNotFound(String name,
                                                      ClassNotFoundException e)
                                               throws NoClassDefFoundError
Raise NoClassDefFoundError for javassist not found

Parameters:
name - the name
e - the not found error
Returns:
never
Throws:
NoClassDefFoundError - always

raiseMethodNotFound

public static NoClassDefFoundError raiseMethodNotFound(String name,
                                                       javassist.NotFoundException e)
                                                throws NoClassDefFoundError
Raise NoClassDefFoundError for javassist not found

Parameters:
name - the name
e - the not found error
Returns:
never
Throws:
NoClassDefFoundError - always

raiseFieldNotFound

public static NoClassDefFoundError raiseFieldNotFound(String name,
                                                      javassist.NotFoundException e)
                                               throws NoClassDefFoundError
Raise NoClassDefFoundError for javassist not found

Parameters:
name - the name
e - the not found error
Returns:
never
Throws:
NoClassDefFoundError - always

instantiate

protected TypeInfo instantiate(Class clazz)
Specified by:
instantiate in class org.jboss.util.collection.WeakClassCache<TypeInfo>

instantiate

protected TypeInfo instantiate(javassist.CtClass ctClass,
                               Class<?> clazz)

getTypeInfo

protected TypeInfo getTypeInfo(javassist.CtClass ctClass)
Get the type info

Parameters:
ctClass - the ctClass
Returns:
the typeinfo

convertName

protected static String convertName(javassist.CtClass clazz)
Convert name

Parameters:
clazz - the class
Returns:
the converted name

getCtClass

protected javassist.CtClass getCtClass(String name,
                                       ClassLoader classLoader)
Gets the CtClass corresponding to name.

Parameters:
name - the name of the CtClass to be retrieved
classLoader - the classLoader that loaded the corresponding Class object
Returns:
the CtClass

getCtClass

protected javassist.CtClass getCtClass(String name)
Gets the CtClass corresponding to name by using the bootstrap class pool.

Parameters:
name - the name of the CtClass to be retrieved
Returns:
the CtClass

generate

protected void generate(Class clazz,
                        TypeInfo result)
Specified by:
generate in class org.jboss.util.collection.WeakClassCache<TypeInfo>

getTypeInfo

public TypeInfo getTypeInfo(Class<?> clazz)
Description copied from interface: TypeInfoFactory
Get a type info

Specified by:
getTypeInfo in interface TypeInfoFactory
Parameters:
clazz - the class
Returns:
the type info

getTypeInfo

public TypeInfo getTypeInfo(String name,
                            ClassLoader cl)
                     throws ClassNotFoundException
Gets the type info for a class

Specified by:
getTypeInfo in interface TypeInfoFactory
Parameters:
name - the type
cl - the classloader
Returns:
the type info
Throws:
ClassNotFoundException - when there is no such class

getTypeInfo

public TypeInfo getTypeInfo(Type type)
Gets the type info for a reflect type

Specified by:
getTypeInfo in interface TypeInfoFactory
Parameters:
type - the type
Returns:
the type info

get

public TypeInfo get(String name,
                    ClassLoader cl)
             throws ClassNotFoundException
Get the information for a class

Overrides:
get in class org.jboss.util.collection.WeakClassCache<TypeInfo>
Parameters:
name - the name
cl - the classloader
Returns:
the info
Throws:
ClassNotFoundException - when the class cannot be found

get

public TypeInfo get(Class clazz)
Get the information for a class

Overrides:
get in class org.jboss.util.collection.WeakClassCache<TypeInfo>
Parameters:
clazz - the class
Returns:
the info

get

protected TypeInfo get(String name,
                       ClassLoader cl,
                       Class<?> clazz)
                throws ClassNotFoundException
Get the information for a class

Parameters:
name - the name
cl - the classloader
clazz - the class
Returns:
the info
Throws:
ClassNotFoundException - when the class cannot be found

get

protected TypeInfo get(javassist.CtClass ctClass)
Get the information for a class

Parameters:
ctClass - the class
Returns:
the info

get

protected TypeInfo get(javassist.CtClass ctClass,
                       Class<?> clazz,
                       String name,
                       ClassLoader cl,
                       boolean delegateToReflectIfNotFound)
                throws ClassNotFoundException
Get the information for a class

Parameters:
ctClass - the class, may be null
clazz - the class, may be null
name - the name of the class
cl - the class loader
Returns:
the info
Throws:
IllegalArgumentException - if either name or cl are null
ClassNotFoundException

getAnnotations

public AnnotationValue[] getAnnotations(Object obj)
Description copied from interface: AnnotationHelper
Get the annotations for the annotated object

Specified by:
getAnnotations in interface AnnotationHelper
Parameters:
obj - the annotated object
Returns:
the annotations

createAnnotationValue

public AnnotationValue createAnnotationValue(AnnotationInfo info,
                                             Object ann)
Description copied from interface: AnnotationHelper
Create an annotation from the underlying implementation and its info type

Specified by:
createAnnotationValue in interface AnnotationHelper
Parameters:
info - the annotation info
ann - the underlying annotation
Returns:
the annotation value

getMutable

public MutableClassInfo getMutable(String name,
                                   ClassLoader cl)
Description copied from interface: MutableTypeInfoFactory
Gets the information for a MutableClass. Note that this will not put the MutableClass in any cache.

Specified by:
getMutable in interface MutableTypeInfoFactory
Parameters:
name - the name of the class to be retrieved
cl - the ClassLoader that should be used to retrieve the class. Note that, if cl is null, the default ClassLoader will be used.
Returns:
the MutableClassInfo representation of the queried class

createNewMutableClass

public MutableClassInfo createNewMutableClass(String name)
Description copied from interface: MutableTypeInfoFactory
Creates a new MutableClass.

Specified by:
createNewMutableClass in interface MutableTypeInfoFactory
Parameters:
name - the name of the class to be created
Returns:
the created class

createNewMutableClass

public MutableClassInfo createNewMutableClass(String name,
                                              ClassInfo superClass)
Description copied from interface: MutableTypeInfoFactory
Creates a new MutableClass.

Specified by:
createNewMutableClass in interface MutableTypeInfoFactory
Parameters:
name - the name of the class to be created
superClass - the super class of the class to be created
Returns:
the created class

createNewMutableInterface

public MutableClassInfo createNewMutableInterface(String name)
Description copied from interface: MutableTypeInfoFactory
Creates a new mutable interface.

Specified by:
createNewMutableInterface in interface MutableTypeInfoFactory
Parameters:
name - the name of the interface to be created
Returns:
the created interface

createNewMutableInterface

public MutableClassInfo createNewMutableInterface(String name,
                                                  ClassInfo superClass)
Description copied from interface: MutableTypeInfoFactory
Creates a new mutable interface.

Specified by:
createNewMutableInterface in interface MutableTypeInfoFactory
Parameters:
name - the name of the interface to be created
superClass - the super type of the interface to be created
Returns:
the created interface

getParameterizedType

protected TypeInfo getParameterizedType(ParameterizedType type)
Creates a type info from a reflect generic paramemeterized type

Parameters:
type - the parameterized type
Returns:
the type info

getTypeInfo

protected TypeInfo getTypeInfo(ClassLoader loader,
                               javassist.bytecode.SignatureAttribute.Type type,
                               org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
Gets the type info for a javassist type

Parameters:
loader - the class loader
type - the class type
spy - used to determine actual types of type variables
Returns:
the type info

getTypeInfo

protected TypeInfo getTypeInfo(ClassLoader loader,
                               javassist.bytecode.SignatureAttribute.ClassType type,
                               org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
Gets the type info for a javassist generic class type

Parameters:
loader - the class loader of the raw class
type - the class type
spy - used to determine actual types of type variables
Returns:
the type info

createTypeInfoForTypeArgument

protected TypeInfo createTypeInfoForTypeArgument(javassist.bytecode.SignatureAttribute.TypeArgument arg,
                                                 ClassLoader loader,
                                                 org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
Gets the type info for a javassist type argument

Parameters:
arg - the type argument
loader - the class loader
spy - used to determine actual types of type variables
Returns:
the type info

getWildcardType

protected TypeInfo getWildcardType(WildcardType type)
Gets the type info for a reflect wildcard type

Parameters:
type - the wildcard type
Returns:
the type info

getClassLoaderCache

protected Map<String,WeakReference<TypeInfo>> getClassLoaderCache(ClassLoader cl)
Gets the classloader cache for the passed in classloader.

Overrides:
getClassLoaderCache in class org.jboss.util.collection.WeakClassCache<TypeInfo>
Parameters:
cl - the classloader. If null is used, the Thread context classloader will be used instead
Returns:
the cache of type infos by name

getGenericArrayType

protected TypeInfo getGenericArrayType(GenericArrayType type)
Get the type info for a reflect generic array type

Parameters:
type - the array type
Returns:
the info

getGenericArrayType

protected ArrayInfo getGenericArrayType(ClassLoader cl,
                                        javassist.bytecode.SignatureAttribute.ArrayType type,
                                        org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
Get the type info for a javassist array type

Parameters:
cl - the classloader
type - the array type
spy - used to determine actual types of type variables
Returns:
the type info

getGenericArrayType

protected ArrayInfo getGenericArrayType(ClassLoader cl,
                                        JavassistTypeInfoFactoryImpl.ModifiableArrayType type,
                                        org.jboss.reflect.plugins.javassist.JavassistTypeVariableSpy spy)
Recursively get the type info for a javassist array type

Parameters:
cl - the classloader
type - the array type
spy - used to determine actual types of type variables
Returns:
the type info

getTypeVariable

protected TypeInfo getTypeVariable(TypeVariable<?> type)
Get the type info for a reflect TypeVariable

Parameters:
type - the type variable
Returns:
the type info

JBoss Reflection 2.2.1.SP1

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.