geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r776791 - in /geronimo/sandbox/blueprint: blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/contain...
Date Wed, 20 May 2009 18:02:01 GMT
Author: gnodet
Date: Wed May 20 18:02:01 2009
New Revision: 776791

URL: http://svn.apache.org/viewvc?rev=776791&view=rev
Log:
Make sure loading class is done as late as possible to avoid breaking the lazy activation
policy

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedBeanMetadata.java
Modified:
    geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BeanProcessor.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/BlueprintObjectInstantiator.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.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/di/AbstractRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ArrayRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ValueRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableBeanMetadata.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/BeanMetadataImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
    geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java

Modified: geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/CmNamespaceHandler.java
Wed May 20 18:02:01 2009
@@ -141,6 +141,7 @@
 
     private ComponentMetadata parsePropertyPlaceholder(ExtendedParserContext context, Element
element) {
         MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+        metadata.setProcessor(true);
         metadata.setId(getName(element));
         metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
         metadata.setRuntimeClass(CmPropertyPlaceholder.class);
@@ -280,6 +281,7 @@
         }
         generateIdIfNeeded(((MutableBeanMetadata) component));
         MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+        metadata.setProcessor(true);
         metadata.setId(getName(element));
         metadata.setRuntimeClass(CmManagedProperties.class);
         metadata.setInitMethodName("init");

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BeanProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BeanProcessor.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BeanProcessor.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BeanProcessor.java
Wed May 20 18:02:01 2009
@@ -19,7 +19,16 @@
 package org.apache.geronimo.blueprint;
 
 /**
- * TODO
+ * TODO: javadoc
+ *
+ * TODO: processors have to be advertized as being processors. currently
+ * TODO: it can only be done by using a custom namespace and setting the
+ * TODO: ExtendedBeanMetadata#isProcessor() flag
+ * TODO: we need a namespace extension to add an attribute to the <bp:bean/>
+ * TODO: element such as <bp:bean gbp:processor="true" ...
+ * TODO: but we'll see later with the spec when it evolves to better support
+ * TODO: namespaces
+ *
  *
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedBeanMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedBeanMetadata.java?rev=776791&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedBeanMetadata.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedBeanMetadata.java
Wed May 20 18:02:01 2009
@@ -0,0 +1,34 @@
+/**
+ *  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;
+
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+
+/**
+ * An extended <code>BeanMetadata</code> that allows specifying if
+ * the bean instances are processors or not.
+ * 
+ * Such processors have to be instantiated before instantiating all
+ * other singletons, but to avoid breaking the lazy activation of
+ * bundles, the Blueprint container needs to be aware of those and not
+ * try to load the class to perform some introspection.
+ */
+public interface ExtendedBeanMetadata extends BeanMetadata {
+
+    boolean isProcessor();
+
+}

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=776791&r1=776790&r2=776791&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 May 20 18:02:01 2009
@@ -42,6 +42,7 @@
 import org.apache.geronimo.blueprint.Destroyable;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.apache.geronimo.blueprint.NamespaceHandlerRegistry;
+import org.apache.geronimo.blueprint.ExtendedBeanMetadata;
 import org.apache.geronimo.blueprint.container.SatisfiableRecipe;
 import org.apache.geronimo.blueprint.convert.ConversionServiceImpl;
 import org.apache.geronimo.blueprint.di.DefaultExecutionContext;
@@ -75,14 +76,12 @@
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.osgi.service.blueprint.reflect.BeanArgument;
 import org.osgi.service.blueprint.reflect.BeanProperty;
-import org.osgi.service.blueprint.reflect.ValueMetadata;
 import org.osgi.service.blueprint.reflect.CollectionMetadata;
 import org.osgi.service.blueprint.reflect.MapMetadata;
 import org.osgi.service.blueprint.reflect.MapEntry;
 import org.osgi.service.blueprint.reflect.PropsMetadata;
 import org.osgi.service.blueprint.reflect.RefCollectionMetadata;
 import org.osgi.service.blueprint.reflect.Listener;
-import org.osgi.service.blueprint.reflect.ReferenceMetadata;
 import org.osgi.service.blueprint.reflect.RegistrationListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -227,7 +226,7 @@
                         state = State.Populated;
                         break;
                     case Populated:
