FELIX-1010: Use qdox to read annotations; get default values by using reflection.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@765177 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 5810d8c..a4247c4 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -58,11 +58,11 @@
</dependency>
<dependency>
- <groupId>asm</groupId>
- <artifactId>asm-all</artifactId>
- <version>3.0</version>
+ <groupId>asm</groupId>
+ <artifactId>asm-all</artifactId>
+ <version>3.1</version>
</dependency>
-
+
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index 55e41a3..a8e4a73 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -534,6 +534,8 @@
if (StringUtils.isEmpty(type)) {
if ( reference.getField() != null ) {
type = reference.getField().getType();
+ } else {
+ throw new MojoExecutionException("Interface missing for reference " + refName + " in class " + reference.getJavaClassDescription().getName());
}
} else if ( isInspectedClass ) {
// check if the value points to a class/interface
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
index 496c00f..e774483 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/ClassUtil.java
@@ -26,13 +26,15 @@
*/
public class ClassUtil {
+ public static ClassLoader classLoader;
+
/**
* Try to get the initial value of a static field
* @param clazz The class.
* @param fieldName The name of the field.
* @return The initial value or null.
*/
- public static String[] getInitializationExpression(Class clazz, String fieldName) {
+ public static String[] getInitializationExpression(Class<?> clazz, String fieldName) {
try {
final Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
@@ -55,4 +57,21 @@
}
return null;
}
+
+ /**
+ * Get the compiled class.
+ */
+ public static Class<?> getClass(String name) {
+ if ( classLoader == null ) {
+ return null;
+ }
+ try {
+ if ( name.endsWith(".class") ) {
+ name = name.substring(0, name.length() - 6);
+ }
+ return classLoader.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ }
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
index aeefe9b..d6480ee 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescriptorManager.java
@@ -105,6 +105,7 @@
this.project = project;
this.annotationTagProviderManager = new AnnotationTagProviderManager(annotationTagProviders);
this.classloader = this.getCompileClassLoader();
+ ClassUtil.classLoader = this.classloader;
// get all the class sources through qdox
this.log.debug("Setting up QDox");
@@ -302,6 +303,25 @@
return list;
}
+ /**
+ * Get the url for the target directory
+ */
+ protected URL getOutputDirectory()
+ throws MojoFailureException {
+ final String targetDirectory = this.getProject().getBuild().getOutputDirectory();
+ try {
+ return new File(targetDirectory).toURI().toURL();
+ } catch (IOException ioe) {
+ throw new MojoFailureException("Unable to add target directory to classloader.");
+ }
+ }
+
+ /**
+ * Create a class loader containing all compile artifacts including
+ * the target/class directory of the current project
+ * @return The class loader
+ * @throws MojoFailureException
+ */
protected ClassLoader getCompileClassLoader()
throws MojoFailureException {
@SuppressWarnings("unchecked")
@@ -316,12 +336,8 @@
throw new MojoFailureException("Unable to get compile class loader.");
}
}
- final String targetDirectory = this.getProject().getBuild().getOutputDirectory();
- try {
- path[path.length - 1] = new File(targetDirectory).toURI().toURL();
- } catch (IOException ioe) {
- throw new MojoFailureException("Unable to add target directory to classloader.");
- }
+ path[path.length - 1] = this.getOutputDirectory();
+
return new URLClassLoader(path, this.getClass().getClassLoader());
}
@@ -397,7 +413,7 @@
if ( javaClass.getFullyQualifiedName().equals(className) ) {
try {
// check for java annotation descriptions - fallback to QDox if none found
- Class clazz = this.classloader.loadClass(className);
+ Class<?> clazz = this.classloader.loadClass(className);
if (this.processAnnotations && getAnnotationTagProviderManager().hasScrPluginAnnotation(javaClass)) {
this.log.debug("Found java annotation description for: " + className);
result = new AnnotationJavaClassDescription(clazz, this.sources[index], this);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
index a74d16d..5a17a05 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaClassDescription.java
@@ -19,7 +19,6 @@
package org.apache.felix.scrplugin.tags.annotation;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
import java.util.*;
import org.apache.felix.scrplugin.tags.*;
@@ -40,7 +39,7 @@
* @param source QDox source
* @param manager description manager
*/
- public AnnotationJavaClassDescription(Class clazz, JavaSource source, JavaClassDescriptorManager manager) {
+ public AnnotationJavaClassDescription(Class<?> clazz, JavaSource source, JavaClassDescriptorManager manager) {
super(clazz, source, manager);
}
@@ -84,6 +83,14 @@
}
}
}
+ for(com.thoughtworks.qdox.model.Annotation annotation : this.javaClass.getAnnotations()) {
+ List<JavaTag> annotationTags = manager.getAnnotationTagProviderManager().getTags(annotation, this);
+ for (JavaTag tag : annotationTags) {
+ if (tag.getName().equals(name)) {
+ tags.add(tag);
+ }
+ }
+ }
if (inherited && this.getSuperClass() != null) {
final JavaTag[] superTags = this.getSuperClass().getTagsByName(name, inherited);
@@ -100,7 +107,10 @@
*/
@Override
public JavaField[] getFields() {
- final Field[] fields = this.clazz.getDeclaredFields();
+ final com.thoughtworks.qdox.model.JavaField fields[] = this.javaClass.getFields();
+ if ( fields == null || fields.length == 0 ) {
+ return new JavaField[0];
+ }
final JavaField[] javaFields = new JavaField[fields.length];
for (int i = 0; i < fields.length; i++) {
javaFields[i] = new AnnotationJavaField(fields[i], this);
@@ -113,14 +123,7 @@
*/
@Override
public JavaField getFieldByName(String name) throws MojoExecutionException {
- Field field = null;
- try {
- field = this.clazz.getField(name);
- } catch (SecurityException e) {
- // ignore
- } catch (NoSuchFieldException e) {
- // ignore
- }
+ final com.thoughtworks.qdox.model.JavaField field = this.javaClass.getFieldByName(name);
if (field != null) {
return new AnnotationJavaField(field, this);
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java
index d2edabc..d4d40ea 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationJavaField.java
@@ -18,20 +18,16 @@
*/
package org.apache.felix.scrplugin.tags.annotation;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
import java.util.List;
-import org.apache.felix.scrplugin.tags.ClassUtil;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.*;
/**
* Description of a java field
*/
public class AnnotationJavaField implements JavaField {
- protected final Field field;
+ protected final com.thoughtworks.qdox.model.JavaField field;
protected final AnnotationJavaClassDescription description;
@@ -39,7 +35,7 @@
* @param field Field
* @param description description
*/
- public AnnotationJavaField(Field field, AnnotationJavaClassDescription description) {
+ public AnnotationJavaField(com.thoughtworks.qdox.model.JavaField field, AnnotationJavaClassDescription description) {
this.field = field;
this.description = description;
}
@@ -62,16 +58,15 @@
* @see JavaField#getTagByName(String)
*/
public JavaTag getTagByName(String name) {
- for (Annotation annotation : this.field.getAnnotations()) {
- List<JavaTag> tags = description.getManager().getAnnotationTagProviderManager().getTags(annotation,
- this.description, this);
+ for(com.thoughtworks.qdox.model.Annotation annotation : this.field.getAnnotations()) {
+ List<JavaTag> tags = description.getManager().getAnnotationTagProviderManager().getTags(annotation, this.description, this);
for (JavaTag tag : tags) {
if (tag.getName().equals(name)) {
return tag;
}
-
}
}
+
return null;
}
@@ -79,7 +74,7 @@
* @see JavaField#getType()
*/
public String getType() {
- return this.field.getType().getName();
+ return this.field.getType().getValue();
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java
index 0083367..943c62d 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/AnnotationTagProviderManager.java
@@ -56,7 +56,7 @@
// add custom providers defined in pom
for (int i = 0; i < annotationTagProviderClasses.length; i++) {
try {
- Class clazz = Class.forName(annotationTagProviderClasses[i]);
+ Class<?> clazz = Class.forName(annotationTagProviderClasses[i]);
try {
annotationTagProviders.add((AnnotationTagProvider) clazz.newInstance());
} catch (ClassCastException e) {
@@ -140,7 +140,7 @@
* @param pClass Class
* @return true if SCR plugin java annotation found
*/
- public boolean hasScrPluginAnnotation(Class pClass) {
+ public boolean hasScrPluginAnnotation(Class<?> pClass) {
for (Annotation annotation : pClass.getAnnotations()) {
if (getTags(annotation, null).size() > 0) {
return true;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
index 6352043..5817b69 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
@@ -52,47 +52,47 @@
this.annotation = new Component() {
public boolean componentAbstract() {
- return Util.getValue(annotation, "componentAbstract", false);
+ return Util.getBooleanValue(annotation, "componentAbstract", Component.class);
}
public boolean createPid() {
- return Util.getValue(annotation, "createPid", true);
+ return Util.getBooleanValue(annotation, "createPid", Component.class);
}
public String description() {
- return Util.getValue(annotation, "description", "");
+ return Util.getStringValue(annotation, "description", Component.class);
}
public boolean ds() {
- return Util.getValue(annotation, "ds", true);
+ return Util.getBooleanValue(annotation, "ds", Component.class);
}
public boolean enabled() {
- return Util.getValue(annotation, "enabled", true);
+ return Util.getBooleanValue(annotation, "enabled", Component.class);
}
public String factory() {
- return Util.getValue(annotation, "factory", "");
+ return Util.getStringValue(annotation, "factory", Component.class);
}
public boolean immediate() {
- return Util.getValue(annotation, "immediate", false);
+ return Util.getBooleanValue(annotation, "immediate", Component.class);
}
public boolean inherit() {
- return Util.getValue(annotation, "inherit", true);
+ return Util.getBooleanValue(annotation, "inherit", Component.class);
}
public String label() {
- return Util.getValue(annotation, "label", "");
+ return Util.getStringValue(annotation, "label", Component.class);
}
public boolean metatype() {
- return Util.getValue(annotation, "metatype", false);
+ return Util.getBooleanValue(annotation, "metatype", Component.class);
}
public String name() {
- return Util.getValue(annotation, "name", "");
+ return Util.getStringValue(annotation, "name", Component.class);
}
public Class<? extends java.lang.annotation.Annotation> annotationType() {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
index 9023e60..671a51b 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
@@ -80,26 +80,29 @@
if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Component.class.getName())) {
tags.add(new ComponentTag(annotation, description));
} else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Property.class.getName())) {
- //tags.add(new PropertyTag(annotation, description));
+ tags.add(new PropertyTag(annotation, description));
} else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Service.class.getName())) {
- //tags.add(new ServiceTag(annotation, description));
+ tags.add(new ServiceTag(annotation, description));
} else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Reference.class.getName())) {
- //tags.add(new ReferenceTag(annotation, description, field));
+ tags.add(new ReferenceTag(annotation, description, field));
}
// check for multi-annotations
else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Properties.class.getName())) {
- //for (Property property : ((Properties) annotation).value()) {
- // tags.add(new PropertyTag(property, description));
- //}
+ final com.thoughtworks.qdox.model.Annotation[] properties = (com.thoughtworks.qdox.model.Annotation[])annotation.getNamedParameter("value");
+ for (com.thoughtworks.qdox.model.Annotation property : properties) {
+ tags.add(new PropertyTag(property, description));
+ }
} else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Services.class.getName())) {
- //for (Service service : ((Services) annotation).value()) {
- // tags.add(new ServiceTag(service, description));
- //}
+ final com.thoughtworks.qdox.model.Annotation[] services = (com.thoughtworks.qdox.model.Annotation[])annotation.getNamedParameter("value");
+ for (com.thoughtworks.qdox.model.Annotation service : services) {
+ tags.add(new ServiceTag(service, description));
+ }
} else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(References.class.getName())) {
- //for (Reference reference : ((References) annotation).value()) {
- // tags.add(new ReferenceTag(reference, description, field));
- //}
+ final com.thoughtworks.qdox.model.Annotation[] references = (com.thoughtworks.qdox.model.Annotation[])annotation.getNamedParameter("value");
+ for (com.thoughtworks.qdox.model.Annotation reference : references) {
+ tags.add(new ReferenceTag(reference, description, field));
+ }
}
return tags;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
index 0fc24a0..279a234 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
@@ -24,6 +24,8 @@
import org.apache.felix.scrplugin.annotations.*;
import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import com.thoughtworks.qdox.model.Annotation;
+
/**
* Description of a java tag for components.
*/
@@ -40,6 +42,61 @@
this.annotation = annotation;
}
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public PropertyTag(final Annotation annotation, JavaClassDescription desc) {
+ super(desc, null);
+ this.annotation = new Property() {
+
+ public int cardinality() {
+ return Util.getIntValue(annotation, "cardinality", Property.class);
+ }
+
+ public String description() {
+ return Util.getStringValue(annotation, "description", Property.class);
+ }
+
+ public String label() {
+ return Util.getStringValue(annotation, "label", Property.class);
+ }
+
+ public String name() {
+ return Util.getStringValue(annotation, "name", Property.class);
+ }
+
+ public PropertyOption[] options() {
+ final Object obj = annotation.getNamedParameter("options");
+ if ( obj != null ) {
+ return (PropertyOption[])obj;
+ }
+ try {
+ return (PropertyOption[]) Property.class.getMethod("options").getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return null;
+ }
+ }
+
+ public boolean propertyPrivate() {
+ return Util.getBooleanValue(annotation, "propertyPrivate", Property.class);
+ }
+
+ public Class<?> type() {
+ return Util.getClassValue(annotation, "type", Property.class);
+ }
+
+ public String[] value() {
+ return Util.getStringValues(annotation, "value", Property.class);
+ }
+
+ public Class<? extends java.lang.annotation.Annotation> annotationType() {
+ return null;
+ }
+ };
+ }
+
@Override
public String getName() {
return Constants.PROPERTY;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
index 4cf97e7..f7c67eb 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ReferenceTag.java
@@ -22,11 +22,12 @@
import java.util.Map;
import org.apache.felix.scrplugin.Constants;
-import org.apache.felix.scrplugin.annotations.AutoDetect;
-import org.apache.felix.scrplugin.annotations.Reference;
+import org.apache.felix.scrplugin.annotations.*;
import org.apache.felix.scrplugin.tags.JavaClassDescription;
import org.apache.felix.scrplugin.tags.JavaField;
+import com.thoughtworks.qdox.model.Annotation;
+
/**
* Description of a java tag for components.
*/
@@ -44,6 +45,81 @@
this.annotation = annotation;
}
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public ReferenceTag(final Annotation annotation, JavaClassDescription desc, JavaField field) {
+ super(desc, field);
+
+ this.annotation = new Reference() {
+
+ public String bind() {
+ return Util.getStringValue(annotation, "bind", Reference.class);
+ }
+
+ public ReferenceCardinality cardinality() {
+ final Object obj = annotation.getNamedParameter("cardinality");
+ if ( obj != null ) {
+ if ( obj instanceof ReferenceCardinality ) {
+ return (ReferenceCardinality)obj;
+ }
+ return ReferenceCardinality.values()[(Integer)obj];
+ }
+ try {
+ return (ReferenceCardinality) Reference.class.getMethod("cardinality").getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return null;
+ }
+ }
+
+ public boolean checked() {
+ return Util.getBooleanValue(annotation, "checked", Reference.class);
+ }
+
+ public String name() {
+ return Util.getStringValue(annotation, "name", Reference.class);
+ }
+
+ public ReferencePolicy policy() {
+ final Object obj = annotation.getNamedParameter("policy");
+ if ( obj != null ) {
+ if ( obj instanceof ReferencePolicy ) {
+ return (ReferencePolicy)obj;
+ }
+ return ReferencePolicy.values()[(Integer)obj];
+ }
+ try {
+ return (ReferencePolicy) Reference.class.getMethod("policy").getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return null;
+ }
+ }
+
+ public Class<?> referenceInterface() {
+ return Util.getClassValue(annotation, "referenceInterface", Reference.class);
+ }
+
+ public String strategy() {
+ return Util.getStringValue(annotation, "strategy", Reference.class);
+ }
+
+ public String target() {
+ return Util.getStringValue(annotation, "target", Reference.class);
+ }
+
+ public String unbind() {
+ return Util.getStringValue(annotation, "unbind", Reference.class);
+ }
+
+ public Class<? extends java.lang.annotation.Annotation> annotationType() {
+ return null;
+ }
+ };
+ }
+
@Override
public String getName() {
return Constants.REFERENCE;
@@ -55,11 +131,10 @@
map.put(Constants.REFERENCE_NAME, emptyToNull(this.annotation.name()));
- String referenceInterface = null;
if (this.annotation.referenceInterface() != AutoDetect.class) {
- referenceInterface = this.annotation.referenceInterface().getName();
+ String referenceInterface = this.annotation.referenceInterface().getName();
+ map.put(Constants.REFERENCE_INTERFACE, referenceInterface);
}
- map.put(Constants.REFERENCE_INTERFACE, referenceInterface);
map.put(Constants.REFERENCE_CARDINALITY, this.annotation.cardinality().getCardinalityString());
map.put(Constants.REFERENCE_POLICY, this.annotation.policy().getPolicyString());
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
index 7578f25..512751f 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
@@ -26,6 +26,8 @@
import org.apache.felix.scrplugin.annotations.Service;
import org.apache.felix.scrplugin.tags.JavaClassDescription;
+import com.thoughtworks.qdox.model.Annotation;
+
/**
* Description of a java tag for components.
*/
@@ -42,6 +44,28 @@
this.annotation = annotation;
}
+ /**
+ * @param annotation Annotation
+ * @param desc Description
+ */
+ public ServiceTag(final Annotation annotation, JavaClassDescription desc) {
+ super(desc, null);
+ this.annotation = new Service() {
+
+ public boolean serviceFactory() {
+ return Util.getBooleanValue(annotation, "serviceFactory", Service.class);
+ }
+
+ public Class<?> value() {
+ return Util.getClassValue(annotation, "value", Service.class);
+ }
+
+ public Class<? extends java.lang.annotation.Annotation> annotationType() {
+ return null;
+ }
+ };
+ }
+
@Override
public String getName() {
return Constants.SERVICE;
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
index 7cc3239..4478fe6 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
@@ -18,11 +18,13 @@
*/
package org.apache.felix.scrplugin.tags.annotation.defaulttag;
+import org.apache.felix.scrplugin.tags.ClassUtil;
+
import com.thoughtworks.qdox.model.Annotation;
public abstract class Util {
- public static boolean getValue(Annotation annotation, String name, boolean defaultValue) {
+ public static boolean getBooleanValue(Annotation annotation, String name, final Class<?> clazz) {
final Object obj = annotation.getNamedParameter(name);
if ( obj != null ) {
if ( obj instanceof String ) {
@@ -32,10 +34,46 @@
}
return Boolean.valueOf(obj.toString());
}
- return defaultValue;
+ try {
+ return (Boolean) clazz.getMethod(name).getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return true;
+ }
}
- public static String getValue(Annotation annotation, String name, String defaultValue) {
+ public static int getIntValue(Annotation annotation, String name, final Class<?> clazz) {
+ final Object obj = annotation.getNamedParameter(name);
+ if ( obj != null ) {
+ if ( obj instanceof String ) {
+ return Integer.valueOf((String)obj);
+ } else if ( obj instanceof Number ) {
+ return ((Number)obj).intValue();
+ }
+ return Integer.valueOf(obj.toString());
+ }
+ try {
+ return (Integer) clazz.getMethod(name).getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return 0;
+ }
+ }
+
+ public static String[] getStringValues(Annotation annotation, String name, final Class<?> clazz) {
+ final Object obj = annotation.getNamedParameter(name);
+ if ( obj != null ) {
+ return (String[])obj;
+ }
+ try {
+ return (String[]) clazz.getMethod(name).getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return null;
+ }
+ }
+
+ public static String getStringValue(Annotation annotation, String name, final Class<?> clazz) {
final Object obj = annotation.getNamedParameter(name);
if ( obj != null ) {
if ( obj instanceof String ) {
@@ -43,6 +81,27 @@
}
return obj.toString();
}
- return defaultValue;
+ try {
+ return (String) clazz.getMethod(name).getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return "";
+ }
+ }
+
+ public static Class<?> getClassValue(Annotation annotation, String name, final Class<?> clazz) {
+ final Object obj = annotation.getNamedParameter(name);
+ if ( obj != null ) {
+ if ( obj instanceof Class ) {
+ return (Class<?>)obj;
+ }
+ return ClassUtil.getClass(obj.toString());
+ }
+ try {
+ return (Class<?>) clazz.getMethod(name).getDefaultValue();
+ } catch( NoSuchMethodException mnfe) {
+ // we ignore this
+ return null;
+ }
}
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
index 064e996..ee9a049 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
@@ -46,9 +46,9 @@
protected final JavaSource source;
/** The compiled class. */
- protected final Class clazz;
+ protected final Class<?> clazz;
- public QDoxJavaClassDescription(Class clazz, JavaSource source, JavaClassDescriptorManager m) {
+ public QDoxJavaClassDescription(Class<?> clazz, JavaSource source, JavaClassDescriptorManager m) {
this.javaClass = source.getClasses()[0];
this.manager = m;
this.source = source;
@@ -419,7 +419,7 @@
return getName();
}
- public Class getCompiledClass() {
+ public Class<?> getCompiledClass() {
return this.clazz;
}
}