View Javadoc
1   /*
2    * Copyright 2009 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.castor.core.annotationprocessing;
17  
18  import java.lang.annotation.Annotation;
19  import java.lang.reflect.AnnotatedElement;
20  import java.util.Set;
21  
22  import org.castor.core.nature.BaseNature;
23  import org.castor.core.nature.PropertyHolder;
24  
25  /**
26   * Extension of {@link AnnotationProcessingService} to handle target-aware 
27   * {@link Annotation}s.
28   * 
29   * @see AnnotationProcessingService
30   * @author Alexander Eibner, Peter Schmidt
31   * @since 1.3.1
32   */
33  public interface TargetAwareAnnotationProcessingService extends
34          AnnotationProcessingService {
35  
36      /**
37       * Calls {@link #processAnnotation(BaseNature, Annotation)} for each given
38       * Annotation.
39       * 
40       * @param info
41       *            the {@link BaseNature} (and so its {@link PropertyHolder})
42       *            that should be filled with the information read
43       * @param annotations
44       *            the annotations to process
45       * @param target
46       *            the target ({@link AnnotatedElement}) of the given annotation
47       * @return Annotation[] filled with unprocessed annotations
48       * @throws AnnotationTargetException
49       *             if an annotation is used in a context that is not valid.
50       * @see #processAnnotation(BaseNature, Annotation)
51       */
52      public abstract <I extends BaseNature> Annotation[] processAnnotations(
53              I info, final Annotation[] annotations,
54              final AnnotatedElement target) throws AnnotationTargetException;
55  
56      /**
57       * The processing action of this service. If an annotation is given which is
58       * not supported by this processor false is returned. Otherwise the
59       * Annotations specific processor will (try to) process the Annotation and
60       * the result of
61       * {@link TargetAwareAnnotationProcessor#processAnnotation(BaseNature, Annotation, AnnotatedElement)}
62       * is returned.
63       * 
64       * @param info
65       *            the {@link BaseNature} (and so its {@link PropertyHolder})
66       *            that should be filled with the information read
67       * @param annotation
68       *            the annotation to process
69       * @param target
70       *            the target ({@link AnnotatedElement}) of the given annotation
71       * @return true, if the annotation was processed, false if not
72       * @throws AnnotationTargetException
73       *             if an annotation is used in a context that is not valid.
74       * @see TargetAwareAnnotationProcessor
75       */
76      public <I extends BaseNature, A extends Annotation> boolean processAnnotation(
77              I info, final A annotation, final AnnotatedElement target)
78              throws AnnotationTargetException;
79  
80      /**
81       * Add an {@link TargetAwareAnnotationProcessor} to the service.
82       * 
83       * @param annotationProcessor
84       *            the {@link TargetAwareAnnotationProcessor} to add to this
85       *            service.
86       */
87      public void addAnnotationProcessor(
88              final TargetAwareAnnotationProcessor annotationProcessor);
89  
90      /**
91       * Returns the set of {@link TargetAwareAnnotationProcessor}s registered
92       * with this service.
93       * 
94       * @return A set of {@link TargetAwareAnnotationProcessor}s registered with
95       *         this service.
96       */
97      public Set<TargetAwareAnnotationProcessor> getTargetAwareAnnotationProcessors();
98  
99      /**
100      * Returns the set of {@link AnnotationProcessor}s and
101      * {@link TargetAwareAnnotationProcessor}s registered with this service.
102      * 
103      * @return A set of {@link AnnotationProcessor}s registered with this
104      *         service.
105      */
106     public Set<AnnotationProcessor> getAllAnnotationProcessors();
107 
108 }