-                        instantiator = new BlueprintObjectInstantiator(conversionService,
new RecipeBuilder(this).createRepository());
+                        instantiator = new BlueprintObjectInstantiator(this, new RecipeBuilder(this).createRepository());
                         checkReferences();
                         trackServiceReferences();
                         timerTask = new TimerTask() {
@@ -261,12 +260,10 @@
                     case InitialReferencesSatisfied:
                         processTypeConverters();
                         processProcessors();
+                        // Update repository wrt bean processing
+                        untrackServiceReferences();
                         DefaultRepository repository = (DefaultRepository) instantiator.getRepository();
                         DefaultRepository tmpRepo = new RecipeBuilder(this).createRepository();
-
-                        instantiator = new BlueprintObjectInstantiator(conversionService,
new RecipeBuilder(this).createRepository());
-
-                        untrackServiceReferences();
                         for (String name : repository.getNames()) {
                             Recipe recipe = repository.getRecipe(name);
                             Object instance = repository.getInstance(name);
@@ -276,8 +273,9 @@
                             }
                         }
                         satisfiables = null;
-                        instantiator = new BlueprintObjectInstantiator(conversionService,
tmpRepo);
+                        instantiator = new BlueprintObjectInstantiator(this, tmpRepo);
                         trackServiceReferences();
