geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r790110 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/container/ main/java/org/apache/geronimo/blueprint/di/ main/java/org/apache/geronimo/blueprint/namespace/ main/java/org/apache/geronimo/blu...
Date Wed, 01 Jul 2009 10:48:23 GMT
Author: gnodet
Date: Wed Jul  1 10:48:23 2009
New Revision: 790110

URL: http://svn.apache.org/viewvc?rev=790110&view=rev
Log:
Refactor support for environment managers, add a few validation tests

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/EnvironmentRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/EnvironmentMetadataImpl.java
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Repository.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/AbstractBlueprintTest.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/TestBlueprintContainer.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
Wed Jul  1 10:48:23 2009
@@ -40,6 +40,7 @@
 import org.apache.geronimo.blueprint.ExtendedServiceReferenceMetadata;
 import org.apache.geronimo.blueprint.di.AbstractRecipe;
 import org.apache.geronimo.blueprint.di.Recipe;
+import org.apache.geronimo.blueprint.di.CollectionRecipe;
 import org.apache.geronimo.blueprint.utils.BundleDelegatingClassLoader;
 import org.apache.geronimo.blueprint.utils.ReflectionUtils;
 import org.osgi.framework.Constants;
@@ -72,7 +73,7 @@
 
     protected final ExtendedBlueprintContainer blueprintContainer;
     protected final ServiceReferenceMetadata metadata;
-    protected final Recipe listenersRecipe;
+    protected final CollectionRecipe listenersRecipe;
     protected final List<Recipe> explicitDependencies;
     protected final ClassLoader proxyClassLoader;
     protected final boolean optional;
@@ -91,7 +92,7 @@
     protected AbstractServiceReferenceRecipe(String name,
                                              ExtendedBlueprintContainer blueprintContainer,
                                              ServiceReferenceMetadata metadata,
-                                             Recipe listenersRecipe,
+                                             CollectionRecipe listenersRecipe,
                                              List<Recipe> explicitDependencies) {
         super(name);
         this.prototype = false;
@@ -111,6 +112,10 @@
         this.filter = createOsgiFilter(metadata);
     }
 
+    public CollectionRecipe getListenersRecipe() {
+        return listenersRecipe;
+    }
+
     public void start(SatisfactionListener listener) {
         if (listener == null) throw new NullPointerException("satisfactionListener is null");
         if (started.compareAndSet(false, true)) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintContainerImpl.java
Wed Jul  1 10:48:23 2009
@@ -43,6 +43,7 @@
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.apache.geronimo.blueprint.NamespaceHandler;
 import org.apache.geronimo.blueprint.Processor;
+import org.apache.geronimo.blueprint.reflect.EnvironmentMetadataImpl;
 import org.apache.geronimo.blueprint.di.Recipe;
 import org.apache.geronimo.blueprint.di.Repository;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
@@ -239,6 +240,10 @@
                             eventDispatcher.blueprintEvent(new BlueprintEvent(BlueprintEvent.GRACE_PERIOD,
getBundleContext().getBundle(), getExtenderBundle(), missing.toArray(new String[missing.size()])));
                             return;
                         }
+                        componentDefinitionRegistry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintContainer",
this));
+                        componentDefinitionRegistry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintBundle",
bundleContext.getBundle()));
+                        componentDefinitionRegistry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintBundleContext",
bundleContext));
+                        componentDefinitionRegistry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintConverter",
converter));
                         parser.populate(handlers, componentDefinitionRegistry);
                         state = State.Populated;
                         break;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java
