You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2011/02/22 17:50:56 UTC

svn commit: r1073402 - in /felix/trunk/scrplugin: annotations/ annotations/src/main/java/org/apache/felix/scr/annotations/ annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ generator/src/main/java/org/apache/felix/scrplug...

Author: cziegeler
Date: Tue Feb 22 16:50:56 2011
New Revision: 1073402

URL: http://svn.apache.org/viewvc?rev=1073402&view=rev
Log:
FELIX-2753 : Support array of classes for @Service annotation

Modified:
    felix/trunk/scrplugin/annotations/pom.xml
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Service.java
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Services.java
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java

Modified: felix/trunk/scrplugin/annotations/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/pom.xml?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/pom.xml (original)
+++ felix/trunk/scrplugin/annotations/pom.xml Tue Feb 22 16:50:56 2011
@@ -47,7 +47,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.scr.generator</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
+            <version>1.0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Service.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Service.java?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Service.java (original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Service.java Tue Feb 22 16:50:56 2011
@@ -18,11 +18,7 @@
  */
 package org.apache.felix.scr.annotations;
 
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
 
 /**
  * The <code>Service</code> annotation defines whether and which service
@@ -43,7 +39,7 @@ public @interface Service {
      * property is not set provide elements will be generated for all interfaces
      * generated by the class
      */
-    Class<?> value() default AutoDetect.class;
+    Class<?>[] value() default AutoDetect.class;
 
     /**
      * Whether the component is registered as a

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Services.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Services.java?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Services.java (original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Services.java Tue Feb 22 16:50:56 2011
@@ -18,18 +18,17 @@
  */
 package org.apache.felix.scr.annotations;
 
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
 
 /**
  * Allows to define multiple {@link Service} annotations for one type.
+ *
+ * @deprecated It's now possible to use multiple classes in the {@link Service} annotation.
  */
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.SOURCE)
 @Documented
+@Deprecated
 public @interface Services {
 
     /**

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java (original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/DefaultAnnotationTagProvider.java Tue Feb 22 16:50:56 2011
@@ -21,13 +21,7 @@ package org.apache.felix.scrplugin.tags.
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.References;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.felix.scr.annotations.Services;
+import org.apache.felix.scr.annotations.*;
 import org.apache.felix.scrplugin.tags.JavaField;
 import org.apache.felix.scrplugin.tags.JavaTag;
 import org.apache.felix.scrplugin.tags.annotation.AnnotationJavaClassDescription;
@@ -53,7 +47,7 @@ public class DefaultAnnotationTagProvide
         } else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Property.class.getName())) {
             tags.add(new PropertyTag(annotation, description, field));
         } else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Service.class.getName())) {
-            tags.add(new ServiceTag(annotation, description));
+            tags.addAll(ServiceTag.createServiceTags(annotation, description));
         } else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(Reference.class.getName())) {
             tags.add(new ReferenceTag(annotation, description, field));
         }
@@ -69,7 +63,7 @@ public class DefaultAnnotationTagProvide
             @SuppressWarnings("unchecked")
             final List<Annotation> services = (List<Annotation>)annotation.getNamedParameter("value");
             for (Annotation service : services) {
-                tags.add(new ServiceTag(service, description));
+                tags.addAll(ServiceTag.createServiceTags(service, description));
             }
         } else if (annotation.getType().getJavaClass().getFullyQualifiedName().equals(References.class.getName())) {
             @SuppressWarnings("unchecked")

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java (original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java Tue Feb 22 16:50:56 2011
@@ -18,8 +18,7 @@
  */
 package org.apache.felix.scrplugin.tags.annotation.defaulttag;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 import org.apache.felix.scr.annotations.AutoDetect;
 import org.apache.felix.scr.annotations.Service;
@@ -37,26 +36,19 @@ public class ServiceTag extends Abstract
 
     protected final Service annotation;
 
+    protected final String serviceInterface;
+
     /**
      * @param annotation Annotation
      * @param desc Description
      */
-    public ServiceTag(final Annotation annotation, JavaClassDescription desc) {
+    public ServiceTag(final Annotation annotation,
+            final JavaClassDescription desc,
+            final Service tag,
+            final String serviceInterface) {
         super(annotation, 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;
-            }
-        };
+        this.annotation = tag;
+        this.serviceInterface = serviceInterface;
     }
 
     @Override
@@ -68,15 +60,37 @@ public class ServiceTag extends Abstract
     public Map<String, String> createNamedParameterMap() {
         final Map<String, String> map = new HashMap<String, String>();
 
-        String serviceInterface = null;
-        if (this.annotation.value() != AutoDetect.class) {
-            serviceInterface = this.annotation.value().getName();
-        }
-        map.put(Constants.SERVICE_INTERFACE, serviceInterface);
-
+        map.put(Constants.SERVICE_INTERFACE, this.serviceInterface);
         map.put(Constants.SERVICE_FACTORY, String.valueOf(this.annotation.serviceFactory()));
 
         return map;
     }
 
+    public static List<ServiceTag> createServiceTags(final Annotation annotation, JavaClassDescription desc) {
+        final Service tag = new Service() {
+
+            public boolean serviceFactory() {
+                return Util.getBooleanValue(annotation, "serviceFactory", Service.class);
+            }
+
+            public Class<?>[] value() {
+                return Util.getClassArrayValue(annotation, "value", Service.class);
+            }
+
+            public Class<? extends java.lang.annotation.Annotation> annotationType() {
+                return null;
+            }
+        };
+        final Class<?>[] classes = tag.value();
+        System.out.println("Classes: " + Arrays.toString(classes));
+        if ( classes != null && classes.length > 0
+             && (classes.length != 1 || !classes[0].getName().equals(AutoDetect.class.getName()))) {
+            final List<ServiceTag> tags = new ArrayList<ServiceTag>();
+            for(final Class<?> c : classes ) {
+                tags.add(new ServiceTag(annotation, desc, tag, c.getName()));
+            }
+            return tags;
+        }
+        return Collections.singletonList(new ServiceTag(annotation, desc, tag, null));
+    }
 }

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java?rev=1073402&r1=1073401&r2=1073402&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java (original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java Tue Feb 22 16:50:56 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.scrplugin.tags.annotation;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.felix.scrplugin.SCRDescriptorException;
@@ -309,11 +310,14 @@ public abstract class Util {
     }
 
     public static Class<?>[] getClassArrayValue(Annotation annotation, String name, final Class<?> clazz) {
-        final Object obj = annotation.getNamedParameter(name);
+        Object obj = annotation.getNamedParameter(name);
         if ( obj != null ) {
             if ( obj instanceof Class<?> ) {
                 return new Class<?>[] {(Class<?>)obj};
             }
+            if ( obj instanceof Collection<?> ) {
+                obj = ((Collection<?>)obj).toArray();
+            }
             if ( obj.getClass().isArray() ) {
                 final Object[] objArray = (Object[])obj;
                 final Class<?>[] result = new Class<?>[objArray.length];