aQute.bnd.osgi.Annotation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bnd Show documentation
Show all versions of bnd Show documentation
A command line utility and Ant plugin to wrap, build, or examine bundles.
package aQute.bnd.osgi;
import java.lang.annotation.*;
import java.util.*;
import aQute.bnd.annotation.metatype.*;
import aQute.bnd.osgi.Descriptors.TypeRef;
public class Annotation {
private TypeRef name;
private Map elements;
private ElementType member;
private RetentionPolicy policy;
public Annotation(TypeRef name, Map elements, ElementType member, RetentionPolicy policy) {
this.name = name;
if (elements == null)
this.elements = null;
else
this.elements = elements;
this.member = member;
this.policy = policy;
}
public TypeRef getName() {
return name;
}
public ElementType getElementType() {
return member;
}
public RetentionPolicy getRetentionPolicy() {
return policy;
}
@Override
public String toString() {
return name + ":" + member + ":" + policy + ":" + (elements == null ? "{}" : elements);
}
public T get(String string) {
if (elements == null)
return null;
return (T) elements.get(string);
}
public void put(String string, Object v) {
if (elements == null)
elements = new LinkedHashMap();
elements.put(string, v);
}
public Set keySet() {
if (elements == null)
return Collections.emptySet();
return elements.keySet();
}
public T getAnnotation() throws Exception {
String cname = name.getFQN();
try {
Class c = (Class) getClass().getClassLoader().loadClass(cname);
return getAnnotation(c);
}
catch (ClassNotFoundException e) {
}
catch (NoClassDefFoundError e) {
}
return null;
}
public T getAnnotation(Class c) throws Exception {
String cname = name.getFQN();
if (!c.getName().equals(cname))
return null;
return Configurable.createConfigurable(c, elements == null ? elements=new LinkedHashMap() : elements);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy