Package javassist.tools.rmi
Class StubGenerator
- java.lang.Object
-
- javassist.tools.rmi.StubGenerator
-
- All Implemented Interfaces:
Translator
public class StubGenerator extends java.lang.Object implements Translator
A stub-code generator. It is used for producing a proxy class.The proxy class for class A is as follows:
public class A implements Proxy, Serializable { private ObjectImporter importer; private int objectId; public int _getObjectId() { return objectId; } public A(ObjectImporter oi, int id) { importer = oi; objectId = id; } ... the same methods that the original class A declares ... }Instances of the proxy class is created by an
ObjectImporterobject.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringaccessorObjectIdprivate ClassPoolclassPoolprivate CtClass[]exceptionForProxyprivate static java.lang.StringfieldImporterprivate static java.lang.StringfieldObjectIdprivate CtMethodforwardMethodprivate CtMethodforwardStaticMethodprivate CtClass[]interfacesForProxyprivate java.util.HashtableproxyClassesprivate CtClass[]proxyConstructorParamTypesprivate static java.lang.StringsampleClass
-
Constructor Summary
Constructors Constructor Description StubGenerator()Constructs a stub-code generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddMethods(CtClass proxy, java.lang.reflect.Method[] ms)booleanisProxyClass(java.lang.String name)Returnstrueif the specified class is a proxy class recorded bymakeProxyClass().booleanmakeProxyClass(java.lang.Class clazz)Makes a proxy class.private voidmodifySuperclass(CtClass orgclass)Adds a default constructor to the super classes.voidonLoad(ClassPool pool, java.lang.String classname)Does nothing.private CtClassproduceProxyClass(CtClass orgclass, java.lang.Class orgRtClass)voidstart(ClassPool pool)Initializes the object.private CtClasstoCtClass(java.lang.Class rtclass)private CtClass[]toCtClass(java.lang.Class[] rtclasses)
-
-
-
Field Detail
-
fieldImporter
private static final java.lang.String fieldImporter
- See Also:
- Constant Field Values
-
fieldObjectId
private static final java.lang.String fieldObjectId
- See Also:
- Constant Field Values
-
accessorObjectId
private static final java.lang.String accessorObjectId
- See Also:
- Constant Field Values
-
sampleClass
private static final java.lang.String sampleClass
- See Also:
- Constant Field Values
-
classPool
private ClassPool classPool
-
proxyClasses
private java.util.Hashtable proxyClasses
-
forwardMethod
private CtMethod forwardMethod
-
forwardStaticMethod
private CtMethod forwardStaticMethod
-
proxyConstructorParamTypes
private CtClass[] proxyConstructorParamTypes
-
interfacesForProxy
private CtClass[] interfacesForProxy
-
exceptionForProxy
private CtClass[] exceptionForProxy
-
-
Method Detail
-
start
public void start(ClassPool pool) throws NotFoundException
Initializes the object. This is a method declared in javassist.Translator.- Specified by:
startin interfaceTranslator- Parameters:
pool- theClassPoolthat this translator should use.- Throws:
NotFoundException- if aCtClasscannot be found.- See Also:
Translator.start(ClassPool)
-
onLoad
public void onLoad(ClassPool pool, java.lang.String classname)
Does nothing. This is a method declared in javassist.Translator.- Specified by:
onLoadin interfaceTranslator- Parameters:
pool- theClassPoolthat this translator should use.classname- the name of the class being loaded.- See Also:
Translator.onLoad(ClassPool,String)
-
isProxyClass
public boolean isProxyClass(java.lang.String name)
Returnstrueif the specified class is a proxy class recorded bymakeProxyClass().- Parameters:
name- a fully-qualified class name
-
makeProxyClass
public boolean makeProxyClass(java.lang.Class clazz) throws CannotCompileException, NotFoundExceptionMakes a proxy class. The produced class is substituted for the original class.- Parameters:
clazz- the class referenced through the proxy class.- Returns:
falseif the proxy class has been already produced.- Throws:
CannotCompileExceptionNotFoundException
-
produceProxyClass
private CtClass produceProxyClass(CtClass orgclass, java.lang.Class orgRtClass) throws CannotCompileException, NotFoundException
-
toCtClass
private CtClass toCtClass(java.lang.Class rtclass) throws NotFoundException
- Throws:
NotFoundException
-
toCtClass
private CtClass[] toCtClass(java.lang.Class[] rtclasses) throws NotFoundException
- Throws:
NotFoundException
-
addMethods
private void addMethods(CtClass proxy, java.lang.reflect.Method[] ms) throws CannotCompileException, NotFoundException
-
modifySuperclass
private void modifySuperclass(CtClass orgclass) throws CannotCompileException, NotFoundException
Adds a default constructor to the super classes.
-
-