com.caucho.config.gen
Class AbstractAspectGenerator<X>

java.lang.Object
  extended by com.caucho.config.gen.AbstractAspectGenerator<X>
All Implemented Interfaces:
AspectGenerator<X>
Direct Known Subclasses:
AsyncHeadGenerator, CacheGenerator, InterceptorGenerator, LockGenerator, MethodHeadGenerator, SecurityGenerator, StatelessScheduledMethodHeadGenerator, XaGenerator

@Module
public abstract class AbstractAspectGenerator<X>
extends java.lang.Object
implements AspectGenerator<X>

Represents a filter for invoking a method


Constructor Summary
protected AbstractAspectGenerator(AspectFactory<X> factory, AnnotatedMethod<? super X> method, AspectGenerator<X> next)
           
 
Method Summary
 void generate(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> prologueMap)
          Top-level generator.
 void generateApplicationException(JavaWriter out, java.lang.Class<?> exn)
          Generates application (checked) exception code for the method.
 void generateAsync(JavaWriter out)
          Generates pre-async dispatch code.
 void generateBeanConstructor(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates initialization in the constructor
 void generateBeanPrologue(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates the static class prologue
 void generateCall(JavaWriter out)
          Generates the method interception code
protected  void generateContent(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates the body of the method.
 void generateDestroy(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates destroy code
 void generateEpilogue(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates epilogue
 void generateFinally(JavaWriter out)
          Generates finally code for the method
 void generateInject(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates extra inject code
 void generateMethodPrologue(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates the static class prologue
 void generatePostCall(JavaWriter out)
          Generates code after the call, before the return.
 void generatePostConstruct(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates @PostConstruct code
 void generatePostFinally(JavaWriter out)
          Generates finally code for the method
 void generatePreCall(JavaWriter out)
          Generates code before the call, in the try block.
 void generatePreDestroy(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates @PreDestroy code
 void generatePreTry(JavaWriter out)
          Generates code before the try block
 void generateProxyConstructor(JavaWriter out, java.util.HashMap<java.lang.String,java.lang.Object> map)
          Generates initialization in the proxy constructor
 void generateSystemException(JavaWriter out, java.lang.Class<?> exn)
          Generates system (runtime) exception code for the method.
protected
<Z extends java.lang.annotation.Annotation>
Z
getAnnotation(java.lang.Class<Z> annotationType, AnnotatedMethod<?> apiMethod, AnnotatedMethod<?> implMethod)
           
protected
<Z extends java.lang.annotation.Annotation>
Z
getAnnotation(java.lang.Class<Z> annotationType, AnnotatedMethod<?> apiMethod, AnnotatedType<?> apiClass, AnnotatedMethod<?> implementationMethod, AnnotatedType<?> implementationClass)
           
protected
<Z extends java.lang.annotation.Annotation>
Z
getAnnotation(java.lang.Class<Z> annotationType, AnnotatedType<?> apiClass, AnnotatedType<?> implClass)
           
protected  AspectBeanFactory<X> getBeanFactory()
           
protected  AnnotatedType<X> getBeanType()
          Returns the owning bean type.
protected  AspectFactory<X> getFactory()
           
protected  java.lang.Class<X> getJavaClass()
           
protected  java.lang.reflect.Method getJavaMethod()
          Returns the JavaMethod for this aspect.
 AnnotatedMethod<? super X> getMethod()
          Returns the underlying method.
protected  java.lang.Class<?>[] getThrowsExceptions()
           
protected  java.util.Set<VarType<?>> getTypeVariables()
           
 boolean isApplicationExceptionThrown()
          Returns true if the application exception can be thrown.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractAspectGenerator

protected AbstractAspectGenerator(AspectFactory<X> factory,
                                  AnnotatedMethod<? super X> method,
                                  AspectGenerator<X> next)
Method Detail

getFactory

protected AspectFactory<X> getFactory()

getBeanFactory

protected AspectBeanFactory<X> getBeanFactory()

getBeanType

protected AnnotatedType<X> getBeanType()
Returns the owning bean type.


getJavaClass

protected java.lang.Class<X> getJavaClass()

getMethod

public AnnotatedMethod<? super X> getMethod()
Description copied from interface: AspectGenerator
Returns the underlying method.

Specified by:
getMethod in interface AspectGenerator<X>

getTypeVariables

protected java.util.Set<VarType<?>> getTypeVariables()

getJavaMethod

protected java.lang.reflect.Method getJavaMethod()
Returns the JavaMethod for this aspect.


generate

public void generate(JavaWriter out,
                     java.util.HashMap<java.lang.String,java.lang.Object> prologueMap)
              throws java.io.IOException
Top-level generator.

Specified by:
generate in interface AspectGenerator<X>
Throws:
java.io.IOException

generateContent

protected void generateContent(JavaWriter out,
                               java.util.HashMap<java.lang.String,java.lang.Object> map)
                        throws java.io.IOException
Generates the body of the method.
 MyType myMethod(...)
 {
   [pre-try]
   try {
     [pre-call]
     [call]   // retValue = super.myMethod(...)
     [post-call]
     return retValue;
   } catch (RuntimeException e) {
     [system-exception]
     throw e;
   } catch (Exception e) {
     [application-exception]
     throw e;
   } finally {
     [finally]
   }
 

Throws:
java.io.IOException

getThrowsExceptions

protected java.lang.Class<?>[] getThrowsExceptions()

generateBeanPrologue

public void generateBeanPrologue(JavaWriter out,
                                 java.util.HashMap<java.lang.String,java.lang.Object> map)
                          throws java.io.IOException
Generates the static class prologue

Specified by:
generateBeanPrologue in interface AspectGenerator<X>
Throws:
java.io.IOException

generateBeanConstructor

public void generateBeanConstructor(JavaWriter out,
                                    java.util.HashMap<java.lang.String,java.lang.Object> map)
                             throws java.io.IOException
Generates initialization in the constructor

Specified by:
generateBeanConstructor in interface AspectGenerator<X>
Throws:
java.io.IOException

generateProxyConstructor

public void generateProxyConstructor(JavaWriter out,
                                     java.util.HashMap<java.lang.String,java.lang.Object> map)
                              throws java.io.IOException
Generates initialization in the proxy constructor

Specified by:
generateProxyConstructor in interface AspectGenerator<X>
Throws:
java.io.IOException

generateInject

public void generateInject(JavaWriter out,
                           java.util.HashMap<java.lang.String,java.lang.Object> map)
                    throws java.io.IOException
Generates extra inject code

Specified by:
generateInject in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePostConstruct

public void generatePostConstruct(JavaWriter out,
                                  java.util.HashMap<java.lang.String,java.lang.Object> map)
                           throws java.io.IOException
Generates @PostConstruct code

Specified by:
generatePostConstruct in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePreDestroy

public void generatePreDestroy(JavaWriter out,
                               java.util.HashMap<java.lang.String,java.lang.Object> map)
                        throws java.io.IOException
Generates @PreDestroy code

Specified by:
generatePreDestroy in interface AspectGenerator<X>
Throws:
java.io.IOException

generateEpilogue

public void generateEpilogue(JavaWriter out,
                             java.util.HashMap<java.lang.String,java.lang.Object> map)
                      throws java.io.IOException
Generates epilogue

Specified by:
generateEpilogue in interface AspectGenerator<X>
Throws:
java.io.IOException

generateDestroy

public void generateDestroy(JavaWriter out,
                            java.util.HashMap<java.lang.String,java.lang.Object> map)
                     throws java.io.IOException
Generates destroy code

Specified by:
generateDestroy in interface AspectGenerator<X>
Throws:
java.io.IOException

generateMethodPrologue

public void generateMethodPrologue(JavaWriter out,
                                   java.util.HashMap<java.lang.String,java.lang.Object> map)
                            throws java.io.IOException
Generates the static class prologue

Specified by:
generateMethodPrologue in interface AspectGenerator<X>
Throws:
java.io.IOException

generateAsync

public void generateAsync(JavaWriter out)
                   throws java.io.IOException
Generates pre-async dispatch code.

Specified by:
generateAsync in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePreTry

public void generatePreTry(JavaWriter out)
                    throws java.io.IOException
Generates code before the try block

Specified by:
generatePreTry in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePreCall

public void generatePreCall(JavaWriter out)
                     throws java.io.IOException
Generates code before the call, in the try block.
 retType myMethod(...)
 {
   try {
     [pre-call]
     value = bean.myMethod(...);
     ...
 }
 

Specified by:
generatePreCall in interface AspectGenerator<X>
Throws:
java.io.IOException

generateCall

public void generateCall(JavaWriter out)
                  throws java.io.IOException
Generates the method interception code

Specified by:
generateCall in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePostCall

public void generatePostCall(JavaWriter out)
                      throws java.io.IOException
Generates code after the call, before the return.
 retType myMethod(...)
 {
   try {
     ...
     value = bean.myMethod(...);
     [post-call]
     return value;
   } finally {
     ...
   }
 }
 

Specified by:
generatePostCall in interface AspectGenerator<X>
Throws:
java.io.IOException

isApplicationExceptionThrown

public boolean isApplicationExceptionThrown()
Returns true if the application exception can be thrown.

Specified by:
isApplicationExceptionThrown in interface AspectGenerator<X>

generateApplicationException

public void generateApplicationException(JavaWriter out,
                                         java.lang.Class<?> exn)
                                  throws java.io.IOException
Generates application (checked) exception code for the method.

Specified by:
generateApplicationException in interface AspectGenerator<X>
Throws:
java.io.IOException

generateSystemException

public void generateSystemException(JavaWriter out,
                                    java.lang.Class<?> exn)
                             throws java.io.IOException
Generates system (runtime) exception code for the method.

Specified by:
generateSystemException in interface AspectGenerator<X>
Throws:
java.io.IOException

generateFinally

public void generateFinally(JavaWriter out)
                     throws java.io.IOException
Generates finally code for the method

Specified by:
generateFinally in interface AspectGenerator<X>
Throws:
java.io.IOException

generatePostFinally

public void generatePostFinally(JavaWriter out)
                         throws java.io.IOException
Description copied from interface: AspectGenerator
Generates finally code for the method
 retType myMethod(...)
 {
   try {
     ...
     value = bean.myMethod(...);
     ...
     return value;
   } finally {
     ...
   }
   [post-finally]
 }
 

Specified by:
generatePostFinally in interface AspectGenerator<X>
Throws:
java.io.IOException

getAnnotation

protected <Z extends java.lang.annotation.Annotation> Z getAnnotation(java.lang.Class<Z> annotationType,
                                                                      AnnotatedMethod<?> apiMethod,
                                                                      AnnotatedMethod<?> implMethod)

getAnnotation

protected <Z extends java.lang.annotation.Annotation> Z getAnnotation(java.lang.Class<Z> annotationType,
                                                                      AnnotatedType<?> apiClass,
                                                                      AnnotatedType<?> implClass)

getAnnotation

protected <Z extends java.lang.annotation.Annotation> Z getAnnotation(java.lang.Class<Z> annotationType,
                                                                      AnnotatedMethod<?> apiMethod,
                                                                      AnnotatedType<?> apiClass,
                                                                      AnnotatedMethod<?> implementationMethod,
                                                                      AnnotatedType<?> implementationClass)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object