geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r775197 - in /geronimo/sandbox/blueprint: blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ blueprint-core/src/main/java/org/apache/xbean/recipe/ blueprint-...
Date Fri, 15 May 2009 15:44:28 GMT
Author: gnodet
Date: Fri May 15 15:44:27 2009
New Revision: 775197

URL: http://svn.apache.org/viewvc?rev=775197&view=rev
Log:
Rework signature disambiguation / conversion + fix reference tracking (integration tests now work again)

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
Removed:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.java
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ReflectionUtils.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ArrayRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/CollectionRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/MapRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Recipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceNameRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceRecipe.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/TestReferences.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintContextImpl.java Fri May 15 15:44:27 2009
@@ -85,6 +85,8 @@
         Populated,
         WaitForInitialReferences,
         InitialReferencesSatisfied,
+        WaitForInitialReferences2,
+        InitialReferencesSatisfied2,
         WaitForTrigger,
         Create,
         Created,
@@ -224,8 +226,44 @@
                             return;
                         }
                     case InitialReferencesSatisfied:
-                        processHelpers();
-                        new RecipeBuilder(this).updateRepository((BlueprintObjectRepository) instantiator.getRepository());
+                        processTypeConverters();
+                        processProcessors();
+                        BlueprintObjectRepository repository = (BlueprintObjectRepository) instantiator.getRepository();
+                        BlueprintObjectRepository tmpRepo = new RecipeBuilder(this).createRepository();
+
+                        BlueprintObjectInstantiator oldInstantiator = instantiator;
+                        instantiator = new BlueprintObjectInstantiator(new RecipeBuilder(this).createRepository());
+
+                        untrackServiceReferences();
+                        for (String name : repository.getNames()) {
+                            Recipe recipe = repository.getRecipe(name);
+                            Object instance = repository.getInstance(name);
+                            if (instance != null) {
+                                tmpRepo.putRecipe(name, recipe);
+                                tmpRepo.putInstance(name, instance);
+                            }
+                        }
+                        satisfiables = null;
+                        instantiator = new BlueprintObjectInstantiator(tmpRepo);
+                        trackServiceReferences();
+                        if (checkAllSatisfiables() || !waitForDependencies) {
+                            state = State.InitialReferencesSatisfied2;
+                        } else {
+                            // TODO: pass correct parameters
+                            // TODO: do we need to send one event for each missing reference ?
+                            // TODO: create a timer, then fail after it elapsed
+                            sender.sendWaiting(this, null, null);
+                            state = State.WaitForInitialReferences2;
+                        }
+                        break;
+                    case WaitForInitialReferences2:
+                        if (checkAllSatisfiables()) {
+                            state = State.InitialReferencesSatisfied2;
+                            break;
+                        } else {
+                            return;
+                        }
+                    case InitialReferencesSatisfied2:
                         // TODO: we should always register ServiceFactory in all cases.
                         //       the reason is that the trigger service creation may actually trigger the activation of
                         //       the bundle if the service properties reference any other components (thus loading a class
@@ -274,7 +312,7 @@
         }
     }
 
-    private void processHelpers() throws Exception {
+    private void processTypeConverters() throws Exception {
         List<String> typeConverters = new ArrayList<String>();
         for (Target target : componentDefinitionRegistry.getTypeConverters()) {
             if (target instanceof ComponentMetadata) {
@@ -294,13 +332,15 @@
                 throw new ComponentDefinitionException("Type converter " + obj + " does not implement the " + Converter.class.getName() + " interface");
             }
         }
+    }
 
+    private void processProcessors() throws Exception {
         // Instanciate ComponentDefinitionRegistryProcessor and BeanProcessor
         for (BeanMetadata bean : getBeanComponentsMetadata()) {
             Class clazz = bean.getRuntimeClass();
             if (clazz == null && bean.getClassName() != null) {
                 clazz = loadClass(bean.getClassName());
-            } 
+            }
             if (clazz == null) {
                 continue;
             }
@@ -312,8 +352,6 @@
                 this.beanProcessors.add((BeanProcessor) obj);
             }
         }
