aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1781793 - in /aries/trunk/blueprint/plugin/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/model/ test/java/org/apache/aries/blueprint/plugin/model/
Date Sun, 05 Feb 2017 20:16:15 GMT
Author: alien11689
Date: Sun Feb  5 20:16:15 2017
New Revision: 1781793

URL: http://svn.apache.org/viewvc?rev=1781793&view=rev
Log:
[REFACTOR] Extract bean template from bean ref

Added:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java
      - copied, changed from r1781787, aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java
Modified:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
Sun Feb  5 20:16:15 2017
@@ -46,10 +46,12 @@ import java.util.TreeSet;
 import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findName;
 import static org.apache.aries.blueprint.plugin.model.AnnotationHelper.findValue;
 
-class Bean extends BeanRef implements BeanEnricher, XmlWriter {
+class Bean implements BeanEnricher, XmlWriter {
 
     private static final String NS_EXT = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
 
+    String id;
+    final Class<?> clazz;
     SortedSet<Property> properties = new TreeSet<>();
     List<Argument> constructorArguments = new ArrayList<>();
     final Map<String, String> attributes = new HashMap<>();
@@ -57,7 +59,8 @@ class Bean extends BeanRef implements Be
     protected final ContextEnricher contextEnricher;
 
     Bean(Class<?> clazz, ContextEnricher contextEnricher) {
-        super(clazz, getBeanName(clazz), clazz.getAnnotations());
+        this.clazz = clazz;
+        this.id = getBeanName(clazz);
         this.contextEnricher = contextEnricher;
         Introspector introspector = new Introspector(clazz);
 
@@ -172,7 +175,7 @@ class Bean extends BeanRef implements Be
             }
 
             if (ref == null && value == null) {
-                BeanRef template = new BeanRef(parameterTypes[i], annotations);
+                BeanTemplate template = new BeanTemplate(parameterTypes[i], annotations);
                 BeanRef bean = blueprintRegistry.getMatching(template);
                 if (bean != null) {
                     ref = bean.id;
@@ -262,7 +265,7 @@ class Bean extends BeanRef implements Be
     }
 
     BeanRef toBeanRef() {
-        return this;
+        return new BeanRef(clazz, id, clazz.getAnnotations());
     }
 
     static String getBeanName(Class<?> clazz) {

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanFromFactory.java
Sun Feb  5 20:16:15 2017
@@ -28,11 +28,11 @@ import java.lang.reflect.Method;
 class BeanFromFactory extends Bean {
     private final Method producingMethod;
 
-    BeanFromFactory(Class<?> clazz, BeanRef factoryBean, Method factoryMethod, ContextEnricher
contextEnricher) {
+    BeanFromFactory(Class<?> clazz, Bean factoryBean, Method factoryMethod, ContextEnricher
contextEnricher) {
         this(clazz, null, factoryBean, factoryMethod, contextEnricher);
     }
 
-    BeanFromFactory(Class<?> clazz, String id, BeanRef factoryBean, Method factoryMethod,
ContextEnricher contextEnricher) {
+    BeanFromFactory(Class<?> clazz, String id, Bean factoryBean, Method factoryMethod,
ContextEnricher contextEnricher) {
         super(clazz, contextEnricher);
         if (id != null) {
             this.id = id;

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
Sun Feb  5 20:16:15 2017
@@ -18,60 +18,21 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
-import org.apache.aries.blueprint.plugin.handlers.Handlers;
-
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashSet;
 import java.util.Set;
 
 class BeanRef implements Comparable<BeanRef> {
-    public String id;
-    public final Class<?> clazz;
-    private final Set<Annotation> qualifiers = new HashSet<>();
+    final String id;
+    private final Class<?> clazz;
+    private final Set<Annotation> qualifiers;
 
     BeanRef(Class<?> clazz, String id, Annotation[] qualifiers) {
         this.clazz = clazz;
         this.id = id;
-        setQualifiersFromAnnotations(qualifiers);
-    }
-
-    BeanRef(Class<?> clazz, Annotation[] qualifiers) {
-        this.clazz = clazz;
-        setQualifiersFromAnnotations(qualifiers);
-    }
-
-    BeanRef(Field field) {
-        this(field.getType(), field.getAnnotations());
-    }
-
-    BeanRef(Method method) {
-        this(method.getParameterTypes()[0], method.getAnnotations());
-    }
-
-    private void setQualifiersFromAnnotations(Annotation[] annotations) {
-        for (Annotation ann : annotations) {
-            if (isQualifier(ann) != null) {
-                this.qualifiers.add(ann);
-            }
-        }
+        this.qualifiers = QualifierHelper.getQualifiers(qualifiers);
     }
 
-    private Object isQualifier(Annotation ann) {
-        for (Class<? extends Annotation> qualifingAnnotationClass : Handlers.QUALIFING_ANNOTATION_CLASSES)
{
-            Object annotation = ann.annotationType().getAnnotation(qualifingAnnotationClass);
-            if (annotation != null) {
-                return annotation;
-            }
-        }
-        return null;
-    }
-
-    boolean matches(BeanRef template) {
-        if (template.id != null) {
-            return template.id.equals(id);
-        }
+    boolean matches(BeanTemplate template) {
         boolean assignable = template.clazz.isAssignableFrom(this.clazz);
         return assignable && qualifiers.containsAll(template.qualifiers);
     }
@@ -81,24 +42,4 @@ class BeanRef implements Comparable<Bean
         return this.id.compareTo(other.id);
     }
 
-    @Override
-    public String toString() {
-        return this.clazz.getSimpleName() + "(" + this.id + ")";
-    }
-
-    public boolean equals(Object o) {
-        if (o == this) return true;
-        if (!(o instanceof BeanRef)) return false;
-        final BeanRef other = (BeanRef) o;
-        if (!other.canEqual(this)) return false;
-        return this.id == null ? other.id == null : this.id.equals(other.id);
-    }
-
-    public int hashCode() {
-        return 1 * 59 + (this.id == null ? 0 : this.id.hashCode());
-    }
-
-    protected boolean canEqual(Object other) {
-        return other instanceof BeanRef;
-    }
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRefStore.java
Sun Feb  5 20:16:15 2017
@@ -15,7 +15,7 @@ class BeanRefStore {
         return reg;
     }
 
-    BeanRef getMatching(BeanRef template) {
+    BeanRef getMatching(BeanTemplate template) {
         for (BeanRef bean : reg) {
             if (bean.matches(template)) {
                 return bean;

Copied: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java
(from r1781787, aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java?p2=aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java&p1=aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java&r1=1781787&r2=1781793&rev=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanTemplate.java
Sun Feb  5 20:16:15 2017
@@ -18,87 +18,26 @@
  */
 package org.apache.aries.blueprint.plugin.model;
 
-import org.apache.aries.blueprint.plugin.handlers.Handlers;
-
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.HashSet;
 import java.util.Set;
 
-class BeanRef implements Comparable<BeanRef> {
-    public String id;
-    public final Class<?> clazz;
-    private final Set<Annotation> qualifiers = new HashSet<>();
+class BeanTemplate {
+    final Class<?> clazz;
+    final Set<Annotation> qualifiers;
 
-    BeanRef(Class<?> clazz, String id, Annotation[] qualifiers) {
+    BeanTemplate(Class<?> clazz, Annotation[] qualifiers) {
         this.clazz = clazz;
-        this.id = id;
-        setQualifiersFromAnnotations(qualifiers);
+        this.qualifiers = QualifierHelper.getQualifiers(qualifiers);
     }
 
-    BeanRef(Class<?> clazz, Annotation[] qualifiers) {
-        this.clazz = clazz;
-        setQualifiersFromAnnotations(qualifiers);
-    }
-
-    BeanRef(Field field) {
+    BeanTemplate(Field field) {
         this(field.getType(), field.getAnnotations());
     }
 
-    BeanRef(Method method) {
+    BeanTemplate(Method method) {
         this(method.getParameterTypes()[0], method.getAnnotations());
     }
 
-    private void setQualifiersFromAnnotations(Annotation[] annotations) {
-        for (Annotation ann : annotations) {
-            if (isQualifier(ann) != null) {
-                this.qualifiers.add(ann);
-            }
-        }
-    }
-
-    private Object isQualifier(Annotation ann) {
-        for (Class<? extends Annotation> qualifingAnnotationClass : Handlers.QUALIFING_ANNOTATION_CLASSES)
{
-            Object annotation = ann.annotationType().getAnnotation(qualifingAnnotationClass);
-            if (annotation != null) {
-                return annotation;
-            }
-        }
-        return null;
-    }
-
-    boolean matches(BeanRef template) {
-        if (template.id != null) {
-            return template.id.equals(id);
-        }
-        boolean assignable = template.clazz.isAssignableFrom(this.clazz);
-        return assignable && qualifiers.containsAll(template.qualifiers);
-    }
-
-    @Override
-    public int compareTo(BeanRef other) {
-        return this.id.compareTo(other.id);
-    }
-
-    @Override
-    public String toString() {
-        return this.clazz.getSimpleName() + "(" + this.id + ")";
-    }
-
-    public boolean equals(Object o) {
-        if (o == this) return true;
-        if (!(o instanceof BeanRef)) return false;
-        final BeanRef other = (BeanRef) o;
-        if (!other.canEqual(this)) return false;
-        return this.id == null ? other.id == null : this.id.equals(other.id);
-    }
-
-    public int hashCode() {
-        return 1 * 59 + (this.id == null ? 0 : this.id.hashCode());
-    }
-
-    protected boolean canEqual(Object other) {
-        return other instanceof BeanRef;
-    }
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
Sun Feb  5 20:16:15 2017
@@ -114,7 +114,7 @@ public class Blueprint implements Bluepr
         }
     }
 
-    public BeanRef getMatching(BeanRef template) {
+    public BeanRef getMatching(BeanTemplate template) {
         return beanRefStore.getMatching(template);
     }
 

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BlueprintRegistry.java
Sun Feb  5 20:16:15 2017
@@ -21,5 +21,5 @@ package org.apache.aries.blueprint.plugi
 import org.apache.aries.blueprint.plugin.spi.ContextEnricher;
 
 interface BlueprintRegistry extends ContextEnricher {
-    BeanRef getMatching(BeanRef template);
+    BeanRef getMatching(BeanTemplate template);
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
Sun Feb  5 20:16:15 2017
@@ -65,7 +65,7 @@ class Property implements Comparable<Pro
             if (ref != null) {
                 return new Property(field.getName(), ref, null, true);
             }
-            BeanRef matching = blueprintRegistry.getMatching(new BeanRef(field));
+            BeanRef matching = blueprintRegistry.getMatching(new BeanTemplate(field));
             ref = (matching == null) ? getDefaultRefName(field) : matching.id;
             return new Property(field.getName(), ref, null, true);
         } else {
@@ -118,9 +118,9 @@ class Property implements Comparable<Pro
                 return new Property(propertyName, ref, null, false);
             }
 
-            BeanRef beanRef = new BeanRef(method);
-            BeanRef matching = blueprintRegistry.getMatching(beanRef);
-            ref = (matching == null) ? beanRef.id : matching.id;
+            BeanTemplate template = new BeanTemplate(method);
+            BeanRef matching = blueprintRegistry.getMatching(template);
+            ref = (matching == null) ? Bean.getBeanName(method.getParameterTypes()[0]) :
matching.id;
             return new Property(propertyName, ref, null, false);
         }
 

Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java?rev=1781793&view=auto
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java
(added)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/QualifierHelper.java
Sun Feb  5 20:16:15 2017
@@ -0,0 +1,48 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.aries.blueprint.plugin.model;
+
+import org.apache.aries.blueprint.plugin.handlers.Handlers;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+class QualifierHelper {
+    static Set<Annotation> getQualifiers(Annotation[] annotations) {
+        final Set<Annotation> qualifiers = new HashSet<>();
+        for (Annotation ann : annotations) {
+            if (isQualifier(ann) != null) {
+                qualifiers.add(ann);
+            }
+        }
+        return qualifiers;
+    }
+
+    private static Object isQualifier(Annotation ann) {
+        for (Class<? extends Annotation> qualifingAnnotationClass : Handlers.QUALIFING_ANNOTATION_CLASSES)
{
+            Object annotation = ann.annotationType().getAnnotation(qualifingAnnotationClass);
+            if (annotation != null) {
+                return annotation;
+            }
+        }
+        return null;
+    }
+
+}

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java?rev=1781793&r1=1781792&r2=1781793&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BlueprintTest.java
Sun Feb  5 20:16:15 2017
@@ -71,7 +71,7 @@ public class BlueprintTest {
 
     private void assertSpecialRef(String expectedId, Class<?> clazz) {
         Blueprint blueprint = new Blueprint(blueprintConfiguration);
-        BeanRef ref = blueprint.getMatching(new BeanRef(clazz, new Annotation[]{}));
+        BeanRef ref = blueprint.getMatching(new BeanTemplate(clazz, new Annotation[]{}));
         assertEquals(expectedId, ref.id);
     }
 
@@ -83,13 +83,4 @@ public class BlueprintTest {
         assertSpecialRef("blueprintConverter", Converter.class);
     }
 
-    @Test
-    public void testProduced() throws NoSuchFieldException, SecurityException {
-        Blueprint blueprint = new Blueprint(blueprintConfiguration, MyFactoryBean.class);
-        BeanFromFactory matching = (BeanFromFactory) blueprint.getMatching(new BeanRef(MyProduced.class,
new Annotation[]{}));
-        Assert.assertEquals(MyProduced.class, matching.clazz);
-        Assert.assertEquals("myFactoryBean", matching.attributes.get("factory-ref"));
-        Assert.assertEquals("create", matching.attributes.get("factory-method"));
-    }
-
 }



Mime
View raw message