View Javadoc

1   /**
2    * - Digitalis Internal Framework v2.0 - (C) 2007, Digitalis Informatica. Distribuicao e Gestao de Informatica, Lda.
3    * Estrada de Paco de Arcos num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999
4    * http://www.digitalis.pt
5    */
6   package pt.digitalis.dif.codegen.util;
7   
8   import pt.digitalis.dif.dem.DEMAnnotationLogic;
9   import pt.digitalis.dif.exception.codegen.AnnotationMisuseException;
10  import pt.digitalis.dif.exception.codegen.DIFCodeGenerationException;
11  import pt.digitalis.dif.utils.annotations.Contribution;
12  import pt.digitalis.utils.bytecode.exceptions.CodeGenerationException;
13  import pt.digitalis.utils.bytecode.holders.AnnotationHolder;
14  import pt.digitalis.utils.bytecode.holders.AttributeHolder;
15  import pt.digitalis.utils.bytecode.holders.ClassHolder;
16  import pt.digitalis.utils.bytecode.holders.MethodHolder;
17  import pt.digitalis.utils.inspection.exception.ResourceNotFoundException;
18  
19  /**
20   * Defines the basic behavior that any DIF class enhancer must implement.
21   * 
22   * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a>
23   * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a>
24   * @created Jul 23, 2007
25   */
26  @Contribution
27  public interface IClassEnhancer {
28  
29      /**
30       * Enhances a given class.
31       * 
32       * @param clazz
33       *            the class to enhance.
34       * @return the entity class for DEMRegistry addition
35       * @throws ResourceNotFoundException
36       *             if the class could not be loaded
37       * @throws CodeGenerationException
38       *             if class could not be enhanced
39       * @throws AnnotationMisuseException
40       *             if an inappropriate annotation use was made
41       * @throws DIFCodeGenerationException
42       */
43      public ClassHolder enhance(ClassHolder clazz) throws ResourceNotFoundException, CodeGenerationException,
44              AnnotationMisuseException, DIFCodeGenerationException;
45  
46      /**
47       * Processes a given type-targeted annotation, enhancing the class with bytecode generated accordingly to the
48       * annotation.
49       * 
50       * @param classEnhancementContext
51       *            the class enhancement context
52       * @param annotation
53       *            the annotation used to choose the appropriate code enhancement
54       * @param annotationLogic
55       *            the annotationLogic class implementation
56       * @throws ResourceNotFoundException
57       *             if any need resource can't be found or loaded
58       * @throws CodeGenerationException
59       *             if source code can not be compiled or appended to class
60       * @throws DIFCodeGenerationException
61       */
62      public void processAnnotation(ClassEnhancementContext classEnhancementContext, AnnotationHolder annotation,
63              DEMAnnotationLogic annotationLogic) throws ResourceNotFoundException, CodeGenerationException,
64              DIFCodeGenerationException;
65  
66      /**
67       * Processes a given field-targeted annotation, enhancing the class with bytecode generated accordingly to the
68       * annotation.
69       * 
70       * @param classEnhancementContext
71       *            the class enhancement context
72       * @param attribute
73       *            annotated attribute
74       * @param annotation
75       *            the annotation used to choose the appropriate code enhancement
76       * @param annotationLogic
77       *            the annotationLogic class implementation
78       * @throws ResourceNotFoundException
79       *             if any need resource can't be found or loaded
80       * @throws CodeGenerationException
81       *             if source code can not be compiled or appended to class
82       * @throws DIFCodeGenerationException
83       */
84      public void processAnnotation(ClassEnhancementContext classEnhancementContext, AttributeHolder attribute,
85              AnnotationHolder annotation, DEMAnnotationLogic annotationLogic) throws ResourceNotFoundException,
86              CodeGenerationException, DIFCodeGenerationException;
87  
88      /**
89       * Processes a given method-targeted annotation, enhancing the class with bytecode generated accordingly to the
90       * annotation.
91       * 
92       * @param classEnhancementContext
93       *            the class enhancement context
94       * @param method
95       *            annotated method
96       * @param annotation
97       *            the annotation used to choose the appropriate code enhancement
98       * @param annotationLogic
99       *            the annotationLogic class implementation
100      * @throws ResourceNotFoundException
101      *             if any need resource can't be found or loaded
102      * @throws CodeGenerationException
103      *             if source code can not be compiled or appended to class
104      * @throws DIFCodeGenerationException
105      */
106     public void processAnnotation(ClassEnhancementContext classEnhancementContext, MethodHolder method,
107             AnnotationHolder annotation, DEMAnnotationLogic annotationLogic) throws ResourceNotFoundException,
108             CodeGenerationException, DIFCodeGenerationException;
109 }