Wed Jul  1 10:48:23 2009
@@ -182,10 +182,15 @@
     private boolean isCompatible(Bundle bundle) {
         // Check compatibility
         boolean compatible;
-        try {
-            Class clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
-            compatible = (clazz == BlueprintContainer.class);
-        } catch (ClassNotFoundException e) {
+        if (bundle.getState() == Bundle.ACTIVE) {
+            try {
+                Class clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
+                compatible = (clazz == BlueprintContainer.class);
+            } catch (ClassNotFoundException e) {
+                compatible = true;
+            }
+        } else {
+            // for lazy bundle, we can't load the class, so just assume it's ok
             compatible = true;
         }
         return compatible;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintRepository.java
Wed Jul  1 10:48:23 2009
@@ -38,6 +38,7 @@
 import org.apache.geronimo.blueprint.di.Recipe;
 import org.apache.geronimo.blueprint.di.RefRecipe;
 import org.apache.geronimo.blueprint.di.Repository;
+import org.apache.geronimo.blueprint.di.CollectionRecipe;
 import org.osgi.service.blueprint.container.ReifiedType;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.osgi.service.blueprint.container.NoSuchComponentException;
@@ -57,11 +58,6 @@
     private final ExtendedBlueprintContainer blueprintContainer;
 
     /**
-     * Contains environment objects
-     */
-    private final Map<String, Object> defaults = new ConcurrentHashMap<String, Object>();
-
-    /**
      * Contains object recipes
      */
     private final Map<String, Recipe> recipes = new ConcurrentHashMap<String, Recipe>();
@@ -104,26 +100,13 @@
         return recipes.get(name);
     }
 
-    public Object getDefault(String name) {
-        return defaults.get(name);
-    }
-
     public Set<String> getNames() {
         Set<String> names = new HashSet<String>();
         names.addAll(recipes.keySet());
         names.addAll(instances.keySet());
-        names.addAll(defaults.keySet());
         return names;
     }
 
-    public void putDefault(String name, Object instance) {
-        if (instance != null) {
-            defaults.put(name, instance);
-        } else {
-            defaults.remove(name);
-        }
-    }
-
     public void putRecipe(String name, Recipe recipe) {
         if (instances.get(name) != null) {
             throw new ComponentDefinitionException("Name " + name + " is already registered
to instance " + instances.get(name));
@@ -214,25 +197,63 @@
             }
         }
         if (instance == null) {
-            instance = getDefault(name);
-        }
-        if (instance == null) {
             throw new NoSuchComponentException(name);
         }
         return instance;
     }
 
-    public void checkReferences() {
+    public void validate() {
         for (Recipe recipe : getAllRecipes()) {
+            // Check that references are satisfied
             String ref = null;
             if (recipe instanceof RefRecipe) {
                 ref = ((RefRecipe) recipe).getIdRef();
             } else if (recipe instanceof IdRefRecipe) {
                 ref = ((IdRefRecipe) recipe).getIdRef();
             }
-            if (ref != null && getRecipe(ref) == null && getDefault(ref)
== null) {
+            if (ref != null && getRecipe(ref) == null) {
                 throw new ComponentDefinitionException("Unresolved ref/idref to component:
" + ref);
             }
+            // Check service
+            if (recipe instanceof ServiceRecipe) {
+                Recipe r = ((ServiceRecipe) recipe).getServiceRecipe();
+                if (r instanceof RefRecipe) {
+                    r = getRecipe(((RefRecipe) r).getIdRef());
+                }
+                if (r instanceof ServiceRecipe) {
+                    throw new ComponentDefinitionException("The target for a <service>
element must not be <service> element");
+                }
+                if (r instanceof ReferenceListRecipe) {
+                    throw new ComponentDefinitionException("The target for a <service>
element must not be <reference-list> element");
+                }
+                CollectionRecipe listeners = ((ServiceRecipe) recipe).getListenersRecipe();
+                for (Recipe l : listeners.getDependencies()) {
+                    if (l instanceof RefRecipe) {
+                        l = getRecipe(((RefRecipe) l).getIdRef());
+                    }
+                    if (l instanceof ServiceRecipe) {
+                        throw new ComponentDefinitionException("The target for a <registration-listener>
element must not be <service> element");
+                    }
+                    if (l instanceof ReferenceListRecipe) {
+                        throw new ComponentDefinitionException("The target for a <registration-listener>
element must not be <reference-list> element");
+                    }
+                }
+            }
+            // Check references
+            if (recipe instanceof AbstractServiceReferenceRecipe) {
+                CollectionRecipe listeners = ((AbstractServiceReferenceRecipe) recipe).getListenersRecipe();
+                for (Recipe l : listeners.getDependencies()) {
+                    if (l instanceof RefRecipe) {
+                        l = getRecipe(((RefRecipe) l).getIdRef());
+                    }
+                    if (l instanceof ServiceRecipe) {
+                        throw new ComponentDefinitionException("The target for a <reference-listener>
element must not be <service> element");
+                    }
+                    if (l instanceof ReferenceListRecipe) {
+                        throw new ComponentDefinitionException("The target for a <reference-listener>
element must not be <reference-list> element");
+                    }
+                }
+            }
         }
     }
 
@@ -284,8 +305,7 @@
 
     public boolean containsObject(String name) {
         return getInstance(name) != null
-                || getRecipe(name) != null
-                || getDefault(name) != null;
+                || getRecipe(name) != null;
     }
 
     public Object getObject(String name) {
@@ -293,9 +313,6 @@
         if (object == null) {
             object = getRecipe(name);
         }
-        if (object == null) {
-            object = getDefault(name);
-        }
         return object;
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
Wed Jul  1 10:48:23 2009
@@ -136,7 +136,6 @@
     public static final String NAME_ATTRIBUTE = "name";
     public static final String ID_ATTRIBUTE = "id";
     public static final String CLASS_ATTRIBUTE = "class";
-    public static final String PARENT_ATTRIBUTE = "parent";
     public static final String INDEX_ATTRIBUTE = "index";
     public static final String TYPE_ATTRIBUTE = "type";
     public static final String VALUE_ATTRIBUTE = "value";
@@ -167,10 +166,6 @@
     public static final String FACTORY_REF_ATTRIBUTE = "factory-ref";
     public static final String FACTORY_METHOD_ATTRIBUTE = "factory-method";
 
-    public static final String BOOLEAN_DEFAULT = "default";
-    public static final String BOOLEAN_TRUE = "true";
-    public static final String BOOLEAN_FALSE = "false";
-
     public static final String AUTO_EXPORT_DISABLED = "disabled";
     public static final String AUTO_EXPORT_INTERFACES = "interfaces";
     public static final String AUTO_EXPORT_CLASS_HIERARCHY = "class-hierarchy";
@@ -492,6 +487,9 @@
         if (metadata.getFactoryComponent() != null && metadata.getFactoryMethod()
== null) {
             throw new ComponentDefinitionException("factory-method is required when factory-component
is set");
         }
+        if (metadata.getScope().equals(BeanMetadata.SCOPE_PROTOTYPE) && metadata.getDestroyMethod()
!= null) {
+            throw new ComponentDefinitionException("destroy-method must not be set for a
<bean> with a prototype scope");
+        }
 
         // Parse elements
         NodeList nl = element.getChildNodes();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RecipeBuilder.java
Wed Jul  1 10:48:23 2009
@@ -35,10 +35,11 @@
 import org.apache.geronimo.blueprint.di.MapRecipe;
 import org.apache.geronimo.blueprint.di.Recipe;
 import org.apache.geronimo.blueprint.di.RefRecipe;
-import org.apache.geronimo.blueprint.di.Repository;
 import org.apache.geronimo.blueprint.di.ValueRecipe;
+import org.apache.geronimo.blueprint.di.EnvironmentRecipe;
 import org.apache.geronimo.blueprint.mutable.MutableMapMetadata;
 import org.apache.geronimo.blueprint.reflect.MetadataUtil;
+import org.apache.geronimo.blueprint.reflect.EnvironmentMetadataImpl;
 import org.osgi.service.blueprint.reflect.BeanArgument;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
 import org.osgi.service.blueprint.reflect.BeanProperty;
@@ -76,25 +77,15 @@
         this.registry = blueprintContainer.getComponentDefinitionRegistry();
     }
     
-    private void addBuiltinComponents(Repository repository) {
-        if (blueprintContainer != null) {
-            repository.putDefault("blueprintContainer", blueprintContainer);
-            repository.putDefault("blueprintBundle", blueprintContainer.getBundleContext().getBundle());
-            repository.putDefault("blueprintBundleContext", blueprintContainer.getBundleContext());
-            repository.putDefault("blueprintConverter", blueprintContainer.getConverter());
-        }
-    }
-    
     public BlueprintRepository createRepository() {
         BlueprintRepository repository = new BlueprintRepository(blueprintContainer);
-        addBuiltinComponents(repository);
         // Create component recipes
         for (String name : registry.getComponentDefinitionNames()) {
             ComponentMetadata component = registry.getComponentDefinition(name);
             Recipe recipe = createRecipe(component);
             repository.putRecipe(recipe.getName(), recipe);
         }
-        repository.checkReferences();
+        repository.validate();
         return repository;
     }
 
@@ -106,13 +97,20 @@
         } else if (component instanceof ReferenceMetadata) {
             return createReferenceRecipe((ReferenceMetadata) component);
         } else if (component instanceof ReferenceListMetadata) {
-            return createRefCollectionRecipe((ReferenceListMetadata) component);
+            return createReferenceListRecipe((ReferenceListMetadata) component);
+        } else if (component instanceof EnvironmentMetadataImpl) {
+            return createEnvironmentRecipe((EnvironmentMetadataImpl) component);
         } else {
             throw new IllegalStateException("Unsupported component type " + component.getClass());
         }
     }
 
-    private Recipe createRefCollectionRecipe(ReferenceListMetadata metadata) {
+    private Recipe createEnvironmentRecipe(EnvironmentMetadataImpl environmentMetadata) {
+        return new EnvironmentRecipe(environmentMetadata.getId(), environmentMetadata.getObject());
+    }
+
+
+    private Recipe createReferenceListRecipe(ReferenceListMetadata metadata) {
         CollectionRecipe listenersRecipe = null;
         if (metadata.getReferenceListeners() != null) {
             listenersRecipe = new CollectionRecipe(getName(null), ArrayList.class);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceListRecipe.java
Wed Jul  1 10:48:23 2009
@@ -34,6 +34,7 @@
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.apache.geronimo.blueprint.ExtendedReferenceListMetadata;
 import org.apache.geronimo.blueprint.di.Recipe;
+import org.apache.geronimo.blueprint.di.CollectionRecipe;
 import org.apache.geronimo.blueprint.utils.DynamicCollection;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -62,7 +63,7 @@
     public ReferenceListRecipe(String name,
                          ExtendedBlueprintContainer blueprintContainer,
                          ReferenceListMetadata metadata,
-                         Recipe listenersRecipe,
+                         CollectionRecipe listenersRecipe,
                          List<Recipe> explicitDependencies) {
         super(name, blueprintContainer, metadata, listenersRecipe, explicitDependencies);
         this.metadata = metadata;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
Wed Jul  1 10:48:23 2009
@@ -24,6 +24,7 @@
 
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.apache.geronimo.blueprint.di.Recipe;
+import org.apache.geronimo.blueprint.di.CollectionRecipe;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.blueprint.container.BlueprintEvent;
 import org.osgi.service.blueprint.container.ReifiedType;
@@ -58,7 +59,7 @@
     public ReferenceRecipe(String name,
                            ExtendedBlueprintContainer blueprintContainer,
                            ReferenceMetadata metadata,
-                           Recipe listenersRecipe,
+                           CollectionRecipe listenersRecipe,
                            List<Recipe> explicitDependencies) {
         super(name, blueprintContainer, metadata, listenersRecipe, explicitDependencies);
         this.metadata = metadata;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ServiceRecipe.java
Wed Jul  1 10:48:23 2009
@@ -93,6 +93,14 @@
         this.prototypeService = isPrototypeService(metadata.getServiceComponent());
     }
 
+    public Recipe getServiceRecipe() {
+        return serviceRecipe;
+    }
+
+    public CollectionRecipe getListenersRecipe() {
+        return listenersRecipe;
+    }
+
     public List<Recipe> getDependencies() {
         List<Recipe> recipes = new ArrayList<Recipe>();
         if (serviceRecipe != null) {

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/EnvironmentRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/EnvironmentRecipe.java?rev=790110&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/EnvironmentRecipe.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/EnvironmentRecipe.java
Wed Jul  1 10:48:23 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.di;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+/**
+ * @version $Rev: 6685 $ $Date: 2005-12-28T00:29:37.967210Z $
+ */
+public class EnvironmentRecipe extends AbstractRecipe {
+
+    private Object object;
+
+    public EnvironmentRecipe(String id, Object object) {
+        super(id);
+        this.prototype = false;
+        this.object = object;
+    }
+
+    protected Object internalCreate() throws ComponentDefinitionException {
+        return object;
+    }
+
+    public List<Recipe> getDependencies() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public String toString() {
+        return "EnvironmentRecipe[" +
+                "name='" + name + '\'' +
+                ", object=" + object +
+                ']';
+    }
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Repository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Repository.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Repository.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/Repository.java
Wed Jul  1 10:48:23 2009
@@ -49,18 +49,8 @@
      */
     Recipe getRecipe(String name);
 
-    /**
-     * Return the environment object for a given name.
-     *
-     * @param name
-     * @return the environment object or <code>null</code>
-     */
-    Object getDefault(String name);
-
     void putRecipe(String name, Recipe recipe);
 
-    void putDefault(String name, Object instance);
-
     Object create(String name) throws ComponentDefinitionException;
 
     Map<String,Object> createAll(String... names) throws ComponentDefinitionException;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/namespace/ComponentDefinitionRegistryImpl.java
Wed Jul  1 10:48:23 2009
@@ -27,6 +27,7 @@
 
 import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
 import org.apache.geronimo.blueprint.ComponentNameAlreadyInUseException;
+import org.apache.geronimo.blueprint.reflect.EnvironmentMetadataImpl;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.Target;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
@@ -69,10 +70,7 @@
             // TODO: should we generate a unique name?
             throw new IllegalArgumentException("Component must have a valid id");
         }
-        if (id.equals("blueprintContainer") || id.equals("blueprintBundle")
-                || id.equals("blueprintBundleContext") || id.equals("blueprintConverter"))
{
-            throw new ComponentDefinitionException("Can not override an environment manager
(" + id + ")");
-        } else if (id.startsWith("blueprint")) {
+        if (id.startsWith("blueprint") && !(component instanceof EnvironmentMetadataImpl))
{
             // TODO: log a warning
         }
         // TODO: perform other validation: scope, class/runtimeClass/factoryMethod, etc...

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/EnvironmentMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/EnvironmentMetadataImpl.java?rev=790110&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/EnvironmentMetadataImpl.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/EnvironmentMetadataImpl.java
Wed Jul  1 10:48:23 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.reflect;
+
+/**
+ * A metadata for environment managers.
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 760378 $, $Date: 2009-03-31 11:31:38 +0200 (Tue, 31 Mar 2009) $
+ */
+public class EnvironmentMetadataImpl extends ComponentMetadataImpl {
+
+    private Object object;
+
+    public EnvironmentMetadataImpl(String id, Object object) {
+        this.id = id;
+        this.object = object;
+    }
+
+    public Object getObject() {
+        return object;
+    }
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/AbstractBlueprintTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/AbstractBlueprintTest.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/AbstractBlueprintTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/AbstractBlueprintTest.java
Wed Jul  1 10:48:23 2009
@@ -25,6 +25,7 @@
 import org.apache.geronimo.blueprint.container.NamespaceHandlerRegistry;
 import org.apache.geronimo.blueprint.container.Parser;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.geronimo.blueprint.reflect.EnvironmentMetadataImpl;
 
 public abstract class AbstractBlueprintTest extends TestCase {
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/TestBlueprintContainer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/TestBlueprintContainer.java?rev=790110&r1=790109&r2=790110&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/TestBlueprintContainer.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/TestBlueprintContainer.java
Wed Jul  1 10:48:23 2009
@@ -20,6 +20,7 @@
 
 import org.apache.geronimo.blueprint.container.BlueprintContainerImpl;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.geronimo.blueprint.reflect.EnvironmentMetadataImpl;
 
 public class TestBlueprintContainer extends BlueprintContainerImpl {
 
@@ -28,6 +29,12 @@
     public TestBlueprintContainer(ComponentDefinitionRegistryImpl registry) {
         super(new TestBundleContext(), null, null, null, null, null);
         this.registry = registry;
+        if (registry != null) {
+            registry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintContainer",
this));
+            registry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintBundle",
getBundleContext().getBundle()));
+            registry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintBundleContext",
getBundleContext()));
+            registry.registerComponentDefinition(new EnvironmentMetadataImpl("blueprintConverter",
getConverter()));
+        }
     }
 
     @Override



Mime
View raw message