You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2009/04/20 17:40:10 UTC
svn commit: r766732 - in /geronimo/sandbox/blueprint/blueprint-core/src:
main/java/org/apache/geronimo/blueprint/context/
test/java/org/apache/geronimo/blueprint/ test/resources/
Author: gawor
Date: Mon Apr 20 15:40:09 2009
New Revision: 766732
URL: http://svn.apache.org/viewvc?rev=766732&view=rev
Log:
get prototype scope working
Added:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java (with props)
Modified:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Instanciator.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ScopedRepository.java
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml
Added: 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=766732&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java Mon Apr 20 15:40:09 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.geronimo.blueprint.context;
+
+import org.apache.xbean.recipe.ObjectRecipe;
+
+/**
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BlueprintObjectRecipe extends ObjectRecipe {
+
+ private boolean keepRecipe = false;
+
+ public BlueprintObjectRecipe(String typeName) {
+ super(typeName);
+ }
+
+ public void setKeepRecipe(boolean keepRecipe) {
+ this.keepRecipe = keepRecipe;
+ }
+
+ public boolean getKeepRecipe() {
+ return keepRecipe;
+ }
+
+}
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=766732&r1=766731&r2=766732&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 Mon Apr 20 15:40:09 2009
@@ -128,18 +128,20 @@
private Recipe createRecipe(ComponentMetadata component) throws Exception {
if (component instanceof LocalComponentMetadata) {
LocalComponentMetadata local = (LocalComponentMetadata) component;
- ObjectRecipe recipe = new BundleObjectRecipe(local.getClassName());
+ BundleObjectRecipe recipe = new BundleObjectRecipe(local.getClassName());
recipe.allow(Option.PRIVATE_PROPERTIES);
recipe.setName(component.getName());
for (PropertyInjectionMetadata property : (Collection<PropertyInjectionMetadata>) local.getPropertyInjectionMetadata()) {
Object value = getValue(property.getValue(), null);
recipe.setProperty(property.getName(), value);
}
+ if (LocalComponentMetadata.SCOPE_PROTOTYPE.equals(local.getScope())) {
+ recipe.setKeepRecipe(true);
+ }
// TODO: constructor args
// TODO: init-method
// TODO: destroy-method
// TODO: lazy
- // TODO: scope
// TODO: factory-method
// TODO: factory-component
return recipe;
@@ -308,7 +310,7 @@
return clazz;
}
- private class BundleObjectRecipe extends ObjectRecipe {
+ private class BundleObjectRecipe extends BlueprintObjectRecipe {
String typeName;
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ScopedRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ScopedRepository.java?rev=766732&r1=766731&r2=766732&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ScopedRepository.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ScopedRepository.java Mon Apr 20 15:40:09 2009
@@ -24,6 +24,12 @@
import org.apache.xbean.recipe.Recipe;
import org.apache.xbean.recipe.Repository;
+/**
+ * By default in object repository Recipes are replaced with objects that were creating using the given Recipe.
+ * That essentially implements the 'singleton' scope. For 'prototype' scope we do not allow certain Recipes to
+ * be replaced with resulting objects in the repository. That ensures that a new instance of a object is created
+ * for such Recipes during graph instantiation.
+ */
public class ScopedRepository implements Repository {
private SortedMap<String, Object> instances;
@@ -49,9 +55,17 @@
}
public void add(String name, Object instance) {
- if (instances.containsKey(name) && !(instances.get(name) instanceof Recipe)) {
- throw new ConstructionException("Name " + name + " is already registered to instance " + instance);
+ Object existingObj = instances.get(name);
+ if (existingObj != null) {
+ if (existingObj instanceof BlueprintObjectRecipe) {
+ if ( ((BlueprintObjectRecipe) existingObj ).getKeepRecipe()) {
+ return;
+ }
+ } else if (!(existingObj instanceof Recipe)) {
+ throw new ConstructionException("Name " + name + " is already registered to instance " + instance);
+ }
}
+
instances.put(name, instance);
}
}
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=766732&r1=766731&r2=766732&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 Mon Apr 20 15:40:09 2009
@@ -44,6 +44,8 @@
assertNotNull(obj1);
assertTrue(obj1 instanceof PojoA);
PojoA pojoa = (PojoA) obj1;
+ // test singleton scope
+ assertTrue(obj1 == graph.create("pojoA"));
Object obj2 = graph.create("pojoB");
assertNotNull(obj2);
@@ -90,7 +92,11 @@
Object obj3 = graph.create("service1");
assertNotNull(obj3);
- assertTrue(obj3 instanceof ServiceRegistration);
+ assertTrue(obj3 instanceof ServiceRegistration);
+
+ Object obj4 = graph.create("pojoC");
+ assertNotNull(obj4);
+ assertTrue(obj4 != graph.create("pojoC"));
}
private static class TestInstanciator extends Instanciator {
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml?rev=766732&r1=766731&r2=766732&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml Mon Apr 20 15:40:09 2009
@@ -17,6 +17,10 @@
</service-properties>
</service>
+ <component id="pojoC" class="org.apache.geronimo.blueprint.pojos.PojoB" scope = "prototype">
+ <property name="uri" value="urn:myuri" />
+ </component>
+
<component id="pojoB" class="org.apache.geronimo.blueprint.pojos.PojoB">
<property name="uri" value="urn:myuri" />
</component>