aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1704204 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/b...
Date Sun, 20 Sep 2015 21:13:03 GMT
Author: cschneider
Date: Sun Sep 20 21:12:58 2015
New Revision: 1704204

URL: http://svn.apache.org/viewvc?rev=1704204&view=rev
Log:
[ARIES-1411] Support service refs with same interface but different filter

Added:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java
Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Sun Sep 20 21:12:58 2015
@@ -148,7 +148,7 @@ public class Generator implements Proper
     }
     
     private void writeFactory(ProducedBean bean) throws XMLStreamException {
-        writer.writeAttribute("factory-ref", bean.factoryBeanId);
+        writer.writeAttribute("factory-ref", bean.factoryBean.id);
         writer.writeAttribute("factory-method", bean.factoryMethod);
     }
 

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
Sun Sep 20 21:12:58 2015
@@ -1,15 +1,18 @@
 package org.apache.aries.blueprint.plugin.model;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.inject.Named;
 
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 public class BeanRef implements Comparable<BeanRef> {
     public String id;
     public Class<?> clazz;
+    public Map<Class<? extends Annotation>, Annotation> qualifiers;
     
     /**
      * 
@@ -17,27 +20,25 @@ public class BeanRef implements Comparab
      */
     public BeanRef(Class<?> clazz) {
         this.clazz = clazz;
+        this.qualifiers = new HashMap<Class<? extends Annotation>, Annotation>();
     }
     
-    public BeanRef(Class<?> type, String id) {
-        this.clazz = type;
+    public BeanRef(Class<?> clazz, String id) {
+        this(clazz);
         this.id = id;
     }
 
     public BeanRef(Field field) {
-        this(field.getType(), getDestinationId(field));
+        this(field.getType());
+        for (Annotation ann : field.getAnnotations()) {
+            if (isQualifier(ann) != null) {
+                this.qualifiers.put(ann.annotationType(), ann);
+            }
+        }
     }
 
-    private static String getDestinationId(Field field) {
-        Named named = field.getAnnotation(Named.class);
-        if (named != null) {
-            return named.value();
-        }
-        Qualifier qualifier = field.getAnnotation(Qualifier.class);
-        if (qualifier != null) {
-            return qualifier.value();
-        }
-        return null;
+    private javax.inject.Qualifier isQualifier(Annotation ann) {
+        return ann.annotationType().getAnnotation(javax.inject.Qualifier.class);
     }
 
     public static String getBeanName(Class<?> clazz) {
@@ -59,7 +60,7 @@ public class BeanRef implements Comparab
     
     public boolean matches(BeanRef template) {
         boolean assignable = template.clazz.isAssignableFrom(this.clazz);
-        return assignable && ((template.id == null) || id.equals(template.id));
+        return assignable && qualifiers.values().containsAll(template.qualifiers.values());
     }
 
     @Override

Added: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java?rev=1704204&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java
(added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java
Sun Sep 20 21:12:58 2015
@@ -0,0 +1,25 @@
+package org.apache.aries.blueprint.plugin.model;
+
+import com.google.inject.name.Named;
+
+public class BuiltInBeanRef extends BeanRef {
+
+    public BuiltInBeanRef(Class<?> clazz, String id) {
+        super(clazz);
+        this.id = id;
+    }
+
+    @Override
+    public boolean matches(BeanRef template) {
+        if (template.clazz != this.clazz || template.qualifiers.size() > 1) {
+            return false;
+        }
+        if (template.qualifiers.size() == 0) {
+            return true;
+        }
+        Named name = (Named)template.qualifiers.get(Named.class);
+        return name != null && id.equals(name.value());
+    }
+
+    
+}

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
Sun Sep 20 21:12:58 2015
@@ -64,15 +64,15 @@ public class Context implements Matcher
         Bean bean = new Bean(clazz);
         reg.add(bean);
         addServiceRefs(clazz);
-        addProducedBeans(clazz, bean.id);
+        addProducedBeans(clazz, bean);
     }
 
-    private void addProducedBeans(Class<?> clazz, String factoryBeanId) {
+    private void addProducedBeans(Class<?> clazz, BeanRef factoryBean) {
         for (Method method : clazz.getMethods()) {
             Produces produces = method.getAnnotation(Produces.class);
             if (produces != null) {
                 Class<?> producedClass = method.getReturnType();
-                ProducedBean producedBean = new ProducedBean(producedClass, factoryBeanId,
method.getName());
+                ProducedBean producedBean = new ProducedBean(producedClass, factoryBean,
method.getName());
                 reg.add(producedBean);
             }
         }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
Sun Sep 20 21:12:58 2015
@@ -31,11 +31,23 @@ public class OsgiServiceRef extends Bean
 
     public OsgiServiceRef(Field field) {
         super(field);
-        if (id == null) {
-            id = getBeanName(clazz);
-        }
         OsgiService osgiService = field.getAnnotation(OsgiService.class);
         filter = osgiService.filter();
+        id = getBeanName(clazz);
+        if (filter != null) {
+            id = id + "-" + getId(filter);
+        }
+    }
+
+    private String getId(String raw) {
+        StringBuilder builder = new StringBuilder();
+        for (int c = 0; c < raw.length(); c++) {
+            char ch = raw.charAt(c);
+            if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <=
'Z' || ch >= '0' && ch <= '9') {
+                builder.append(ch);
+            }
+        }
+        return builder.toString();
     }
 
 }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
Sun Sep 20 21:12:58 2015
@@ -3,11 +3,11 @@ package org.apache.aries.blueprint.plugi
 
 public class ProducedBean extends Bean {
     public String factoryMethod;
-    public String factoryBeanId;
+    public BeanRef factoryBean;
     
-    public ProducedBean(Class<?> clazz, String factoryBeanId, String factoryMethod)
{
+    public ProducedBean(Class<?> clazz, BeanRef factoryBean, String factoryMethod)
{
         super(clazz);
-        this.factoryBeanId = factoryBeanId;
+        this.factoryBean = factoryBean;
         this.factoryMethod = factoryMethod;
     }
 

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
Sun Sep 20 21:12:58 2015
@@ -60,11 +60,11 @@ public class Property implements Compara
     private static String getRefName(Field field) {
         Named named = field.getAnnotation(Named.class);
         if (named != null) {
-        	return named.value();
+            return named.value();
         }
     	Qualifier qualifier = field.getAnnotation(Qualifier.class);
         if (qualifier != null) {
-        	return qualifier.value();
+            return qualifier.value();
         }
         return Bean.getBeanName(field.getType());
     }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/ContextTest.java
Sun Sep 20 21:12:58 2015
@@ -45,16 +45,16 @@ public class ContextTest {
     public void testLists2()  {
         Context context = new Context(ServiceReferences.class);
         Assert.assertEquals(1, context.getBeans().size());
-        Assert.assertEquals(2, context.getServiceRefs().size());
+        Assert.assertEquals(3, context.getServiceRefs().size());
     }
     
     @Test
     public void testMatching() throws NoSuchFieldException, SecurityException  {
         Context context = new Context(ServiceReferences.class);
-        BeanRef matching = context.getMatching(new BeanRef(ServiceB.class));
+        BeanRef matching = context.getMatching(new BeanRef(ServiceReferences.class.getDeclaredField("serviceB")));
         Assert.assertEquals(OsgiServiceRef.class, matching.getClass());
         Assert.assertEquals(ServiceB.class, matching.clazz);
-        Assert.assertEquals("serviceB", matching.id);
+        Assert.assertEquals("serviceB-typeB1", matching.id);
     }
     
     private void assertSpecialRef(String expectedId, Class<?> clazz) {
@@ -74,10 +74,10 @@ public class ContextTest {
     @Test
     public void testProduced() throws NoSuchFieldException, SecurityException  {
         Context context = new Context(MyFactoryBean.class);
-        
+        context.resolve();
         ProducedBean matching = (ProducedBean)context.getMatching(new BeanRef(MyProduced.class));
         Assert.assertEquals(MyProduced.class, matching.clazz);
-        Assert.assertEquals("myFactoryBean", matching.factoryBeanId);
+        Assert.assertEquals("myFactoryBean", matching.factoryBean.id);
         Assert.assertEquals("create", matching.factoryMethod);
     }
     

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java?rev=1704204&r1=1704203&r2=1704204&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceReferences.java
Sun Sep 20 21:12:58 2015
@@ -30,4 +30,6 @@ public class ServiceReferences {
     @Inject @OsgiService(filter="(type=B1)") ServiceB serviceB;
     
     @Named("serviceB2Id") @Inject @OsgiService(filter="(type=B2)") ServiceB serviceB2;
+    
+    @Inject @OsgiService(filter="(type=B3)") ServiceB serviceB3;
 }



Mime
View raw message