-        
-        // TODO: need to destroy all those objects at the end
     }
 
     private Map<String, List<SatisfiableRecipe>> getSatisfiableDependenciesMap() {
@@ -325,17 +363,14 @@
             try {
                 satisfiables = new HashMap<String, List<SatisfiableRecipe>>();
                 for (String name : componentDefinitionRegistry.getComponentDefinitionNames()) {
-                    Object val = instantiator.getRepository().get(name);
-                    if (val instanceof Recipe) {
-                        Recipe r = (Recipe) val;
-                        List<SatisfiableRecipe> recipes = new ArrayList<SatisfiableRecipe>();
-                        if (r instanceof SatisfiableRecipe) {
-                            recipes.add((SatisfiableRecipe) r);
-                        }
-                        getSatisfiableDependencies(r, recipes, new HashSet<Recipe>());
-                        if (!recipes.isEmpty()) {
-                            satisfiables.put(name, recipes);
-                        }
+                    Recipe r = ((BlueprintObjectRepository) instantiator.getRepository()).getRecipe(name);
+                    List<SatisfiableRecipe> recipes = new ArrayList<SatisfiableRecipe>();
+                    if (r instanceof SatisfiableRecipe) {
+                        recipes.add((SatisfiableRecipe) r);
+                    }
+                    getSatisfiableDependencies(r, recipes, new HashSet<Recipe>());
+                    if (!recipes.isEmpty()) {
+                        satisfiables.put(name, recipes);
                     }
                 }
                 return satisfiables;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRecipe.java Fri May 15 15:44:27 2009
@@ -22,13 +22,17 @@
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.EnumSet;
-import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,8 +40,7 @@
 
 import org.apache.geronimo.blueprint.BeanProcessor;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
-import org.apache.geronimo.blueprint.utils.ArgumentsMatch;
-import org.apache.geronimo.blueprint.utils.ArgumentsMatcher;
+import org.apache.geronimo.blueprint.utils.ConversionUtils;
 import org.apache.geronimo.blueprint.utils.ReflectionUtils;
 import org.apache.xbean.recipe.AbstractRecipe;
 import org.apache.xbean.recipe.ConstructionException;
@@ -45,14 +48,9 @@
 import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.Recipe;
 import org.apache.xbean.recipe.RecipeHelper;
-import static org.apache.xbean.recipe.RecipeHelper.toClass;
 import org.apache.xbean.recipe.ReferenceRecipe;
+import org.osgi.service.blueprint.convert.ConversionService;
 import org.osgi.service.blueprint.reflect.BeanArgument;
-import org.osgi.service.blueprint.reflect.CollectionMetadata;
-import org.osgi.service.blueprint.reflect.MapMetadata;
-import org.osgi.service.blueprint.reflect.Metadata;
-import org.osgi.service.blueprint.reflect.PropsMetadata;
-import org.osgi.service.blueprint.reflect.ValueMetadata;
 
 /**
  *
@@ -201,60 +199,6 @@
         }
     }
     
-    private List<Object> getInitialArguments(boolean refAllowed) throws ConstructionException {
-        List<Object> args = new ArrayList<Object>();
-        for (int i = 0; beanArguments != null && i < beanArguments.size(); i++) {
-            BeanArgument argument = beanArguments.get(i);
-            String valueType = argument.getValueType();          
-            Class type = loadClass(valueType);
-            Object obj = arguments.get(i);
-            if (type != null) {
-                obj = new TypedRecipe(blueprintContext.getConversionService(), type, obj);
-            } else {
-                if (obj == null) {
-                    obj = new TypedRecipe();
-                } else if (obj instanceof Recipe) {                
-                    if (shouldPreinstantiate(argument.getValue())) {
-                        obj = ((Recipe) obj).create(Object.class, refAllowed);
-                    }
-                }
-            }
-            args.add(obj);
-        }
-
-        return args;
-    }
-    
-    private List<Object> getFinalArguments(ArgumentsMatch match, boolean refAllowed) throws ConstructionException {
-        List<Object> arguments = match.getArguments();
-        Type[] parameterTypes = match.getGenericParameterTypes();
-
-        List<Object> args = new ArrayList<Object>();
-        for (int i = 0; i < arguments.size(); i++) {
-            Object argument = arguments.get(i);
-            if (argument instanceof Recipe) {
-                argument = ((Recipe) argument).create(parameterTypes[i], refAllowed);
-            }
-            args.add(argument);
-        }
-
-        return args;
-    }
-
-    private boolean shouldPreinstantiate(Metadata metadata) {
-        if (metadata instanceof ValueMetadata) {
-            ValueMetadata stringValue = (ValueMetadata) metadata;
-            return (stringValue.getTypeName() != null);
-        } else if (metadata instanceof MapMetadata) {
-            return false;
-        } else if (metadata instanceof CollectionMetadata) {
-            return false;
-        } else if (metadata instanceof PropsMetadata) {
-            return false;
-        }
-        return true;
-    }
-        
     private Class loadClass(String typeName) throws ConstructionException {
         if (typeName == null) {
             return null;
@@ -266,70 +210,199 @@
         }
     }
         
-    private Set<ArgumentsMatcher.Option> getArgumentsMatcherOptions() {
-        Set<ArgumentsMatcher.Option> options = new HashSet<ArgumentsMatcher.Option>();
-        if (reorderArguments) {
-            options.add(ArgumentsMatcher.Option.ARGUMENT_REORDER);
-        }
-        return options;
-    }
-    
     private Object getInstance(boolean refAllowed) throws ConstructionException {
         Object instance = null;
         
-        Set<ArgumentsMatcher.Option> options = getArgumentsMatcherOptions();
-        List<Object> arguments = getInitialArguments(refAllowed);
-        
+        // Instanciate arguments
+        List<Object> args = new ArrayList<Object>();
+        List<Class> types = new ArrayList<Class>();
+        if (arguments != null) {
+            for (int i = 0; i < arguments.size(); i++) {
+                Object arg = arguments.get(i);
+                if (arg instanceof Recipe) {
+                    args.add(((Recipe) arg).create(Object.class, refAllowed));
+                } else {
+                    args.add(arg);
+                }
+                String valueType = beanArguments.get(i).getValueType();
+                if (valueType != null) {
+                    try {
+                        types.add(loadClass(valueType));
+                    } catch (Throwable t) {
+                        throw new ConstructionException("Error loading class " + valueType + " when instanciating bean " + getName());
+                    }
+                } else {
+                    types.add(null);
+                }
+            }
+        }
+
         if (factory != null) {
             // look for instance method on factory object
-            Object factoryObj = factory.create(Object.class, refAllowed);
-            options.add(ArgumentsMatcher.Option.INSTANCE_METHODS_ONLY);
-            ArgumentsMatch match = ArgumentsMatcher.findMethod(factoryObj.getClass(), factoryMethod, arguments, options);
-            // convert parameters
-            List<Object> args = getFinalArguments(match, refAllowed);
-            // invoke instance method
-            try {
-                instance = match.getMethod().invoke(factoryObj, args.toArray());
-            } catch (InvocationTargetException e) {
-                Throwable root = e.getTargetException();
-                throw new ConstructionException(root);
-            } catch (Exception e) {
-                throw new ConstructionException(e);
+            Object factoryObj = factory.create(Object.class, false);
+            // Map of matching methods
+            Map<Method, List<Object>> matches = findMatchingMethods(factoryObj.getClass(), factoryMethod, true, args, types, arguments);
+            if (matches.size() == 1) {
+                try {
+                    Map.Entry<Method, List<Object>> match = matches.entrySet().iterator().next();
+                    instance = match.getKey().invoke(factoryObj, match.getValue().toArray());
+                } catch (InvocationTargetException e) {
+                    Throwable root = e.getTargetException();
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), root);
+                } catch (Throwable e) {
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), e);
+                }
+            } else if (matches.size() == 0) {
+                throw new ConstructionException("Unable to find a matching factory method " + factoryMethod + " on class " + factoryObj.getClass() + " for arguments " + args + " when instanciating bean " + getName());
+            } else {
+                throw new ConstructionException("Multiple matching factory methods " + factoryMethod + " found on class " + factoryObj.getClass() + " for arguments " + args + " when instanciating bean " + getName());
             }
         } else if (factoryMethod != null) {
-            // look for static method on this object
-            options.add(ArgumentsMatcher.Option.STATIC_METHODS_ONLY);
-            ArgumentsMatch match = ArgumentsMatcher.findMethod(getType(), factoryMethod, arguments, options);
-            // convert parameters
-            List<Object> args = getFinalArguments(match, refAllowed);
-            // invoke static method
-            try {
-                instance = match.getMethod().invoke(null, args.toArray());
-            } catch (InvocationTargetException e) {
-                Throwable root = e.getTargetException();
-                throw new ConstructionException(root);
-            } catch (Exception e) {
-                throw new ConstructionException(e);
+            // Map of matching methods
+            Map<Method, List<Object>> matches = findMatchingMethods(getType(), factoryMethod, false, args, types, arguments);
+            if (matches.size() == 1) {
+                try {
+                    Map.Entry<Method, List<Object>> match = matches.entrySet().iterator().next();
+                    instance = match.getKey().invoke(null, match.getValue().toArray());
+                } catch (InvocationTargetException e) {
+                    Throwable root = e.getTargetException();
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), root);
+                } catch (Throwable e) {
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), e);
+                }
+            } else if (matches.size() == 0) {
+                throw new ConstructionException("Unable to find a matching factory method " + factoryMethod + " on class " + getType() + " for arguments " + args + " when instanciating bean " + getName());
+            } else {
+                throw new ConstructionException("Multiple matching factory methods " + factoryMethod + " found on class " + getType() + " for arguments " + args + " when instanciating bean " + getName());
             }
         } else {
-            // look for constructor on this object
-            ArgumentsMatch match = ArgumentsMatcher.findConstructor(getType(), arguments, options);
-            // convert parameters
-            List<Object> args = getFinalArguments(match, refAllowed);
-            // invoke constructor
-            try {
-                instance = match.getConstructor().newInstance(args.toArray());
-            } catch (InvocationTargetException e) {
-                Throwable root = e.getTargetException();
-                throw new ConstructionException(root);
-            } catch (Exception e) {
-                throw new ConstructionException(e);
+            // Map of matching constructors
+            Map<Constructor, List<Object>> matches = findMatchingConstructors(args, types, args);
+            if (matches.size() == 1) {
+                try {
+                    Map.Entry<Constructor, List<Object>> match = matches.entrySet().iterator().next();
+                    instance = match.getKey().newInstance(match.getValue().toArray());
+                } catch (InvocationTargetException e) {
+                    Throwable root = e.getTargetException();
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), root);
+                } catch (Throwable e) {
+                    throw new ConstructionException("Error when instanciating bean " + getName() + " of class " + getType(), e);
+                }
+            } else if (matches.size() == 0) {
+                throw new ConstructionException("Unable to find a matching constructor on class " + getType() + " for arguments " + args + " when instanciating bean " + getName());
+            } else {
+                throw new ConstructionException("Multiple matching constructors found on class " + getType() + " for arguments " + args + " when instanciating bean " + getName());
             }
         }
         
         return instance;
     }
-        
+
+    private Object convert(Object obj, Type type) throws Exception {
+        return ConversionUtils.convert(obj, type, blueprintContext.getConversionService());
+    }
+
+    private Map<Method, List<Object>> findMatchingMethods(Class type, String name, boolean instance, List<Object> args, List<Class> types, List<Object> arguments) {
+        Map<Method, List<Object>> matches = new HashMap<Method, List<Object>>();
+        // Get constructors
+        List<Method> methods = new ArrayList<Method>(Arrays.asList(type.getMethods()));
+        // Discard any signature with wrong cardinality
+        for (Iterator<Method> it = methods.iterator(); it.hasNext();) {
+            Method mth = it.next();
+            if (!mth.getName().equals(name)) {
+                it.remove();
+            } else if (mth.getParameterTypes().length != args.size()) {
+                it.remove();
+            } else if (!instance ^ Modifier.isStatic(mth.getModifiers())) {
+                it.remove();
+            }
+        }
+        // Find a direct match
+        for (Method mth : methods) {
+            boolean found = true;
+            List<Object> match = new ArrayList<Object>();
+            for (int i = 0; i < args.size(); i++) {
+                if (types.get(i) != null && types.get(i) != mth.getParameterTypes()[i]) {
+                    found = false;
+                    break;
+                }
+                try {
+                    Object val = convert(args.get(i), mth.getGenericParameterTypes()[i]);
+                    match.add(val);
+                } catch (Throwable t) {
+                    found = false;
+                    break;
+                }
+            }
+            if (found) {
+                matches.put(mth, match);
+            }
+        }
+        // Start reordering
+        if (matches.size() != 1 && reorderArguments && arguments.size() > 1) {
+            Map<Method, List<Object>> nmatches = new HashMap<Method, List<Object>>();
+            for (Method mth : methods) {
+                ArgumentMatcher matcher = new ArgumentMatcher(mth.getGenericParameterTypes());
+                List<Object> match = matcher.match(args, types);
+                if (match != null) {
+                    nmatches.put(mth, match);
+                }
+            }
+            if (nmatches.size() > 0) {
+                matches = nmatches;
+            }
+        }
+        return matches;
+    }
+
+    private Map<Constructor, List<Object>> findMatchingConstructors(List<Object> args, List<Class> types, List<Object> arguments) {
+        Map<Constructor, List<Object>> matches = new HashMap<Constructor, List<Object>>();
+        // Get constructors
+        List<Constructor> constructors = new ArrayList<Constructor>(Arrays.asList(getType().getConstructors()));
+        // Discard any signature with wrong cardinality
+        for (Iterator<Constructor> it = constructors.iterator(); it.hasNext();) {
+            if (it.next().getParameterTypes().length != args.size()) {
+                it.remove();
+            }
+        }
+        // Find a direct match
+        for (Constructor cns : constructors) {
+            boolean found = true;
+            List<Object> match = new ArrayList<Object>();
+            for (int i = 0; i < args.size(); i++) {
+                if (types.get(i) != null && types.get(i) != cns.getParameterTypes()[i]) {
+                    found = false;
+                    break;
+                }
+                try {
+                    Object val = convert(args.get(i), cns.getGenericParameterTypes()[i]);
+                    match.add(val);
+                } catch (Throwable t) {
+                    found = false;
+                    break;
+                }
+            }
+            if (found) {
+                matches.put(cns, match);
+            }
+        }
+        // Start reordering
+        if (matches.size() != 1 && reorderArguments && arguments.size() > 1) {
+            Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
+            for (Constructor cns : constructors) {
+                ArgumentMatcher matcher = new ArgumentMatcher(cns.getGenericParameterTypes());
+                List<Object> match = matcher.match(args, types);
+                if (match != null) {
+                    nmatches.put(cns, match);
+                }
+            }
+            if (nmatches.size() > 0) {
+                matches = nmatches;
+            }
+        }
+        return matches;
+    }
+
     /**
      * Returns init method (if any). Throws exception if the init-method was set explicitly on the bean
      * and the method is not found on the instance.
@@ -366,20 +439,6 @@
         return method;
     }
     
-    public boolean canCreate(Type type) {
-        if (factoryMethod == null) {
-            Class myType = getType();
-            return RecipeHelper.isAssignable(type, myType) || RecipeHelper.isAssignable(type, myType);
-        } else {
-            // factory-method was specified, so we're not really sure what type of object we create
-            // until we actually create it
-            // TODO: is it possible to perform eager disambiguation on the factory method to get
-            //   the return type?
-            // TODO: this stuff should be moved to getType() instead
-            return true;
-        }
-    }
-
     @Override
     public List<Recipe> getConstructorRecipes() {
         return getNestedRecipes();
@@ -502,7 +561,7 @@
                 propertyValue = ((Recipe) propertyValue).create(type, false);
             }
             try {
-                propertyValue = blueprintContext.getConversionService().convert(propertyValue, toClass(type));
+                propertyValue = convert(propertyValue, type);
             } catch (Exception e) {
                 String valueType = propertyValue == null ? "null" : propertyValue.getClass().getName();
                 String memberType = type instanceof Class ? ((Class) type).getName() : type.toString();
@@ -530,6 +589,8 @@
     }
 
     PropertyDescriptor getPropertyDescriptor(Class clazz, String name) {
+        // TODO: it seems to fail in some cases, for example if there are two setters and no getters
+        //    it should throw an exception
         try {
             BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
             for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
@@ -543,4 +604,85 @@
         }
     }
 
+    private static Object UNMATCHED = new Object();
+
+    private class ArgumentMatcher {
+
+        private ConversionService converter;
+        private List<TypeEntry> entries;
+
+        public ArgumentMatcher(Type[] types) {
+            entries = new ArrayList<TypeEntry>();
+            for (Type type : types) {
+                entries.add(new TypeEntry(type));
+            }
+        }
+
+        public List<Object> match(List<Object> arguments, List<Class> forcedTypes) {
+            if (find(arguments, forcedTypes)) {
+                return getArguments();
+            }
+            return null;
+        }
+
+        private List<Object> getArguments() {
+            List<Object> list = new ArrayList<Object>();
+            for (TypeEntry entry : entries) {
+                if (entry.argument == UNMATCHED) {
+                    throw new RuntimeException("There are unmatched types");
+                } else {
+                    list.add(entry.argument);
+                }
+            }
+            return list;
+        }
+
+        private boolean find(List<Object> arguments, List<Class> forcedTypes) {
+            if (entries.size() == arguments.size()) {
+                boolean matched = true;
+                for (int i = 0; i < arguments.size() && matched; i++) {
+                    matched = find(arguments.get(i), forcedTypes.get(i));
+                }
+                return matched;
+            }
+            return false;
+        }
+
+        private boolean find(Object arg, Class forcedType) {
+            for (TypeEntry entry : entries) {
+                Object val = arg;
+                if (entry.argument != UNMATCHED) {
+                    continue;
+                }
+                if (forcedType != null) {
+                    if (forcedType != entry.type) {
+                        continue;
+                    }
+                } else if (arg != null) {
+                    try {
+                        val = convert(arg, entry.type);
+                    } catch (Throwable t) {
+                        continue;
+                    }
+                }
+                entry.argument = val;
+                return true;
+            }
+            return false;
+        }
+
+    }
+
+    private static class TypeEntry {
+
+        private final Type type;
+        private Object argument;
+
+        public TypeEntry(Type type) {
+            this.type = type;
+            this.argument = UNMATCHED;
+        }
+
+    }
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java Fri May 15 15:44:27 2009
@@ -23,6 +23,9 @@
 import java.util.ListIterator;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.geronimo.blueprint.Destroyable;
 import org.apache.xbean.recipe.ConstructionException;
@@ -34,54 +37,79 @@
  */
 public class BlueprintObjectRepository implements Repository {
 
-    private SortedMap<String, Object> instances;
+    private Map<String, Recipe> recipes;
+    private Map<String, Object> instances;
     private List<DestroyCallback> destroyList;
 
     public BlueprintObjectRepository() {
+        recipes = new TreeMap<String, Recipe>();
         instances = new TreeMap<String, Object>();
         destroyList = new ArrayList<DestroyCallback>();
     }
     
     public BlueprintObjectRepository(BlueprintObjectRepository source) {
-        instances = new TreeMap<String, Object>(source.instances);       
+        recipes = new TreeMap<String, Recipe>(source.recipes);
+        instances = new TreeMap<String, Object>(source.instances);
         destroyList = new ArrayList<DestroyCallback>();
     }
     
     public void set(String name, Object instance) {
-        instances.put(name, instance);
+        if (instance instanceof Recipe) {
+            recipes.put(name, (Recipe) instance);
+        } else {
+            instances.put(name, instance);
+        }
     }
     
     public boolean contains(String name) {
-        return instances.containsKey(name);
+        return recipes.containsKey(name) || instances.containsKey(name);
     }
 
     public Object get(String name) {
+        return instances.get(name) != null ? instances.get(name) : recipes.get(name);
+    }
+
+    public Object getInstance(String name) {
         return instances.get(name);
     }
 
+    public Recipe getRecipe(String name) {
+        return recipes.get(name);
+    }
+
+    public Set<String> getNames() {
+        Set<String> names = new HashSet<String>();
+        names.addAll(recipes.keySet());
+        names.addAll(instances.keySet());
+        return names;
+    }
+
     public void add(String name, Object instance) {
-        Object existingObj = instances.get(name);
-        if (existingObj != null) {
-            if (existingObj instanceof BlueprintObjectRecipe) {    
-                BlueprintObjectRecipe recipe = (BlueprintObjectRecipe) existingObj;
+        if (instances.get(name) != null) {
+            throw new ConstructionException("Name " + name + " is already registered to instance " + instances.get(name));
+        }
+        if (instance instanceof Recipe) {
+            recipes.put(name, (Recipe) instance);
+        } else {
+            if (recipes.get(name) instanceof BlueprintObjectRecipe) {
+                BlueprintObjectRecipe recipe = (BlueprintObjectRecipe) recipes.get(name);
                 Method method = recipe.getDestroyMethod(instance);
                 if (method != null) {
                     destroyList.add(new DestroyCallback(method, instance));
                 }
-            } else if (!(existingObj instanceof Recipe)) {
-                throw new ConstructionException("Name " + name + " is already registered to instance " + instance);
             }
+            instances.put(name, instance);
         }
+    }
 
-        instances.put(name, instance);
+    public void putRecipe(String name, Recipe recipe) {
+        recipes.put(name, recipe);
     }
 
-    public void updateRecipe(String name, Recipe recipe) {
-        if (instances.get(name) instanceof Recipe) {
-            instances.put(name, recipe);
-        }
+    public void putInstance(String name, Object instance) {
+        instances.put(name, instance);
     }
-        
+
     public void destroy() {
         // destroy objects in reverse creation order
         ListIterator<DestroyCallback> reverse = destroyList.listIterator(destroyList.size());

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/CollectionBasedServiceReferenceRecipe.java Fri May 15 15:44:27 2009
@@ -75,10 +75,6 @@
         return new Type[] { metadata.getCollectionType() };
     }
 
-    public boolean canCreate(Type type) {
-        return true;
-    }
-
     @Override
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         Comparator comparator = null;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/RecipeBuilder.java Fri May 15 15:44:27 2009
@@ -102,20 +102,16 @@
         for (String name : registry.getComponentDefinitionNames()) {
             ComponentMetadata component = registry.getComponentDefinition(name);
             Recipe recipe = createRecipe(component);
-            repository.add(name, recipe);
+            addRecipe(repository, recipe);
         }
         return repository;
     }
 
-    public void updateRepository(BlueprintObjectRepository repository) throws Exception {
-        for (String name : registry.getComponentDefinitionNames()) {
-            ComponentMetadata component = registry.getComponentDefinition(name);
-            Recipe recipe = createRecipe(component);
-            repository.updateRecipe(name, recipe);
-        }
+    private void addRecipe(BlueprintObjectRepository repository, Recipe recipe) {
+        repository.add(recipe.getName(), recipe); 
     }
 
-    private Recipe createRecipe(ComponentMetadata component) throws Exception {
+    public Recipe createRecipe(ComponentMetadata component) throws Exception {
         if (component instanceof BeanMetadata) {
             return createBeanRecipe((BeanMetadata) component);
         } else if (component instanceof ServiceMetadata) {
@@ -214,7 +210,7 @@
         recipe.setName(getName(local.getId()));
         recipe.setExplicitDependencies(local.getExplicitDependencies());
         for (BeanProperty property : local.getProperties()) {
-            Object value = getValue(property.getValue(), null);
+            Recipe value = getValue(property.getValue(), null);
             recipe.setProperty(property.getName(), value);
         }
         if (BeanMetadata.SCOPE_PROTOTYPE.equals(local.getScope())) {
@@ -232,7 +228,7 @@
             }
             List<Object> arguments = new ArrayList<Object>();
             for (BeanArgument argument : beanArguments) {
-                Object value = getValue(argument.getValue(), null);
+                Recipe value = getValue(argument.getValue(), null);
                 arguments.add(value);
             }
             recipe.setArguments(arguments);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ReferenceRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ReferenceRecipe.java Fri May 15 15:44:27 2009
@@ -64,24 +64,6 @@
         return getNestedRecipes();
     }
 
-    public boolean canCreate(Type type) {
-        if (referenceName == null) {
-            throw new ConstructionException("Reference name has not been set");
-        }
-
-        ExecutionContext context = ExecutionContext.getContext();
-
-        Object object = context.getObject(referenceName);
-        if (object instanceof Recipe) {
-            Recipe recipe = (Recipe) object;
-            return recipe.canCreate(type);
-        } else if (isServiceReferenceInjection(object, type)) {
-            return true;
-        } else {
-            return RecipeHelper.isInstance(type, object);
-        }
-    }
-
     public Type[] getTypes() {
         if (referenceName == null) {
             throw new ConstructionException("Reference name has not been set");

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceReferenceTracker.java Fri May 15 15:44:27 2009
@@ -63,21 +63,21 @@
         if (started) {
             return;
         }
+        satisfied = optional;
         context.addServiceListener(this, filter);
         ServiceReference[] references = context.getServiceReferences(null, filter);
         if (references != null) {
             for (ServiceReference reference : references) {
-                referenceSet.add(reference);
+                serviceAdded(new ServiceEvent(ServiceEvent.REGISTERED, reference));
             }
         }
-        satisfied = (optional) ? true : !referenceSet.isEmpty();   
         started = true;
     }
     
     public synchronized void stop() {
         context.removeServiceListener(this);
         referenceSet.clear();
-        satisfactionListeners.clear();
+        satisfied = false;
         started = false;
     }
     

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/UnaryServiceReferenceRecipe.java Fri May 15 15:44:27 2009
@@ -114,20 +114,6 @@
         }
     }
 
-    public boolean canCreate(Type type) {
-        try {
-            List<Class> interfaceList = getSupportedTypes();
-            for (Class clazz : interfaceList) {
-                if (RecipeHelper.isAssignable(type, clazz)) {
-                    return true;
-                }
-            }
-            return false;
-        } catch (ClassNotFoundException e) {
-            throw new ConstructionException(e);
-        }
-    }
-        
     @Override
     public void stop() {
         super.stop();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java Fri May 15 15:44:27 2009
@@ -72,18 +72,6 @@
         }
     }
 
-    public boolean canCreate(Type expectedType) {
-        // XXX: this is expensive but that's what spec wants
-        Class myType = determineType(type, expectedType);
-        
-        try {
-            conversionService.convert(value.getStringValue(), myType);
-            return true;
-        } catch (Exception e) {
-            return false;
-        }
-    }
-    
     public String toString() {
         return "ValueRecipe: " + type + " " + value.getStringValue();
     }

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java?rev=775197&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ConversionUtils.java Fri May 15 15:44:27 2009
@@ -0,0 +1,110 @@
+/**
+ * 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.utils;
+
+import java.lang.reflect.Type;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Array;
+import java.lang.reflect.ParameterizedType;
+import java.util.Collection;
+import java.util.Map;
+
+import org.osgi.service.blueprint.convert.ConversionService;
+import org.osgi.framework.ServiceReference;
+import org.apache.xbean.recipe.RecipeHelper;
+import static org.apache.xbean.recipe.RecipeHelper.toClass;
+import static org.apache.xbean.recipe.RecipeHelper.getTypeParameters;
+import org.apache.geronimo.blueprint.context.ServiceReferenceAccessor;
+
+/**
+ * TODO: javadoc
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 767120 $, $Date: 2009-04-21 13:53:32 +0200 (Tue, 21 Apr 2009) $
+ */
+public final class ConversionUtils {
+
+    private ConversionUtils() { }
+
+    public static Object convert(Object obj, Type type, ConversionService converter) throws Exception {
+        // Handle arrays, collections and generics
+        if (obj == null) {
+            return null;
+        } else if (type instanceof GenericArrayType || (type instanceof Class && ((Class) type).isArray())) {
+            if (obj instanceof Collection) {
+                obj = ((Collection) obj).toArray();
+            }
+            if (!obj.getClass().isArray()) {
+                throw new Exception("Unable to convert from " + obj + " to " + type);
+            }
+            Type componentType = type instanceof GenericArrayType
+                                        ? ((GenericArrayType) type).getGenericComponentType()
+                                        : ((Class) type).getComponentType();
+            Object array = Array.newInstance(toClass(componentType), Array.getLength(obj));
+            for (int i = 0; i < Array.getLength(obj); i++) {
+                try {
+                    Array.set(array, i, convert(Array.get(obj, i), componentType, converter));
+                } catch (Exception t) {
+                    throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting array element)", t);
+                }
+            }
+            return array;
+        // TODO: removing the second part of the test will allow conversion between collections, is this desired?
+        } else if (type instanceof ParameterizedType && toClass(type).isInstance(obj)) {
+            Class cl = toClass(type);
+            if (Map.class.isAssignableFrom(cl) && obj instanceof Map) {
+                Type keyType = Object.class;
+                Type valueType = Object.class;
+                Type[] typeParameters = getTypeParameters(Map.class, type);
+                if (typeParameters != null && typeParameters.length == 2) {
+                    keyType = typeParameters[0];
+                    valueType = typeParameters[1];
+                }
+                Map newMap = (Map) obj.getClass().newInstance();
+                for (Map.Entry e : ((Map<Object,Object>) obj).entrySet()) {
+                    try {
+                        newMap.put(convert(e.getKey(), keyType, converter), convert(e.getValue(), valueType, converter));
+                    } catch (Exception t) {
+                        throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t);
+                    }
+                }
+                return newMap;
+            } else if (Collection.class.isAssignableFrom(cl) && obj instanceof Collection) {
+                Type valueType = Object.class;
+                Type[] typeParameters = getTypeParameters(Collection.class, type);
+                if (typeParameters != null && typeParameters.length == 1) {
+                    valueType = typeParameters[0];
+                }
+                Collection newCol = (Collection) obj.getClass().newInstance();
+                for (Object item : (Collection) obj) {
+                    try {
+                        newCol.add(convert(item, valueType, converter));
+                    } catch (Exception t) {
+                        throw new Exception("Unable to convert from " + obj + " to " + type + "(error converting map entry)", t);
+                    }
+                }
+                return newCol;
+            }
+        } else if (type == ServiceReference.class && obj instanceof ServiceReferenceAccessor) {
+            return ((ServiceReferenceAccessor) obj).getServiceReference();
+        }
+        return converter.convert(obj, toClass(type));
+    }
+
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ReflectionUtils.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ReflectionUtils.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ReflectionUtils.java Fri May 15 15:44:27 2009
@@ -64,36 +64,11 @@
         return null;
     }
     
-    public static Method findMethod(Class clazz, String name, Class[] paramTypes) {
-        try {
-            return clazz.getMethod(name, paramTypes);
-        } catch (NoSuchMethodException e) {
-            return findCompatibleMethod(clazz, name, paramTypes);
-        }
-    }
-
-    public static Method findCompatibleMethod(Class clazz, String name, Class[] paramTypes) {
-        Method[] methods = clazz.getMethods();
-        for (Method method :  methods) {
-            Class[] methodParams = method.getParameterTypes();
-            if (name.equals(method.getName()) && methodParams.length == paramTypes.length) {
-                boolean assignable = true;
-                for (int i = 0; i < paramTypes.length && assignable; i++) {
-                    assignable = methodParams[i].isAssignableFrom(paramTypes[i]);
-                }
-                if (assignable) {
-                    return method;
-                }                        
-            }
-        }
-        return null;
-    }
-
     public static List<Method> findCompatibleMethods(Class clazz, String name, Class[] paramTypes) {
         List<Method> methods = new ArrayList<Method>();
         for (Method method : clazz.getMethods()) {
             Class[] methodParams = method.getParameterTypes();
-            if (name.equals(method.getName()) && methodParams.length == paramTypes.length) {
+            if (name.equals(method.getName()) && Void.TYPE.equals(method.getReturnType()) && methodParams.length == paramTypes.length) {
                 boolean assignable = true;
                 for (int i = 0; i < paramTypes.length && assignable; i++) {
                     assignable = methodParams[i].isAssignableFrom(paramTypes[i]);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ArrayRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ArrayRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ArrayRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ArrayRecipe.java Fri May 15 15:44:27 2009
@@ -97,12 +97,6 @@
         }
     }
 
-    public boolean canCreate(Type expectedType) {
-        Class expectedClass = RecipeHelper.toClass(expectedType);
-        Class myType = getType(expectedType);
-        return expectedClass.isArray() && RecipeHelper.isAssignable(expectedClass.getComponentType(), myType);
-    }
-
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         Class type = getType(expectedType);
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/CollectionRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/CollectionRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/CollectionRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/CollectionRecipe.java Fri May 15 15:44:27 2009
@@ -120,11 +120,6 @@
         return new Type[] { type };
     }
 
-    public boolean canCreate(Type expectedType) {
-        Class myType = getType(expectedType);
-        return RecipeHelper.isAssignable(expectedType, myType);
-    }
-
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         Class type = getType(expectedType);
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/MapRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/MapRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/MapRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/MapRecipe.java Fri May 15 15:44:27 2009
@@ -118,11 +118,6 @@
         return new Type[] { typeClass };
     }
 
-    public boolean canCreate(Type type) {
-        Class myType = getType(type);
-        return RecipeHelper.isAssignable(type, myType);
-    }
-
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         Class mapType = getType(expectedType);
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Recipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Recipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Recipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Recipe.java Fri May 15 15:44:27 2009
@@ -28,8 +28,6 @@
 
     Type[] getTypes();
 
-    boolean canCreate(Type type);
-
     Object create() throws ConstructionException;
     Object create(ClassLoader classLoader) throws ConstructionException;
     Object create(Type expectedType, boolean lazyRefAllowed) throws ConstructionException;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java Fri May 15 15:44:27 2009
@@ -110,44 +110,6 @@
         return instance == null || type.isInstance(instance);
     }
 
-    public static boolean isConvertable(Type type, Object propertyValue) {
-        if (propertyValue instanceof Recipe) {
-            Recipe recipe = (Recipe) propertyValue;
-            return recipe.canCreate(type);
-        }
-        throw new IllegalStateException();
-        //return (propertyValue instanceof String && PropertyEditors.canConvert(toClass(type)));
-    }
-
-    public static boolean isAssignableFrom(Class expected, Class actual) {
-        if (expected == null) return true;
-
-        if (expected.isPrimitive()) {
-            // verify actual is the correct wrapper type
-            if (expected.equals(boolean.class)) {
-                return actual.equals(Boolean.class);
-            } else if (expected.equals(char.class)) {
-                return actual.equals(Character.class);
-            } else if (expected.equals(byte.class)) {
-                return actual.equals(Byte.class);
-            } else if (expected.equals(short.class)) {
-                return actual.equals(Short.class);
-            } else if (expected.equals(int.class)) {
-                return actual.equals(Integer.class);
-            } else if (expected.equals(long.class)) {
-                return actual.equals(Long.class);
-            } else if (expected.equals(float.class)) {
-                return actual.equals(Float.class);
-            } else if (expected.equals(double.class)) {
-                return actual.equals(Double.class);
-            } else {
-                throw new AssertionError("Invalid primitve type: " + expected);
-            }
-        }
-
-        return expected.isAssignableFrom(actual);
-    }
-
     public static boolean isAssignable(Type expectedType, Type actualType) {
         Class expectedClass = toClass(expectedType);
         Class actualClass = toClass(actualType);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceNameRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceNameRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceNameRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceNameRecipe.java Fri May 15 15:44:27 2009
@@ -73,11 +73,6 @@
         return new Type[] { String.class };
     }
 
-    public boolean canCreate(Type type) {
-        Object object = getReference();
-        return String.class == RecipeHelper.toClass(type);
-    }
-
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         Object object = getReference();
         return referenceName;

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceRecipe.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReferenceRecipe.java Fri May 15 15:44:27 2009
@@ -71,22 +71,6 @@
         }
     }
 
-    public boolean canCreate(Type type) {
-        if (referenceName == null) {
-            throw new ConstructionException("Reference name has not been set");
-        }
-
-        ExecutionContext context = ExecutionContext.getContext();
-
-        Object object = context.getObject(referenceName);
-        if (object instanceof Recipe) {
-            Recipe recipe = (Recipe) object;
-            return recipe.canCreate(type);
-        } else {
-            return RecipeHelper.isInstance(type, object);
-        }
-    }
-
     protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException {
         if (referenceName == null) {
             throw new ConstructionException("Reference name has not been set");

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=775197&r1=775196&r2=775197&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 Fri May 15 15:44:27 2009
@@ -235,9 +235,13 @@
         
         Object obj8 = graph.create("multipleString");
         testMultiple(obj8, "123", -1, null);
-        
-        Object obj9 = graph.create("multipleStringConvertable");
-        testMultiple(obj9, "hello", -1, null);
+
+        try {
+            graph.create("multipleStringConvertable");
+            fail("Did not throw exception");
+        } catch (RuntimeException e) {
+            // we expect exception
+        }
         
         Object obj10 = graph.create("multipleFactory1");
         testMultiple(obj10, null, 1234, null);
@@ -256,8 +260,9 @@
         Object obj12 = graph.create("multipleFactoryTypedNull");
         testMultiple(obj12, "hello-boolean", -1, null);
 
-        Object obj13 = graph.create("mapConstruction");
-        Object obj14 = graph.create("propsConstruction");
+        // TODO: check the below tests when the incoherence between TCK / spec is solved
+//        Object obj13 = graph.create("mapConstruction");
+//        Object obj14 = graph.create("propsConstruction");
     }
     
     private void testPojoB(Object obj, URI uri, int intValue) {

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java?rev=775197&r1=775196&r2=775197&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java Fri May 15 15:44:27 2009
@@ -43,6 +43,7 @@
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
@@ -152,7 +153,9 @@
             mavenBundle("org.apache.geronimo", "blueprint-bundle"),
             mavenBundle("org.apache.geronimo", "blueprint-sample"),
 
-            felix(), equinox() //, knopflerfish()
+//            vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+            felix() //, equinox(), knopflerfish()
         );
 
         // use config generated by the Maven plugin (until PAXEXAM-62/64 get resolved)



Mime
View raw message