1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.apache.commons.classscan.bcel;
15
16 import java.util.Set;
17
18 import org.apache.bcel.classfile.AnnotationEntry;
19 import org.apache.bcel.classfile.ElementValuePair;
20 import org.apache.commons.classscan.builtin.ClassNameHelper;
21 import org.apache.commons.classscan.spi.model.SpiMetaAnnotation;
22 import org.apache.commons.classscan.spi.model.SpiMetaClassLoader;
23 import org.apache.commons.classscan.util.NameSet;
24
25 public class BcelAnnotation implements SpiMetaAnnotation {
26
27 private final String name;
28 private final NameSet<SpiProperty> properties;
29
30 public BcelAnnotation(AnnotationEntry annotation) {
31 name = ClassNameHelper.internalToCanonicalName(annotation.getAnnotationType());
32
33 ElementValuePair[] elementValuePairs = annotation.getElementValuePairs();
34 if (elementValuePairs.length == 0) {
35 properties = NameSet.emptyNameSet();
36 }
37 else {
38 properties = new NameSet<SpiProperty>(fillMapAndArray(elementValuePairs));
39 }
40 }
41
42 @Override
43 public boolean resolve(SpiMetaClassLoader classLoader) {
44 return properties.resolve(classLoader);
45 }
46
47 private SpiProperty[] fillMapAndArray(ElementValuePair[] evPairs) {
48 SpiProperty[] values = new SpiProperty[evPairs.length];
49 for (int i = 0; i < evPairs.length; ++i) {
50 values[i] = new BcelProperty(evPairs[i]);
51 }
52 return values;
53 }
54
55 @Override
56 public String getName() {
57 return name;
58 }
59
60 @Override
61 public Set<? extends Property> getProperties() {
62 return properties;
63 }
64
65 @Override
66 public Property getProperty(String propertyName) {
67 return properties.getValue(propertyName);
68 }
69 }