geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r767866 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ test/java/org/apache/geronimo/blueprint/ test/java/org/apache/geronimo/blueprint/pojos/ test/resources/
Date Thu, 23 Apr 2009 09:17:31 GMT
Author: gnodet
Date: Thu Apr 23 09:17:29 2009
New Revision: 767866

URL: http://svn.apache.org/viewvc?rev=767866&view=rev
Log:
Handle the depends-on attribute

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml
      - copied, changed from r767576, geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java?rev=767866&r1=767865&r2=767866&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
Thu Apr 23 09:17:29 2009
@@ -21,9 +21,12 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.List;
 
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.ObjectRecipe;
+import org.apache.xbean.recipe.Recipe;
+import org.apache.xbean.recipe.ReferenceRecipe;
 import org.apache.geronimo.blueprint.Destroyable;
 
 /**
@@ -37,6 +40,7 @@
     private boolean keepRecipe = false;
     private Method initMethod;
     private Method destroyMethod;
+    private List<String> explicitDependencies;
     
     public BlueprintObjectRecipe(BlueprintContextImpl blueprintContext, Class typeName) {
         super(typeName);
@@ -66,7 +70,26 @@
     public Method getDestroyMethod() {
         return destroyMethod;
     }
-        
+
+    public List<String> getExplicitDependencies() {
+        return explicitDependencies;
+    }
+
+    public void setExplicitDependencies(List<String> explicitDependencies) {
+        this.explicitDependencies = explicitDependencies;
+    }
+
+    @Override
+    public List<Recipe> getNestedRecipes() {
+        List<Recipe> recipes = super.getNestedRecipes();
+        if (explicitDependencies != null) {
+            for (String name : explicitDependencies) {
+                recipes.add(new ReferenceRecipe(name));
+            }
+        }
+        return recipes;
+    }
+
     @Override
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
         final Object obj = super.internalCreate(expectedType, lazyRefAllowed);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java?rev=767866&r1=767865&r2=767866&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
Thu Apr 23 09:17:29 2009
@@ -179,9 +179,10 @@
     }
 
     private ObjectRecipe createServiceRecipe(ServiceMetadata serviceExport) throws Exception
{
-        ObjectRecipe recipe = new ObjectRecipe(ServiceRegistrationProxy.class);
+        BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, ServiceRegistrationProxy.class);
         recipe.allow(Option.PRIVATE_PROPERTIES);
         recipe.setName(serviceExport.getId());
+        recipe.setExplicitDependencies(serviceExport.getExplicitDependencies());
         recipe.setProperty("moduleContext", blueprintContext);
         BeanMetadata exportedComponent = getLocalServiceComponent(serviceExport.getServiceComponent());
         if (exportedComponent != null && BeanMetadata.SCOPE_BUNDLE.equals(exportedComponent.getScope()))
{
@@ -211,6 +212,7 @@
         BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, loadClass(local.getClassName()));
         recipe.allow(Option.PRIVATE_PROPERTIES);
         recipe.setName(local.getId());
+        recipe.setExplicitDependencies(local.getExplicitDependencies());
         for (BeanProperty property : local.getProperties()) {
             Object value = getValue(property.getValue(), null);
             recipe.setProperty(property.getName(), value);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java?rev=767866&r1=767865&r2=767866&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
Thu Apr 23 09:17:29 2009
@@ -20,12 +20,15 @@
 
 import java.math.BigInteger;
 import java.net.URI;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.geronimo.blueprint.context.Instanciator;
 import org.apache.geronimo.blueprint.convert.ConversionServiceImpl;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.geronimo.blueprint.pojos.PojoA;
 import org.apache.geronimo.blueprint.pojos.PojoB;
+import org.apache.geronimo.blueprint.pojos.BeanC;
+import org.apache.geronimo.blueprint.pojos.BeanD;
 import org.apache.xbean.recipe.ObjectGraph;
 import org.apache.xbean.recipe.Repository;
 import org.osgi.framework.ServiceRegistration;
@@ -110,6 +113,29 @@
         assertTrue(obj4 != graph.create("pojoC"));
     }
 
+    public void testDependsOn() throws Exception {
+        final AtomicBoolean initC = new AtomicBoolean();
+        final AtomicBoolean initD = new AtomicBoolean();
+        BeanC.run = new Runnable() {
+            public void run() {
+                assertTrue(initD.get());
+                initC.set(true);
+            }
+        };
+        BeanD.run = new Runnable() {
+            public void run() {
+                assertFalse(initC.get());
+                initD.set(true);
+            }
+        };
+
+        ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml");
+        Instanciator i = new TestInstanciator(registry);
+        Repository repository = i.createRepository();
+        ObjectGraph graph = new ObjectGraph(repository);
+        graph.createAll("c", "d");
+    }
+
     private static class TestInstanciator extends Instanciator {
         ConversionServiceImpl conversionService = new ConversionServiceImpl();
         ComponentDefinitionRegistryImpl registry;

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java?rev=767866&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
Thu Apr 23 09:17:29 2009
@@ -0,0 +1,10 @@
+package org.apache.geronimo.blueprint.pojos;
+
+public class BeanC {
+
+    public static Runnable run;
+
+    public void init() {
+        run.run();
+    }
+}

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java?rev=767866&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
Thu Apr 23 09:17:29 2009
@@ -0,0 +1,11 @@
+package org.apache.geronimo.blueprint.pojos;
+
+public class BeanD {
+
+    public static Runnable run;
+
+    public void init() {
+        run.run();
+    }
+
+}

Copied: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml (from
r767576, geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml?p2=geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml&p1=geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml&r1=767576&r2=767866&rev=767866&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml Thu Apr
23 09:17:29 2009
@@ -4,37 +4,8 @@
             xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 ../../main/resources/org/apache/geronimo/blueprint/blueprint.xsd"
             default-init-method="init" default-destroy-method="destroy">
 
-    <bean id="pojoA" class="org.apache.geronimo.blueprint.pojos.PojoA" depends-on=" pojoB
, pojoC ,">
-        <argument value="val0"/>
-        <argument ref="val1" />
-        <argument>
-            <description>null value</description>
-            <null/>
-        </argument>
-        <argument type="java.lang.String">
-            <value>val3</value>
-        </argument>
-        <argument>
-            <array>
-                <value>val0</value>
-                <bean class="java.lang.String"/>
-                <null/>
-            </array>
-        </argument>
-        <argument>
-            <ref component="pojoB"/>
-        </argument>
-        <property name="prop1" ref="pojoB"/>
-        <property name="prop2" value="value" />
-        <property name="prop3">
-            <description>property</description>
-            <value>val</value>
-        </property>
-    </bean>
-    
-    <bean id="pojoB" class="org.apache.geronimo.blueprint.pojos.PojoA" init-method="initPojo"
destroy-method="" >
-        <argument index = "1" value="val0"/>
-        <argument index = "0" ref="val1" />
-    </bean>
-    
+    <bean id="c" class="org.apache.geronimo.blueprint.pojos.BeanC" depends-on="d" init-method="init"/>
+
+    <bean id="d" class="org.apache.geronimo.blueprint.pojos.BeanD" init-method="init"/>
+
 </blueprint>
\ No newline at end of file



Mime
View raw message