View Javadoc
1   /*
2    * Copyright 2007 Joachim Grueneis
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.castor.core.annotationprocessing;
15  
16  import java.lang.annotation.Annotation;
17  import java.util.Set;
18  
19  import org.castor.core.nature.BaseNature;
20  import org.castor.core.nature.PropertyHolder;
21  
22  /**
23   * An AnnotationProcessingService handles multiple {@link AnnotationProcessor}s and uses them to
24   * process one or more {@link Annotation}s.
25   * 
26   * @see AnnotationProcessor
27   * @author Alexander Eibner, Peter Schmidt, Joachim Grueneis
28   * @since 1.3
29   */
30  public interface AnnotationProcessingService {
31  
32    /**
33     * Calls {@link #processAnnotation(BaseNature, Annotation)} for each given Annotation.
34     * 
35     * @param info the {@link BaseNature} (and so its {@link PropertyHolder}) that should be filled
36     *        with the information read
37     * @param annotations the annotations to process
38     * @return Annotation[] filled with unprocessed annotations
39     * @see #processAnnotation(BaseNature, Annotation)
40     */
41    public abstract <I extends BaseNature> Annotation[] processAnnotations(I info,
42        final Annotation[] annotations);
43  
44    /**
45     * The processing action of this service. If an annotation is given which is not supported by this
46     * processor false is returned. Otherwise the Annotations specific processor will (try to) process
47     * the Annotation and the result of
48     * {@link AnnotationProcessor#processAnnotation(BaseNature, Annotation)} is returned.
49     * 
50     * @param info the {@link BaseNature} (and so its {@link PropertyHolder}) that should be filled
51     *        with the information read
52     * @param annotation the annotation to process
53     * @return true, if the annotation was processed, false if not
54     * @see AnnotationProcessor
55     */
56    public <I extends BaseNature, A extends Annotation> boolean processAnnotation(I info,
57        final A annotation);
58  
59    /**
60     * Add an {@link AnnotationProcessor} to the service.
61     * 
62     * @param annotationProcessor the {@link AnnotationProcessor} to add to this service.
63     */
64    public void addAnnotationProcessor(final AnnotationProcessor annotationProcessor);
65  
66    /**
67     * Returns the set of {@link AnnotationProcessor}s registered with this service.
68     * 
69     * @return A set of {@link AnnotationProcessor}s registered with this service.
70     */
71    public Set<AnnotationProcessor> getAnnotationProcessors();
72  
73  }