aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1704117 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/test/
Date Sun, 20 Sep 2015 10:01:42 GMT
Author: cschneider
Date: Sun Sep 20 10:01:41 2015
New Revision: 1704117

URL: http://svn.apache.org/viewvc?rev=1704117&view=rev
Log:
Refactoring towards bean registry

Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.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/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/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1704117&r1=1704116&r2=1704117&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Sun Sep 20 10:01:41 2015
@@ -39,7 +39,7 @@ public class Bean extends BeanRef {
     public TransactionalDef transactionDef;
 
     public Bean(Class<?> clazz) {
-        super(clazz);
+        super(clazz, BeanRef.getBeanName(clazz));
 
         for (Method method : clazz.getDeclaredMethods()) {
             PostConstruct postConstruct = getEffectiveAnnotation(method, PostConstruct.class);

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=1704117&r1=1704116&r2=1704117&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 10:01:41 2015
@@ -17,7 +17,6 @@ public class BeanRef implements Comparab
      */
     public BeanRef(Class<?> clazz) {
         this.clazz = clazz;
-        this.id = getBeanName(clazz);
     }
     
     public BeanRef(Class<?> type, String id) {
@@ -67,4 +66,9 @@ public class BeanRef implements Comparab
     public int compareTo(BeanRef other) {
         return this.id.compareTo(other.id);
     }
+    
+    @Override
+    public String toString() {
+        return this.clazz.getSimpleName() + "(" + this.id + ")";
+    }
 }

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=1704117&r1=1704116&r2=1704117&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 10:01:41 2015
@@ -35,19 +35,25 @@ import org.osgi.service.blueprint.contai
 
 public class Context implements Matcher {
 
-    SortedSet<Bean> beans;
-    SortedSet<OsgiServiceRef> serviceRefs;
+    SortedSet<BeanRef> reg;
 
     public Context(Class<?>... beanClasses) {
         this(Arrays.asList(beanClasses));
     }
 
     public Context(Collection<Class<?>> beanClasses) {
-        this.beans = new TreeSet<Bean>();
-        this.serviceRefs = new TreeSet<OsgiServiceRef>();
+        this.reg = new TreeSet<BeanRef>();
+        addBlueprintRefs();
         addBeans(beanClasses);
     }
 
+    private void addBlueprintRefs() {
+        reg.add(new BeanRef(BundleContext.class, "blueprintBundleContext"));
+        reg.add(new BeanRef(Bundle.class, "blueprintBundle"));
+        reg.add(new BeanRef(BlueprintContainer.class, "blueprintContainer"));
+        reg.add(new BeanRef(Converter.class, "blueprintConverter"));
+    }
+
     private void addBeans(Collection<Class<?>> beanClasses) {
         for (Class<?> clazz : beanClasses) {
             addBean(clazz);
@@ -56,7 +62,7 @@ public class Context implements Matcher
 
     private void addBean(Class<?> clazz) {
         Bean bean = new Bean(clazz);
-        beans.add(bean);
+        reg.add(bean);
         addServiceRefs(clazz);
         addProducedBeans(clazz, bean.id);
     }
@@ -67,7 +73,7 @@ public class Context implements Matcher
             if (produces != null) {
                 Class<?> producedClass = method.getReturnType();
                 ProducedBean producedBean = new ProducedBean(producedClass, factoryBeanId,
method.getName());
-                beans.add(producedBean);
+                reg.add(producedBean);
             }
         }
     }
@@ -76,49 +82,43 @@ public class Context implements Matcher
         for (Field field : clazz.getDeclaredFields()) {
             OsgiService osgiService = field.getAnnotation(OsgiService.class);
             if (osgiService != null) {
-                serviceRefs.add(new OsgiServiceRef(field));
+                reg.add(new OsgiServiceRef(field));
             }
         }
     }
 
     public void resolve() {
-        for (Bean bean : beans) {
+        for (Bean bean : getBeans()) {
             bean.resolve(this);
         }
     }
     
     public BeanRef getMatching(BeanRef template) {
-        for (Bean bean : beans) {
+        for (BeanRef bean : reg) {
             if (bean.matches(template)) {
                 return bean;
             }
         }
-        for (BeanRef bean : serviceRefs) {
-            if (bean.matches(template)) {
-                return bean;
-            }
-        }
-        if (template.clazz == BundleContext.class) {
-            return new BeanRef(BundleContext.class, "blueprintBundleContext");
-        }
-        if (template.clazz == Bundle.class) {
-            return new BeanRef(Bundle.class, "blueprintBundle");
-        }
-        if (template.clazz == BlueprintContainer.class) {
-            return new BeanRef(BlueprintContainer.class, "blueprintContainer");
-        }
-        if (template.clazz == Converter.class) {
-            return new BeanRef(Converter.class, "blueprintConverter");
-        }
-        
         return null;
     }
 
     public SortedSet<Bean> getBeans() {
+        TreeSet<Bean> beans = new TreeSet<Bean>();
+        for (BeanRef ref : reg) {
+            if (ref instanceof Bean) {
+                beans.add((Bean)ref);
+            }
+        }
         return beans;
     }
 
     public SortedSet<OsgiServiceRef> getServiceRefs() {
+        TreeSet<OsgiServiceRef> serviceRefs = new TreeSet<OsgiServiceRef>();
+        for (BeanRef ref : reg) {
+            if (ref instanceof OsgiServiceRef) {
+                serviceRefs.add((OsgiServiceRef)ref);
+            }
+        }
         return serviceRefs;
     }
 

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=1704117&r1=1704116&r2=1704117&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 10:01:41 2015
@@ -27,7 +27,7 @@ import org.springframework.stereotype.Co
 
 @Component
 public class ServiceReferences {
-    @Inject @OsgiService ServiceB serviceB;
+    @Inject @OsgiService(filter="(type=B1)") ServiceB serviceB;
     
-    @Named("serviceB2Id") @Inject @OsgiService ServiceB serviceB2;
+    @Named("serviceB2Id") @Inject @OsgiService(filter="(type=B2)") ServiceB serviceB2;
 }



Mime
View raw message