org.apache.avalon.fortress.impl.factory
Class BCELWrapperGenerator

java.lang.Object
  extended by org.apache.avalon.fortress.impl.factory.BCELWrapperGenerator

final class BCELWrapperGenerator
extends java.lang.Object

Create the BCELWrapper for the component. The generated wrapper classes will be assigned the same ProtectionDomain as the actual classes which they are wrapping. This simplifies the configuration of a SecurityManager by making the existence of the BCEL generated classes transparent to the policy file author.

Author:
Avalon Development Team

Nested Class Summary
private  class BCELWrapperGenerator.BCELClassLoader
           
 
Field Summary
private  BCELWrapperGenerator.BCELClassLoader m_bcelClassLoader
          The ClassLoader to use when loading a class generated by this BCELWrapperGenerator.
private  org.apache.bcel.generic.ClassGen m_classGenerator
          The ClassGen instance to use for byte code generation.
private  BCELCodeGenerator m_codeGenerator
          The BCELCodeGenerator to use for byte code generation.
private  org.apache.bcel.util.Repository m_repository
          The BCEL util.Repository instance to use when loading JavaClass instances.
private static java.lang.String WRAPPER_CLASS_INTERFACE_NAME
          The name of the interface each generated wrapper class has to implement.
private static java.lang.String WRAPPER_CLASS_SUFFIX
          The suffix to be appended to the name of the wrapped class when creating the name of the wrapper class.
private static java.lang.String WRAPPER_SUPERCLASS_NAME
          The name of the superclass of the wrapper class to be generated.
 
Constructor Summary
BCELWrapperGenerator()
          No-args default constructor.
 
Method Summary
private  byte[] buildWrapper(org.apache.bcel.classfile.JavaClass[] interfacesToImplement)
          Generates the wrapper byte code for a given interface.
 java.lang.Class createWrapper(java.lang.Class classToWrap)
           
private  java.lang.String[] extractInterfaceNames(java.lang.Class[] interfaces)
          Takes an array of Class instances supposed to represent interfaces and returns a list of the names of those interfaces.
private  org.apache.bcel.classfile.JavaClass lookupClass(java.lang.Class clazz)
          Takes a Class instance as a its parameter and returns corresponding the JavaClass instance as used by BCEL.
private  org.apache.bcel.classfile.JavaClass[] lookupClasses(java.lang.Class[] classes)
          Takes an array of Class instances and returns an array holding the corresponding JavaClass instances as used by BCEL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_repository

private org.apache.bcel.util.Repository m_repository
The BCEL util.Repository instance to use when loading JavaClass instances. Default is to use util.ClassLoaderRepository with thread context classloader.


WRAPPER_CLASS_SUFFIX

private static final java.lang.String WRAPPER_CLASS_SUFFIX
The suffix to be appended to the name of the wrapped class when creating the name of the wrapper class.

See Also:
Constant Field Values

WRAPPER_SUPERCLASS_NAME

private static final java.lang.String WRAPPER_SUPERCLASS_NAME
The name of the superclass of the wrapper class to be generated.

See Also:
Constant Field Values

WRAPPER_CLASS_INTERFACE_NAME

private static final java.lang.String WRAPPER_CLASS_INTERFACE_NAME
The name of the interface each generated wrapper class has to implement.


m_codeGenerator

private final BCELCodeGenerator m_codeGenerator
The BCELCodeGenerator to use for byte code generation.


m_classGenerator

private org.apache.bcel.generic.ClassGen m_classGenerator
The ClassGen instance to use for byte code generation.


m_bcelClassLoader

private final BCELWrapperGenerator.BCELClassLoader m_bcelClassLoader
The ClassLoader to use when loading a class generated by this BCELWrapperGenerator.

Constructor Detail

BCELWrapperGenerator

public BCELWrapperGenerator()
No-args default constructor.

Method Detail

createWrapper

public java.lang.Class createWrapper(java.lang.Class classToWrap)
                              throws java.lang.Exception
Throws:
java.lang.Exception

lookupClass

private org.apache.bcel.classfile.JavaClass lookupClass(java.lang.Class clazz)
                                                 throws java.lang.Exception
Takes a Class instance as a its parameter and returns corresponding the JavaClass instance as used by BCEL.

Parameters:
clazz - The Class instance we want to turn into a JavaClass
Returns:
The JavaClass representing the given Class instance
Throws:
java.lang.Exception

lookupClasses

private org.apache.bcel.classfile.JavaClass[] lookupClasses(java.lang.Class[] classes)
                                                     throws java.lang.Exception
Takes an array of Class instances and returns an array holding the corresponding JavaClass instances as used by BCEL.

Parameters:
classes - An array holding Class instances we want to turn into JavaClass instances
Returns:
JavaClass[] An array of JavaClass instances representing the given Class instances
Throws:
java.lang.Exception

extractInterfaceNames

private java.lang.String[] extractInterfaceNames(java.lang.Class[] interfaces)
Takes an array of Class instances supposed to represent interfaces and returns a list of the names of those interfaces.

Parameters:
interfaces - An array of Class instances
Returns:
String[] An array of the names of those Class instances

buildWrapper

private byte[] buildWrapper(org.apache.bcel.classfile.JavaClass[] interfacesToImplement)
                     throws java.lang.Exception
Generates the wrapper byte code for a given interface.

Parameters:
interfacesToImplement - The interfaces we want to generate wrapper byte code for
Returns:
byte[] The generated byte code
Throws:
java.lang.Exception