You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2010/03/03 21:54:24 UTC

svn commit: r918678 - in /felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation: api/BundleAdapterService.java plugin/bnd/AnnotationCollector.java

Author: pderop
Date: Wed Mar  3 20:54:24 2010
New Revision: 918678

URL: http://svn.apache.org/viewvc?rev=918678&view=rev
Log:
added annotation support for BundleAdapterService

Added:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/BundleAdapterService.java
Modified:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java

Added: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/BundleAdapterService.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/BundleAdapterService.java?rev=918678&view=auto
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/BundleAdapterService.java (added)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/BundleAdapterService.java Wed Mar  3 20:54:24 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.dm.annotation.api;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.osgi.framework.Bundle;
+
+public @Retention(RetentionPolicy.CLASS)
+@Target(ElementType.TYPE)
+@interface BundleAdapterService
+{
+    String filter();
+    int stateMask() default Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE;
+    Class<?> service() default Object.class;
+    Param[] properties() default {};
+    boolean propagate() default true;
+}

Modified: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java?rev=918678&r1=918677&r2=918678&view=diff
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java (original)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java Wed Mar  3 20:54:24 2010
@@ -31,6 +31,7 @@
 
 import org.apache.felix.dm.annotation.api.AdapterService;
 import org.apache.felix.dm.annotation.api.AspectService;
+import org.apache.felix.dm.annotation.api.BundleAdapterService;
 import org.apache.felix.dm.annotation.api.BundleDependency;
 import org.apache.felix.dm.annotation.api.Composition;
 import org.apache.felix.dm.annotation.api.ConfigurationDependency;
@@ -42,6 +43,7 @@
 import org.apache.felix.dm.annotation.api.Start;
 import org.apache.felix.dm.annotation.api.Stop;
 import org.apache.felix.dm.annotation.api.TemporalServiceDependency;
+import org.osgi.framework.Bundle;
 
 import aQute.lib.osgi.Annotation;
 import aQute.lib.osgi.ClassDataCollector;
@@ -76,6 +78,8 @@
         + AspectService.class.getName().replace('.', '/') + ";";
     private final static String A_ADAPTER_SERVICE = "L"
         + AdapterService.class.getName().replace('.', '/') + ";";
+    private final static String A_BUNDLE_ADAPTER_SERVICE = "L"
+        + BundleAdapterService.class.getName().replace('.', '/') + ";";
 
     private Reporter m_reporter;
     private String m_className;
@@ -111,6 +115,7 @@
         Service, 
         AspectService,
         AdapterService,
+        BundleAdapterService,
         ServiceDependency, 
         TemporalServiceDependency, 
         ConfigurationDependency,
@@ -366,6 +371,10 @@
         {
             parseAdapterService(annotation);
         }
+        else if (annotation.getName().equals(A_BUNDLE_ADAPTER_SERVICE))
+        {
+            parseBundleAdapterService(annotation);
+        }
         else if (annotation.getName().equals(A_INIT))
         {
             checkMethod(m_voidMethodPattern);
@@ -693,6 +702,62 @@
         }
     }
 
+    /**
+     * Parses a BundleAdapterService annotation.
+     * @param annotation
+     */
+    private void parseBundleAdapterService(Annotation annotation)
+    {
+        Info info = new Info(EntryTypes.BundleAdapterService);
+        m_infos.add(info);
+        
+        // Register previously parsed Init/Start/Stop/Destroy/Composition annotations
+        addInitStartStopDestroyCompositionParams(info);
+        
+        // Generate Adapter Implementation
+        info.addParam(Params.impl, m_className);
+      
+        // Parse bundle filter
+        String filter = annotation.get(Params.filter.toString());
+        if (filter != null)
+        {
+            Verifier.verifyFilter(filter, 0);
+            info.addParam(Params.filter, filter);
+        }
+        
+        // Parse stateMask attribute
+        info.addParam(annotation, Params.stateMask, new Integer(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE));
+        
+        // Parse Adapter properties.
+        parseParameters(annotation, Params.properties, info);
+
+        // Parse the optional adapter service (use directly implemented interface by default).
+        Object service = annotation.get(Params.service.toString());
+        if (service == null) {
+            if (m_interfaces == null)
+            {
+                throw new IllegalStateException("Invalid BundleAdapterService annotation: " +
+                    "the service attribute has not been set and the class " + m_className + 
+                    " does not implement any interfaces");
+            }
+            if (m_interfaces.length != 1) 
+            {
+                throw new IllegalStateException("Invalid AdapterService annotation: " +
+                    "the service attribute has not been set and the class " + m_className +
+                    " implements more than one interface");
+            }
+            
+            info.addParam(Params.service, m_interfaces[0]);
+        } else 
+        {
+            checkClassImplements(annotation, Params.service);
+            info.addClassParam(annotation, Params.service, null);
+        }
+        
+        // Parse propagate attribute
+        info.addParam(annotation, Params.propagate, Boolean.FALSE);
+    }
+
     private void parseBundleDependencyAnnotation(Annotation annotation)
     {
         Info info = new Info(EntryTypes.BundleDependency);
@@ -849,7 +914,7 @@
         }
 
         // We must have at least a Service or an AspectService annotation.
-        checkServiceDeclared(EntryTypes.Service, EntryTypes.AspectService, EntryTypes.AdapterService);
+        checkServiceDeclared(EntryTypes.Service, EntryTypes.AspectService, EntryTypes.AdapterService, EntryTypes.BundleAdapterService);
 
         StringBuilder sb = new StringBuilder();
         sb.append("Parsed annotation for class ");