View Javadoc

    1   /***************************************************************************************
    2    * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved.                 *
    3    * http://aspectwerkz.codehaus.org                                                    *
    4    * ---------------------------------------------------------------------------------- *
    5    * The software in this package is published under the terms of the LGPL license      *
    6    * a copy of which has been included with this distribution in the license.txt file.  *
    7    **************************************************************************************/
    8   package org.codehaus.aspectwerkz.transform.inlining.spi;
    9
    10  import org.codehaus.aspectwerkz.reflect.ClassInfo;
    11  import org.codehaus.aspectwerkz.definition.AspectDefinition;
    12  import org.codehaus.aspectwerkz.transform.inlining.AdviceMethodInfo;
    13  import org.codehaus.aspectwerkz.transform.inlining.AspectInfo;
    14  import org.objectweb.asm.CodeVisitor;
    15  import org.objectweb.asm.ClassWriter;
    16
    17  /***
    18   * TODO document
    19   *
    20   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
    21   */
    22  public interface AspectModel {
    23      /***
    24       * Returns the aspect model type, which is an id for the the special aspect model, can be anything as long
    25       * as it is unique.
    26       *
    27       * @return the aspect model type id
    28       */
    29      String getAspectModelType();
    30
    31      /***
    32       * Defines the aspect and adds definition to the aspect definition.
    33       *
    34       * @param aspectClassInfo
    35       * @param aspectDef
    36       * @param loader
    37       */
    38      void defineAspect(ClassInfo aspectClassInfo, AspectDefinition aspectDef, ClassLoader loader);
    39
    40      /***
    41       * Returns info about the closure class, name and type (interface or class).
    42       *
    43       * @return the closure class info
    44       */
    45      AroundClosureClassInfo getAroundClosureClassInfo();
    46
    47      /***
    48       * Creates the methods required to implement or extend to implement the closure for the specific aspect model type.
    49       *
    50       * @param cw
    51       * @param className
    52       */
    53      void createMandatoryMethods(ClassWriter cw, String className);
    54
    55      /***
    56       * Creates invocation of the super class for the around closure.
    57       * <p/>
    58       * E.g. the invocation of super(..) in the constructor.
    59       * <p/>
    60       * Only needed to be implemented if the around closure base class is really a base class and not an interface.
    61       *
    62       * @param cv
    63       */
    64      void createInvocationOfAroundClosureSuperClass(CodeVisitor cv);
    65
    66      /***
    67       * Creates aspect reference field (field in the jit jointpoint class f.e.) for an aspect instance.
    68       *
    69       * @param cw
    70       * @param aspectInfo
    71       * @param joinPointClassName
    72       */
    73      void createAspectReferenceField(ClassWriter cw, AspectInfo aspectInfo, String joinPointClassName);
    74
    75      /***
    76       * Creates instantiation of an aspect instance.
    77       *
    78       * @param cv
    79       * @param aspectInfo
    80       * @param joinPointClassName
    81       */
    82      void createAspectInstantiation(CodeVisitor cv, AspectInfo aspectInfo, String joinPointClassName);
    83
    84      /***
    85       * Handles the arguments to the around advice.
    86       *
    87       * @param cv
    88       * @param adviceMethodInfo
    89       */
    90      void createAroundAdviceArgumentHandling(CodeVisitor cv, AdviceMethodInfo adviceMethodInfo);
    91
    92      /***
    93       * Handles the arguments to the after advice.
    94       *
    95       * @param cv
    96       * @param adviceMethodInfo
    97       */
    98      void createBeforeAdviceArgumentHandling(CodeVisitor cv, AdviceMethodInfo adviceMethodInfo);
    99
    100     /***
    101      * Handles the arguments to the after advice.
    102      *
    103      * @param cv
    104      * @param adviceMethodInfo
    105      */
    106     void createAfterAdviceArgumentHandling(CodeVisitor cv, AdviceMethodInfo adviceMethodInfo);
    107
    108     /***
    109      * Should return true if the aspect model requires that Runtime Type Information (RTTI) is build up
    110      * for the join point. Needed for reflective systems and systems that does not support f.e. args() binding.
    111      *
    112      * @return
    113      */
    114     boolean requiresReflectiveInfo();
    115
    116     /***
    117      * Info about the around closure class or interface for this specific aspect model.
    118      *
    119      * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
    120      */
    121     public static class AroundClosureClassInfo {
    122         private final String m_superClassName;
    123         private final String[] m_interfaceNames;
    124         public AroundClosureClassInfo(final String superClassName, final String[] interfaceNames) {
    125             m_superClassName = superClassName;
    126             m_interfaceNames = interfaceNames;
    127         }
    128
    129         public String getSuperClassName() {
    130             return m_superClassName;
    131         }
    132
    133         public String[] getInterfaceNames() {
    134             return m_interfaceNames;
    135         }
    136
    137         /***
    138          * Type safe enum for the around closure class type.
    139          */
    140         public static class Type {
    141             public static final Type INTERFACE = new Type("INTERFACE");
    142             public static final Type CLASS = new Type("CLASS");
    143             private final String m_name;
    144             private Type(String name) {
    145                 m_name = name;
    146             }
    147             public String toString() {
    148                 return m_name;
    149             }
    150         }
    151
    152     }
    153 }