01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.controls.runtime.generator;
20:
21: import java.util.HashMap;
22: import java.util.Map;
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: * Initialize a new helper instance based upon a specific annotation declaration.
35: * @param annot The annotation value declaration
36: */
37: public AptAnnotationHelper(AnnotationMirror annot) {
38: //
39: // Build maps from the element name to its declaration and values
40: //
41: Map<AnnotationTypeElementDeclaration, AnnotationValue> elemValues = annot
42: .getElementValues();
43:
44: for (AnnotationTypeElementDeclaration ated : elemValues
45: .keySet()) {
46: _elementMap.put(ated.getSimpleName(), ated);
47: _valueMap.put(ated.getSimpleName(), elemValues.get(ated));
48: }
49: };
50:
51: /**
52: * Returns the AnnotationTypeElementDeclaration for a particular element
53: */
54: public AnnotationTypeElementDeclaration getElementDeclaration(
55: String elemName) {
56: if (_elementMap.containsKey(elemName))
57: return _elementMap.get(elemName);
58: return null;
59: }
60:
61: /**
62: * Returns the value of a particular element as a String
63: */
64: public String getStringValue(String elemName) {
65: if (_valueMap.containsKey(elemName))
66: return _valueMap.get(elemName).toString();
67: return null;
68: }
69:
70: /**
71: * Returns the value of a particular element as an Object
72: */
73: public Object getObjectValue(String elemName) {
74: if (_valueMap.containsKey(elemName))
75: return _valueMap.get(elemName).getValue();
76: return null;
77: }
78:
79: private HashMap<String, AnnotationTypeElementDeclaration> _elementMap = new HashMap<String, AnnotationTypeElementDeclaration>();
80: private HashMap<String, AnnotationValue> _valueMap = new HashMap<String, AnnotationValue>();
81: }
|