Class Generator

java.lang.Object
com.sun.ejb.codegen.Generator
Direct Known Subclasses:
GenericHomeGenerator, Remote30WrapperGenerator, RemoteGenerator, ServiceInterfaceGenerator

public abstract class Generator extends Object
The base class for all code generators.
  • Constructor Details

  • Method Details

    • getPackageName

      protected abstract String getPackageName()
      Returns:
      the name of the package of the generated class. Can be null.
    • getGeneratedClassName

      public abstract String getGeneratedClassName()
      Returns:
      name of the generated class or interface
    • getAnchorClass

      protected abstract Class<?> getAnchorClass()
      Returns:
      loadable class of the same package as getGeneratedClassName()
    • defineClassBody

      protected abstract void defineClassBody()
      Calls Wrapper methods to configure the class definition. The Wrapper uses ThreadLocal internally, so you should always call Wrapper._clear() in finally block after generation to avoid leakages.
    • getClassLoader

      public ClassLoader getClassLoader()
      Returns:
      ClassLoader owning the generated class.
    • generate

      public Class<?> generate() throws IllegalAccessException
      Generates the bytecode of the configured class with the usage of the PFL tool. Then uses MethodHandles or ClassGenerator to generate the class.

      WARNING: This selection depends on the classloader capabilities and JVM rules, which change between JDK versions.

      Returns:
      Class
      Throws:
      IllegalAccessException
    • getPackageName

      public static String getPackageName(String fullClassName)
      Returns:
      the package name or null.
    • getBaseName

      public static String getBaseName(String fullClassName)
      Returns:
      simple class name (including wrapper class and dollar sign if it is internal class)
    • removeRedundantMethods

      protected Method[] removeRedundantMethods(Method[] methods)
      Remove duplicates from method array.

      Duplicates will arise if a class/intf and super-class/intf define methods with the same signature. Potentially the throws clauses of the methods may be different (note Java requires that the superclass/intf method have a superset of the exceptions in the derived method).

      Parameters:
      methods -
      Returns:
      methods which can be generated in an interface