KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > AptAnnotationHelper


1 package org.apache.beehive.controls.runtime.generator;
2
3 /*
4  * Copyright 2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Header:$
19  */

20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import com.sun.mirror.declaration.AnnotationMirror;
25 import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
26 import com.sun.mirror.declaration.AnnotationValue;
27
28 /**
29  * The AptAnnotationHelper class is a helper class that aids in the reading of annotation
30  * values using APT metadata
31  */

32 public class AptAnnotationHelper
33 {
34     /**
35      * Initialize a new helper instance based upon a specific annotation declaration.
36      * @param annot The annotation value declaration
37      */

38     public AptAnnotationHelper(AnnotationMirror annot)
39     {
40         //
41
// Build maps from the element name to its declaration and values
42
//
43
Map JavaDoc <AnnotationTypeElementDeclaration,AnnotationValue> elemValues =
44             annot.getElementValues();
45
46         for (AnnotationTypeElementDeclaration ated : elemValues.keySet())
47         {
48             _elementMap.put(ated.getSimpleName(), ated);
49             _valueMap.put(ated.getSimpleName(), elemValues.get(ated));
50         }
51     };
52
53     /**
54      * Returns the AnnotationTypeElementDeclaration for a particular element
55      */

56     public AnnotationTypeElementDeclaration getElementDeclaration(String JavaDoc elemName)
57     {
58         if (_elementMap.containsKey(elemName))
59             return _elementMap.get(elemName);
60         return null;
61     }
62
63     /**
64      * Returns the value of a particular element as a String
65      */

66     public String JavaDoc getStringValue(String JavaDoc elemName)
67     {
68         if (_valueMap.containsKey(elemName))
69             return _valueMap.get(elemName).toString();
70         return null;
71     }
72
73     /**
74      * Returns the value of a particular element as an Object
75      */

76     public Object JavaDoc getObjectValue(String JavaDoc elemName)
77     {
78         if (_valueMap.containsKey(elemName))
79             return _valueMap.get(elemName).getValue();
80         return null;
81     }
82
83     private HashMap JavaDoc<String JavaDoc,AnnotationTypeElementDeclaration> _elementMap =
84                 new HashMap JavaDoc<String JavaDoc,AnnotationTypeElementDeclaration>();
85     private HashMap JavaDoc<String JavaDoc,AnnotationValue> _valueMap =
86                 new HashMap JavaDoc<String JavaDoc,AnnotationValue>();
87 }
88
Popular Tags