+                        // Check references
                         if (checkAllSatisfiables() || !waitForDependencies) {
                             state = State.InitialReferencesSatisfied2;
                         } else {
@@ -313,7 +311,7 @@
                         return;
                     case Create:
                         timerTask.cancel();
-                        instantiateComponents();
+                        instantiateEagerSingletonBeans();
 
                         // Register the BlueprintContainer in the OSGi registry
                         if (registration == null) {
@@ -349,7 +347,7 @@
         List<Recipe> recipes = new ArrayList<Recipe>();
         boolean createNewContext = !ExecutionContext.isContextSet();
         if (createNewContext) {
-            ExecutionContext.setContext(new DefaultExecutionContext(conversionService, instantiator.getRepository()));
+            ExecutionContext.setContext(new DefaultExecutionContext(this, instantiator.getRepository()));
         }
         try {
             for (String name : repository.getNames()) {
@@ -408,8 +406,13 @@
     }
 
     private void processProcessors() throws Exception {
+        // TODO: the whole lazy activation just because we need to discover processors
+        // TODO: we need something else to find out which beans are processors, maybe a subtype
of BeanMetadata
         // Instanciate ComponentDefinitionRegistryProcessor and BeanProcessor
         for (BeanMetadata bean : getBeanComponentsMetadata()) {
+            if (bean instanceof ExtendedBeanMetadata && !((ExtendedBeanMetadata)
bean).isProcessor()) {
+                continue;
+            }
             Class clazz = bean.getRuntimeClass();
             if (clazz == null && bean.getClassName() != null) {
                 clazz = loadClass(bean.getClassName());
@@ -431,7 +434,7 @@
         if (satisfiables == null && instantiator != null) {
             boolean createNewContext = !ExecutionContext.isContextSet();
             if (createNewContext) {
-                ExecutionContext.setContext(new DefaultExecutionContext(conversionService,
instantiator.getRepository()));
+                ExecutionContext.setContext(new DefaultExecutionContext(this, instantiator.getRepository()));
             }
             try {
                 satisfiables = new HashMap<String, List<SatisfiableRecipe>>();
@@ -535,7 +538,7 @@
         }
     }
 
-    private void instantiateComponents() {
+    private void instantiateEagerSingletonBeans() {
         List<String> components = new ArrayList<String>();
         for (String name : componentDefinitionRegistry.getComponentDefinitionNames()) {
             ComponentMetadata component = componentDefinitionRegistry.getComponentDefinition(name);
@@ -591,7 +594,7 @@
     private void registerTriggerServices() {
         boolean createNewContext = !ExecutionContext.isContextSet();
         if (createNewContext) {
-            ExecutionContext.setContext(new DefaultExecutionContext(conversionService, instantiator.getRepository()));
+            ExecutionContext.setContext(new DefaultExecutionContext(this, instantiator.getRepository()));
         }
         try {
             for (ServiceMetadata service : getExportedServicesMetadata()) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectInstantiator.java
Wed May 20 18:02:01 2009
@@ -32,17 +32,18 @@
 import org.apache.geronimo.blueprint.di.Repository;
 import org.apache.geronimo.blueprint.di.UnresolvedReferencesException;
 import org.apache.geronimo.blueprint.utils.ConversionUtils;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 import org.osgi.service.blueprint.convert.ConversionService;
 
 /**
  */
 public class BlueprintObjectInstantiator  {
 
-    private ConversionService conversionService;
+    private ExtendedBlueprintContainer blueprintContainer;
     private Repository repository;
 
-    public BlueprintObjectInstantiator(ConversionService conversionService, Repository repository)
{
-        this.conversionService = conversionService;
+    public BlueprintObjectInstantiator(ExtendedBlueprintContainer blueprintContainer, Repository
repository) {
+        this.blueprintContainer = blueprintContainer;
         this.repository = repository;
     }
     
@@ -65,13 +66,14 @@
             
             boolean createNewContext = !ExecutionContext.isContextSet();
             if (createNewContext) {
-                ExecutionContext.setContext(new DefaultExecutionContext(conversionService,
repository));
+                ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer,
repository));
             }
             
             try {
                 Object obj = createInstance(name);
                 try {
-                    obj = ConversionUtils.convert(obj, Object.class, conversionService);
+                    // Make sure to go through the conversion step in case we have a Convertible
object
+                    obj = ConversionUtils.convert(obj, Object.class, blueprintContainer.getConversionService());
                 } catch (Exception e) {
                     throw new ConstructionException("Unable to convert instance " + name,
e);
                 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintObjectRecipe.java
Wed May 20 18:02:01 2009
@@ -37,7 +37,6 @@
 import org.apache.geronimo.blueprint.BeanProcessor;
 import org.apache.geronimo.blueprint.Destroyable;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
-import org.apache.geronimo.blueprint.ExtendedComponentDefinitionRegistry;
 import org.apache.geronimo.blueprint.di.AbstractRecipe;
 import org.apache.geronimo.blueprint.di.ConstructionException;
 import org.apache.geronimo.blueprint.di.Option;
@@ -57,7 +56,7 @@
 
     private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintObjectRecipe.class);
 
-    private Class typeClass;
+    private Object type;
     private final LinkedHashMap<String,Object> properties = new LinkedHashMap<String,Object>();
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
 
@@ -69,14 +68,14 @@
     private Recipe factory; // could be Recipe or actual object
     private String factoryMethod;
     private List<Object> arguments;
-    private List<Class> argTypes;
+    private List<String> argTypes;
     private boolean reorderArguments;
 
     protected ExtendedBlueprintContainer blueprintContainer;
 
-    public BlueprintObjectRecipe(ExtendedBlueprintContainer blueprintContainer, Class typeClass)
{
+    public BlueprintObjectRecipe(ExtendedBlueprintContainer blueprintContainer, Object type)
{
         this.blueprintContainer = blueprintContainer;
-        this.typeClass = typeClass;
+        this.type = type;
         allow(Option.LAZY_ASSIGNMENT);
     }
 
@@ -121,7 +120,7 @@
         this.factory = factory;
     }
     
-    public void setArgTypes(List<Class> argTypes) {
+    public void setArgTypes(List<String> argTypes) {
         this.argTypes = argTypes;
     }
     
@@ -203,6 +202,7 @@
         
         // Instanciate arguments
         List<Object> args = new ArrayList<Object>();
+        List<Class> argTypes = new ArrayList<Class>();
         if (arguments != null) {
             for (int i = 0; i < arguments.size(); i++) {
                 Object arg = arguments.get(i);
@@ -211,6 +211,9 @@
                 } else {
                     args.add(arg);
                 }
+                if (this.argTypes != null) {
+                    argTypes.add(this.argTypes.get(i) != null ? loadClass(this.argTypes.get(i))
: null);
+                }
             }
         }
 
@@ -603,7 +606,13 @@
     }
 
     public Class getType() {
-        return typeClass;
+        if (type instanceof Class) {
+            return (Class) type;
+        } else if (type instanceof String) {
+            return loadClass((String) type);
+        } else {
+            return null;
+        }
     }
 
     private void setProperties(Map<String, Object> propertyValues, Object instance,
Class clazz) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BundleScopeServiceFactory.java
Wed May 20 18:02:01 2009
@@ -77,7 +77,7 @@
         Repository objectRepository = blueprintContainer.getRepository();
         DefaultRepository repository = new DefaultRepository((DefaultRepository)objectRepository);
         repository.set(serviceRecipe.getName(), serviceRecipe);
-        ObjectGraph graph = new ObjectGraph(blueprintContainer.getConversionService(), repository);
+        ObjectGraph graph = new ObjectGraph(blueprintContainer, repository);
         return graph.create(serviceRecipe.getName());
     }
     

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=776791&r1=776790&r2=776791&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 May 20 18:02:01 2009
@@ -67,19 +67,6 @@
  */
 public class RecipeBuilder {
 
-    private static Map<String, Class> primitiveClasses = new HashMap<String, Class>();
-    
-    static {
-        primitiveClasses.put("int", int.class);
-        primitiveClasses.put("short", short.class);
-        primitiveClasses.put("long", long.class);
-        primitiveClasses.put("byte", byte.class);
-        primitiveClasses.put("char", char.class);
-        primitiveClasses.put("float", float.class);
-        primitiveClasses.put("double", double.class);
-        primitiveClasses.put("boolean", boolean.class);
-    }
-    
     private int nameCounter;
     private BlueprintContainerImpl blueprintContainer;
     private ExtendedComponentDefinitionRegistry registry;
@@ -212,8 +199,9 @@
     }
     
     private BlueprintObjectRecipe createBeanRecipe(BeanMetadata local) throws Exception {
-        Class clazz = local.getRuntimeClass() != null ? local.getRuntimeClass() : loadClass(local.getClassName());
-        BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContainer, clazz);
+        BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(
+                blueprintContainer,
+                local.getRuntimeClass() != null ? local.getRuntimeClass() : local.getClassName());
         recipe.setName(getName(local.getId()));
         recipe.setExplicitDependencies(local.getExplicitDependencies());
         for (BeanProperty property : local.getProperties()) {
@@ -234,20 +222,11 @@
                 beanArguments = beanArgumentsCopy;
             }
             List<Object> arguments = new ArrayList<Object>();
-            List<Class> argTypes = new ArrayList<Class>();
+            List<String> argTypes = new ArrayList<String>();
             for (BeanArgument argument : beanArguments) {
                 Recipe value = getValue(argument.getValue(), null);
                 arguments.add(value);
-                String valueType = argument.getValueType();
-                if (valueType != null) {
-                    try {
-                        argTypes.add(loadClass(valueType));
-                    } catch (Throwable t) {
-                        throw new ConstructionException("Error loading class " + valueType
+ " when instanciating bean " + recipe.getName());
-                    }
-                } else {
-                    argTypes.add(null);
-                }
+                argTypes.add(argument.getValueType());
             }
             recipe.setArguments(arguments);
             recipe.setArgTypes(argTypes);
@@ -289,14 +268,14 @@
         }
     }
     
-    private Recipe getValue(Metadata v, Class groupingType) throws Exception {
+    private Recipe getValue(Metadata v, Object groupingType) throws Exception {
         if (v instanceof NullMetadata) {
             return null;
         } else if (v instanceof ComponentMetadata) {
             return createRecipe((ComponentMetadata) v);
         } else if (v instanceof ValueMetadata) {
             ValueMetadata stringValue = (ValueMetadata) v;
-            Class type = loadClass(stringValue.getTypeName());
+            Object type = stringValue.getTypeName();
             type = (type == null) ? groupingType : type;
             return new ValueRecipe(stringValue, type);
         } else if (v instanceof RefMetadata) {
@@ -306,7 +285,7 @@
         } else if (v instanceof CollectionMetadata) {
             CollectionMetadata collectionMetadata = (CollectionMetadata) v;
             Class cl = collectionMetadata.getCollectionClass();
-            Class type = loadClass(collectionMetadata.getValueTypeName());
+            Object type = collectionMetadata.getValueTypeName();
             if (cl == Object[].class) {
                 ArrayRecipe ar = new ArrayRecipe(type);
                 for (Metadata lv : collectionMetadata.getValues()) {
@@ -322,8 +301,8 @@
             }
         } else if (v instanceof MapMetadata) {
             MapMetadata mapValue = (MapMetadata) v;
-            Class keyType = loadClass(mapValue.getKeyTypeName());
-            Class valueType = loadClass(mapValue.getValueTypeName());
+            Object keyType = mapValue.getKeyTypeName();
+            Object valueType = mapValue.getValueTypeName();
             MapRecipe mr = new MapRecipe(HashMap.class);
             for (MapEntry entry : mapValue.getEntries()) {
                 Recipe key = getValue(entry.getKey(), keyType);
@@ -353,10 +332,6 @@
         return blueprintContainer.getConversionService();
     }
     
-    private Class loadClass(String typeName) throws ClassNotFoundException {
-        return loadClass(blueprintContainer, typeName);
-    }
-    
     private String getName(String name) {
         if (name == null) {
             return "recipe-" + ++nameCounter;
@@ -365,21 +340,4 @@
         }
     }
         
-    public static Class loadClass(ExtendedBlueprintContainer context, String typeName) throws
ClassNotFoundException {
-        if (typeName == null) {
-            return null;
-        }
-
-        Class clazz = primitiveClasses.get(typeName);
-        if (clazz == null) {
-            if (context == null) {
-                ClassLoader loader = Thread.currentThread().getContextClassLoader();
-                clazz = loader.loadClass(typeName);
-            } else {
-                clazz = context.loadClass(typeName);
-            }
-        }
-        return clazz;
-    }
-            
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/AbstractRecipe.java
Wed May 20 18:02:01 2009
@@ -122,6 +122,14 @@
         return ExecutionContext.getContext().convert(obj, type);
     }
 
+    protected Class loadClass(String className) {
+        try {
+            return ExecutionContext.getContext().loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new ConstructionException(e);
+        }
+    }
+
     public Destroyable getDestroyable(Object instance) {
         return null;
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ArrayRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ArrayRecipe.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ArrayRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ArrayRecipe.java
Wed May 20 18:02:01 2009
@@ -29,12 +29,12 @@
 public class ArrayRecipe extends AbstractRecipe {
 
     private final List<Recipe> list;
-    private Class typeClass;
+    private Object type;
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
 
-    public ArrayRecipe(Class type) {
+    public ArrayRecipe(Object type) {
         this.list = new ArrayList<Recipe>();
-        this.typeClass = type;
+        this.type = type;
     }
 
     public void allow(Option option) {
@@ -64,7 +64,14 @@
     }
 
     protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
-        Class type = typeClass != null ? typeClass : Object.class;
+        Class type;
+        if (this.type instanceof Class) {
+            type = (Class) this.type;
+        } else if (this.type instanceof String) {
+            type = loadClass((String) this.type);
+        } else {
+            type = Object.class;
+        }
 
         // create array instance
         Object array;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/DefaultExecutionContext.java
Wed May 20 18:02:01 2009
@@ -28,6 +28,8 @@
 import java.util.TreeMap;
 
 import org.apache.geronimo.blueprint.utils.ConversionUtils;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
+import org.apache.geronimo.blueprint.container.RecipeBuilder;
 import org.osgi.service.blueprint.convert.ConversionService;
 
 public class DefaultExecutionContext extends ExecutionContext {
@@ -36,7 +38,7 @@
      */
     private Repository repository;
 
-    private ConversionService conversionService;
+    private ExtendedBlueprintContainer blueprintContainer;
 
     /**
      * Contains partial objects.
@@ -56,14 +58,14 @@
      */
     private final SortedMap<String, List<Reference>> unresolvedRefs = new TreeMap<String,
List<Reference>>();
 
-    public DefaultExecutionContext(ConversionService conversionService) {
-        this(conversionService, new DefaultRepository());
+    public DefaultExecutionContext(ExtendedBlueprintContainer blueprintContainer) {
+        this(blueprintContainer, new DefaultRepository());
     }
 
-    public DefaultExecutionContext(ConversionService conversionService, Repository repository)
{
-        if (conversionService == null) throw new NullPointerException("conversionService
is null");
+    public DefaultExecutionContext(ExtendedBlueprintContainer blueprintContainer, Repository
repository) {
+        if (blueprintContainer == null) throw new NullPointerException("blueprintContainer
is null");
         if (repository == null) throw new NullPointerException("repository is null");
-        this.conversionService = conversionService;
+        this.blueprintContainer = blueprintContainer;
         this.repository = repository;
     }
 
@@ -174,6 +176,35 @@
     }
 
     public Object convert(Object value, Type type) throws Exception {
-        return ConversionUtils.convert(value, type, conversionService);
+        return ConversionUtils.convert(value, type, blueprintContainer.getConversionService());
+    }
+
+    private static Map<String, Class> primitiveClasses = new HashMap<String, Class>();
+
+    static {
+        primitiveClasses.put("int", int.class);
+        primitiveClasses.put("short", short.class);
+        primitiveClasses.put("long", long.class);
+        primitiveClasses.put("byte", byte.class);
+        primitiveClasses.put("char", char.class);
+        primitiveClasses.put("float", float.class);
+        primitiveClasses.put("double", double.class);
+        primitiveClasses.put("boolean", boolean.class);
+    }
+
+    public Class loadClass(String typeName) throws ClassNotFoundException {
+        if (typeName == null) {
+            return null;
+        }
+        Class clazz = primitiveClasses.get(typeName);
+        if (clazz == null && typeName.startsWith("java.")) {
+            // We can bypass classes starting with "java." because they are always delegated
+            // to the system bundle, so we'll end up with the same class in all cases 
+            clazz = getClass().getClassLoader().loadClass(typeName);
+        }
+        if (clazz == null) {
+            clazz = blueprintContainer.loadClass(typeName);
+        }
+        return clazz;
     }
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ExecutionContext.java
Wed May 20 18:02:01 2009
@@ -114,4 +114,6 @@
     public abstract Object getCreatedObject(String name);
 
     public abstract Object convert(Object value, Type type) throws Exception;
+
+    public abstract Class loadClass(String className) throws ClassNotFoundException;
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ObjectGraph.java
Wed May 20 18:02:01 2009
@@ -28,16 +28,17 @@
 import java.util.Map;
 
 import org.osgi.service.blueprint.convert.ConversionService;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 
 public class ObjectGraph {
 
-    private ConversionService conversionService;
+    private ExtendedBlueprintContainer blueprintContainer;
     private Repository repository;
 
-    public ObjectGraph(ConversionService conversionService, Repository repository) {
-        if (conversionService == null) throw new NullPointerException("conversionService
is null");
+    public ObjectGraph(ExtendedBlueprintContainer blueprintContainer, Repository repository)
{
+        if (blueprintContainer == null) throw new NullPointerException("blueprintContainer
is null");
         if (repository == null) throw new NullPointerException("repository is null");
-        this.conversionService = conversionService;
+        this.blueprintContainer = blueprintContainer;
         this.repository = repository;
     }
 
@@ -67,7 +68,7 @@
         // setup execution container
         boolean createNewContext = !ExecutionContext.isContextSet();
         if (createNewContext) {
-            ExecutionContext.setContext(new DefaultExecutionContext(conversionService, repository));
+            ExecutionContext.setContext(new DefaultExecutionContext(blueprintContainer, repository));
         }
         WrapperExecutionContext wrapperContext = new WrapperExecutionContext(ExecutionContext.getContext());
         ExecutionContext.setContext(wrapperContext);
@@ -298,5 +299,9 @@
         public Object convert(Object value, Type type) throws Exception {
             return executionContext.convert(value, type);
         }
+
+        public Class loadClass(String className) throws ClassNotFoundException {
+            return executionContext.loadClass(className);
+        }
     }
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ValueRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ValueRecipe.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ValueRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/di/ValueRecipe.java
Wed May 20 18:02:01 2009
@@ -18,7 +18,12 @@
  */
 package org.apache.geronimo.blueprint.di;
 
+import java.lang.reflect.Type;
+
 import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.apache.geronimo.blueprint.container.RecipeBuilder;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
 
 /**
  * This recipe will be used to create an object from a ValueMetadata.
@@ -31,9 +36,9 @@
 public class ValueRecipe extends AbstractRecipe {
 
     private ValueMetadata value;
-    private Class type;
+    private Object type;
 
-    public ValueRecipe(ValueMetadata value, Class type) {
+    public ValueRecipe(ValueMetadata value, Object type) {
         this.value = value;
         this.type = type;
     }
@@ -41,7 +46,13 @@
     @Override
     protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
         try {
-            return convert(value.getStringValue(), type != null ? type : Object.class);
+            Type type = Object.class;
+            if (this.type instanceof Type) {
+                type = (Type) this.type;
+            } else if (this.type instanceof String) {
+                type = loadClass((String) this.type);
+            }
+            return convert(value.getStringValue(), type);
         } catch (Exception e) {            
             throw new ConstructionException(e);
         }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableBeanMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableBeanMetadata.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableBeanMetadata.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableBeanMetadata.java
Wed May 20 18:02:01 2009
@@ -23,6 +23,7 @@
 import org.osgi.service.blueprint.reflect.BeanProperty;
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.osgi.service.blueprint.reflect.Target;
+import org.apache.geronimo.blueprint.ExtendedBeanMetadata;
 
 /**
  * A mutable version of the <code>BeanMetadata</code> that allows modifications.
@@ -30,7 +31,7 @@
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
  */
-public interface MutableBeanMetadata extends BeanMetadata, MutableComponentMetadata {
+public interface MutableBeanMetadata extends ExtendedBeanMetadata, MutableComponentMetadata
{
 
     void setId(String id);
 
@@ -66,4 +67,6 @@
 
     void setRuntimeClass(Class runtimeClass);
 
+    void setProcessor(boolean processor);
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/BeanMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/BeanMetadataImpl.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/BeanMetadataImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/BeanMetadataImpl.java
Wed May 20 18:02:01 2009
@@ -48,6 +48,7 @@
     private String scope;
     private Class runtimeClass;
     private List<String> explicitDependencies;
+    private boolean processor;
 
     public BeanMetadataImpl() {
     }
@@ -221,7 +222,15 @@
             this.explicitDependencies.remove(dependency);
         }
     }
-    
+
+    public boolean isProcessor() {
+        return processor;
+    }
+
+    public void setProcessor(boolean processor) {
+        this.processor = processor;
+    }
+
     @Override
     public String toString() {
         return "BeanMetadata[" +

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=776791&r1=776790&r2=776791&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
Wed May 20 18:02:01 2009
@@ -49,7 +49,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         DefaultRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
         
         Object obj1 = graph.create("pojoA");
         assertNotNull(obj1);
@@ -139,7 +139,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         DefaultRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
         
         Object obj5 = graph.create("compound");
         assertNotNull(obj5);
@@ -153,7 +153,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         DefaultRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
         
         try {
             graph.create("badIdRef");
@@ -177,7 +177,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         DefaultRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
         Map instances = graph.createAll("c", "d", "e");
         
         List<Callback> callback = CallbackTracker.getCallbacks();
@@ -208,7 +208,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-constructor.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
 
         Object obj1 = graph.create("pojoA");
         assertNotNull(obj1);
@@ -300,7 +300,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
         
         List<Integer> expectedList = new ArrayList<Integer>();
         expectedList.add(new Integer(10));
@@ -351,7 +351,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new TestBlueprintContext(registry),
repository);
 
         // this should pass (we allow circular dependencies for components without init method)
         Object obj1 = graph.create("a");

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java?rev=776791&r1=776790&r2=776791&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestConfigAdmin.java
Wed May 20 18:02:01 2009
@@ -33,6 +33,7 @@
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.OptionUtils;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
 import org.osgi.service.blueprint.container.BlueprintContainer;
@@ -182,6 +183,9 @@
             mavenBundle("org.apache.geronimo", "blueprint-bundle"),
             mavenBundle("org.apache.geronimo", "blueprint-sample").noStart(),
 
+//            vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+//            felix()
+
             felix(), equinox() //, knopflerfish()
         );
 



Mime
View raw message