geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r774504 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ main/java/org/apache/geronimo/blueprint/utils/ main/java/org/apache/xbean/recipe/ test/java/org/apache/geronimo/blueprint/ test/ja...
Date Wed, 13 May 2009 20:08:11 GMT
Author: gnodet
Date: Wed May 13 20:08:10 2009
New Revision: 774504

URL: http://svn.apache.org/viewvc?rev=774504&view=rev
Log:
Add a getTypes() method on Recipes for better disambiguation (the canCreate should be removed
soon as it's not needed anymore)

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-ambiguous.xml
      - copied, changed from r774245, geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml
Removed:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/AllPropertiesRecipe.java
Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
    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/CollectionBasedServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
    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/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/ArgumentsMatch.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.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/ObjectRecipe.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/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-core/src/test/java/org/apache/geronimo/blueprint/pojos/Multiple.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-constructor.xml
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/AbstractServiceReferenceRecipe.java
Wed May 13 20:08:10 2009
@@ -19,6 +19,7 @@
 package org.apache.geronimo.blueprint.context;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -234,6 +234,7 @@
                         //       from the bundle and activating it)
                         //       the lazy activation should be a best effot and the lazy
creation of services should be
                         //       done in all cases
+                        //       Not sure about listeners
                         if (lazyActivation) {
                             registerTriggerServices();
                             state = State.WaitForTrigger;                            

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -71,6 +71,10 @@
         this.comparatorRecipe = comparatorRecipe;
     }
 
+    public Type[] getTypes() {
+        return new Type[] { metadata.getCollectionType() };
+    }
+
     public boolean canCreate(Type type) {
         return true;
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
Wed May 13 20:08:10 2009
@@ -1009,6 +1009,10 @@
             if (node instanceof Element) {
                 Element e = (Element) node;
                 if (nodeNameEquals(e, VALUE_ELEMENT)) {
+                    String v = getTextValue(e).trim();
+                    if (interfaceNames.contains(v)) {
+                        throw new ComponentDefinitionException("The element " + INTERFACES_ELEMENT
+ " should not contain the same interface twice");
+                    }
                     interfaceNames.add(getTextValue(e));
                 } else {
                     throw new ComponentDefinitionException("Unsupported element " + e.getNodeName()
+ " inside an " + INTERFACES_ELEMENT + " element");

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/TypedRecipe.java
Wed May 13 20:08:10 2009
@@ -68,6 +68,16 @@
         }
     }
 
+    public Type[] getTypes() {
+        if (type != null) {
+            return new Type[] { type };
+        }
+        if (value instanceof Recipe) {
+            return ((Recipe) value).getTypes();
+        }
+        return new Type[] { value != null ? value.getClass() : Object.class };
+    }
+
     public boolean canCreate(Type expectedType) {
         Class expectedClass = RecipeHelper.toClass(expectedType);
         if (type == null) {

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -21,6 +21,7 @@
 import java.lang.reflect.Type;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.List;
 
 import net.sf.cglib.proxy.Dispatcher;
 
@@ -86,6 +87,19 @@
         }
     }
 
+    public Type[] getTypes() {
+        try {
+            List<String> interfaceNames = metadata.getInterfaceNames();
+            Type[] types = new Type[interfaceNames.size()];
+            for (int i = 0; i < interfaceNames.size(); i++) {
+                types[i] = proxyClassLoader.loadClass(interfaceNames.get(i));
+            }
+            return types;
+        } catch (ClassNotFoundException e) {
+            throw new ConstructionException(e);
+        }
+    }
+
     public boolean canCreate(Type type) {
         return true;
     }

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -23,6 +23,8 @@
 import org.apache.xbean.recipe.AbstractRecipe;
 import org.apache.xbean.recipe.ConstructionException;
 import org.apache.xbean.recipe.RecipeHelper;
+import org.apache.xbean.recipe.Recipe;
+import org.apache.geronimo.blueprint.convert.ConversionServiceImpl;
 import org.osgi.service.blueprint.convert.ConversionService;
 import org.osgi.service.blueprint.reflect.ValueMetadata;
 
@@ -60,6 +62,16 @@
         }
     }
 
+    public Type[] getTypes() {
+        if (type != null) {
+            return new Type[] { type };
+        //} else if (value.getTypeName() != null) {
+            // TODO
+        } else {
+            return new Type[] { String.class };
+        }
+    }
+
     public boolean canCreate(Type expectedType) {
         // XXX: this is expensive but that's what spec wants
         Class myType = determineType(type, expectedType);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatch.java
Wed May 13 20:08:10 2009
@@ -80,6 +80,27 @@
     public String toString() {
         return method + " " + constructor + " " + arguments;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof ArgumentsMatch)) return false;
+
+        ArgumentsMatch that = (ArgumentsMatch) o;
+
+        if (constructor != null ? !constructor.equals(that.constructor) : that.constructor
!= null) return false;
+        if (method != null ? !method.equals(that.method) : that.method != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = method != null ? method.hashCode() : 0;
+        result = 31 * result + (constructor != null ? constructor.hashCode() : 0);
+        result = 31 * result + (arguments != null ? arguments.hashCode() : 0);
+        return result;
+    }
 }
 
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/utils/ArgumentsMatcher.java
Wed May 13 20:08:10 2009
@@ -21,12 +21,15 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import java.util.HashSet;
 
 import org.apache.xbean.recipe.Recipe;
 import org.apache.xbean.recipe.RecipeHelper;
+import org.apache.xbean.recipe.ReflectionUtil;
 
 /**
  * TODO: javadoc
@@ -46,24 +49,47 @@
         List<ArgumentsMatch> matches = new ArrayList<ArgumentsMatch>();
         Method[] methods = type.getMethods();
         
-        // look for matching method using the order of arguments specified    
+        boolean allowReorder = options.contains(Option.ARGUMENT_REORDER);
+
+        // look for matching method using the order of arguments specified
         for (Method method : methods) {
             if (method.getName().equals(name) && isAcceptable(method, options)) {
                 Class[] parameterTypes = method.getParameterTypes();
-                if (isAssignable(parameterTypes, arguments)) {
+                if (isAssignable(parameterTypes, arguments, false, true)) {
                     matches.add(new ArgumentsMatch(method, arguments));
                 }
             }
         }
-        
-        boolean allowReorder = options.contains(Option.ARGUMENT_REORDER); 
+
+        if (matches.size() == 0) {
+            for (Method method : methods) {
+                if (method.getName().equals(name) && isAcceptable(method, options))
{
+                    Class[] parameterTypes = method.getParameterTypes();
+                    if (isAssignable(parameterTypes, arguments, false, false)) {
+                        matches.add(new ArgumentsMatch(method, arguments));
+                    }
+                }
+            }
+        }
+
+        if (matches.size() == 0) {
+            for (Method method : methods) {
+                if (method.getName().equals(name) && isAcceptable(method, options))
{
+                    Class[] parameterTypes = method.getParameterTypes();
+                    if (isAssignable(parameterTypes, arguments, true, false)) {
+                        matches.add(new ArgumentsMatch(method, arguments));
+                    }
+                }
+            }
+        }
+
         if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
-            // we did not find any matching method, let's try re-ordering the arguments 
      
+            // we did not find any matching method, let's try re-ordering the arguments
             for (Method method : methods) {
                 if (method.getName().equals(name) && isAcceptable(method, options))
{
-                    Class[] parameterTypes = method.getParameterTypes();                
-                    if (parameterTypes.length == arguments.size()) {   
-                        ArgumentMatcher matcher = new ArgumentMatcher(method);
+                    Class[] parameterTypes = method.getParameterTypes();
+                    if (parameterTypes.length == arguments.size()) {
+                        ArgumentMatcher matcher = new ArgumentMatcher(method, false, true);
                         ArgumentsMatch match = matcher.match(arguments);
                         if (match != null) {
                             matches.add(match);
@@ -72,7 +98,39 @@
                 }
             }
         }
-        
+
+        if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
+            // we did not find any matching method, let's try re-ordering the arguments
+            for (Method method : methods) {
+                if (method.getName().equals(name) && isAcceptable(method, options))
{
+                    Class[] parameterTypes = method.getParameterTypes();
+                    if (parameterTypes.length == arguments.size()) {
+                        ArgumentMatcher matcher = new ArgumentMatcher(method, false, false);
+                        ArgumentsMatch match = matcher.match(arguments);
+                        if (match != null) {
+                            matches.add(match);
+                        }
+                    }
+                }
+            }
+        }
+
+        if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
+            // we did not find any matching method, let's try re-ordering the arguments
+            for (Method method : methods) {
+                if (method.getName().equals(name) && isAcceptable(method, options))
{
+                    Class[] parameterTypes = method.getParameterTypes();
+                    if (parameterTypes.length == arguments.size()) {
+                        ArgumentMatcher matcher = new ArgumentMatcher(method, true, false);
+                        ArgumentsMatch match = matcher.match(arguments);
+                        if (match != null) {
+                            matches.add(match);
+                        }
+                    }
+                }
+            }
+        }
+
         int size = matches.size();
         if (size == 0) {
             throw new RuntimeException("Did not find any matching method");
@@ -84,59 +142,117 @@
     }
        
     public static ArgumentsMatch findConstructor(Class type, List<Object> arguments,
Set<Option> options) { 
-        List<ArgumentsMatch> matches = new ArrayList<ArgumentsMatch>();
+        Set<ArgumentsMatch> matches = new HashSet<ArgumentsMatch>();
         Constructor[] constructors = type.getConstructors();
         
-        // look for matching constructor using the order of arguments specified in config
file                        
+        boolean allowReorder = options.contains(Option.ARGUMENT_REORDER);
+
+        // look for matching constructor using the exact match
         for (Constructor constructor : constructors) {
             Class[] parameterTypes = constructor.getParameterTypes();
-            if (isAssignable(parameterTypes, arguments)) {
+            if (isAssignable(parameterTypes, arguments, false, true)) {
                 matches.add(new ArgumentsMatch(constructor, arguments));
             }
         }
-            
-        boolean allowReorder = options.contains(Option.ARGUMENT_REORDER);
+
+        if (matches.size() == 0) {
+            for (Constructor constructor : constructors) {
+                Class[] parameterTypes = constructor.getParameterTypes();
+                if (isAssignable(parameterTypes, arguments, false, false)) {
+                    matches.add(new ArgumentsMatch(constructor, arguments));
+                }
+            }
+        }
+
+        // look for matching constructor using the order of arguments specified in config
file
+        if (matches.size() == 0) {
+            for (Constructor constructor : constructors) {
+                Class[] parameterTypes = constructor.getParameterTypes();
+                if (isAssignable(parameterTypes, arguments, true, false)) {
+                    matches.add(new ArgumentsMatch(constructor, arguments));
+                }
+            }
+        }
+
         if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
-            // we did not find any matching constructor, let's try re-ordering the arguments
           
+            // we did not find any matching constructor, let's try re-ordering the arguments
             for (Constructor constructor : constructors) {
-                Class[] parameterTypes = constructor.getParameterTypes();               
  
-                if (parameterTypes.length == arguments.size()) {   
-                    ArgumentMatcher matcher = new ArgumentMatcher(constructor);
+                Class[] parameterTypes = constructor.getParameterTypes();
+                if (parameterTypes.length == arguments.size()) {
+                    ArgumentMatcher matcher = new ArgumentMatcher(constructor, false, true);
                     ArgumentsMatch match = matcher.match(arguments);
                     if (match != null) {
                         matches.add(match);
-                    }                   
+                    }
                 }
             }
         }
-        
+
+        if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
+            // we did not find any matching constructor, let's try re-ordering the arguments
+            for (Constructor constructor : constructors) {
+                Class[] parameterTypes = constructor.getParameterTypes();
+                if (parameterTypes.length == arguments.size()) {
+                    ArgumentMatcher matcher = new ArgumentMatcher(constructor, false, false);
+                    ArgumentsMatch match = matcher.match(arguments);
+                    if (match != null) {
+                        matches.add(match);
+                    }
+                }
+            }
+        }
+
+        if (matches.size() == 0 && arguments.size() > 1 && allowReorder)
{
+            // we did not find any matching constructor, let's try re-ordering the
+            for (Constructor constructor : constructors) {
+                Class[] parameterTypes = constructor.getParameterTypes();
+                if (parameterTypes.length == arguments.size()) {
+                    ArgumentMatcher matcher = new ArgumentMatcher(constructor, true, false);
+                    ArgumentsMatch match = matcher.match(arguments);
+                    if (match != null) {
+                        matches.add(match);
+                    }
+                }
+            }
+        }
+
         int size = matches.size();
         if (size == 0) {
             throw new RuntimeException("Did not find any matching constructor");
         } else if (size == 1) {
-            return matches.get(0);
+            return matches.iterator().next();
         } else {
             throw new RuntimeException("Found multiple matching constructors");
         }
     }
     
-    public static boolean isAssignable(Class[] parameterTypes, List<Object> arguments)
{
+    public static boolean isAssignable(Class[] parameterTypes, List<Object> arguments,
boolean allowConversion, boolean strict) {
         if (parameterTypes.length == arguments.size()) {
             boolean assignable = true;
             for (int i = 0; i < parameterTypes.length && assignable; i++) {
-                assignable = isAssignable(parameterTypes[i], arguments.get(i));
+                assignable = isAssignable(parameterTypes[i], arguments.get(i), allowConversion,
strict);
             }
             return assignable;
         }
         return false;
     }
     
-    public static boolean isAssignable(Class type, Object argument) {
+    public static boolean isAssignable(Class type, Object argument, boolean allowConversion,
boolean strict) {
         if (argument == null) {
             return true;
         } else if (argument instanceof Recipe) {
             Recipe recipe = (Recipe) argument;
-            return recipe.canCreate(type);
+            if (allowConversion) {
+                // TODO: use conversion service
+                return recipe.canCreate(type);
+            } else {
+                for (Type t : recipe.getTypes()) {
+                    if (type.equals(RecipeHelper.toClass(t))) {
+                        return true;
+                    }
+                }
+                return false;
+            }
         } else {
             return RecipeHelper.isAssignableFrom(type, argument.getClass());
         }
@@ -157,15 +273,21 @@
         private List<TypeEntry> entries;
         private Method method;
         private Constructor constructor;
+        private boolean allowConversion;
+        private boolean strict;
         
-        public ArgumentMatcher(Constructor constructor) {
+        public ArgumentMatcher(Constructor constructor, boolean allowConversion, boolean
strict) {
             this.constructor = constructor;
             buildTypes(constructor.getParameterTypes());
+            this.allowConversion = allowConversion;
+            this.strict = strict;
         }
         
-        public ArgumentMatcher(Method method) {
+        public ArgumentMatcher(Method method, boolean allowConversion, boolean strict) {
             this.method = method;
             buildTypes(method.getParameterTypes());
+            this.allowConversion = allowConversion;
+            this.strict = strict;
         }
         
         private void buildTypes(Class[] types) {
@@ -222,7 +344,7 @@
         private boolean find(Object arg) {
             for (TypeEntry entry : entries) {
                 if (entry.getArgument() == null &&
-                    ArgumentsMatcher.isAssignable(entry.getType(), arg)) {
+                    ArgumentsMatcher.isAssignable(entry.getType(), arg, allowConversion,
strict)) {
                     entry.setArgument(arg);
                     return true;
                 }

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -82,6 +82,21 @@
         return Collections.emptyList();
     }
 
+    public Type[] getTypes() {
+        if (typeClass != null) {
+            return new Type[] { typeClass };
+        } else if (typeName != null) {
+            try {
+                Type type = RecipeHelper.loadClass(typeName);
+                return new Type[] { type };
+            } catch (ClassNotFoundException e) {
+                throw new ConstructionException("Type class could not be found: " + typeName);
+            }
+        } else {
+            return new Type[] { Object[].class };
+        }
+    }
+
     public boolean canCreate(Type expectedType) {
         Class expectedClass = RecipeHelper.toClass(expectedType);
         Class myType = 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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -105,6 +105,21 @@
         return Collections.emptyList();
     }
 
+    public Type[] getTypes() {
+        Class type = typeClass;
+        if (type == null && typeName != null) {
+            try {
+                type = RecipeHelper.loadClass(typeName);
+            } catch (ClassNotFoundException e) {
+                throw new ConstructionException("Type class could not be found: " + typeName);
+            }
+        }
+        if (type == null) {
+            type = Collection.class;
+        }
+        return new Type[] { type };
+    }
+
     public boolean canCreate(Type expectedType) {
         Class myType = getType(expectedType);
         return RecipeHelper.isAssignable(expectedType, myType);

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -114,6 +114,10 @@
         return Collections.emptyList();
     }
 
+    public Type[] getTypes() {
+        return new Type[] { typeClass };
+    }
+
     public boolean canCreate(Type type) {
         Class myType = getType(type);
         return RecipeHelper.isAssignable(type, myType);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectRecipe.java
Wed May 13 20:08:10 2009
@@ -250,6 +250,15 @@
         }
     }
 
+    public Type[] getTypes() {
+        Class type = getType();
+        if (type != null) {
+            return new Type[] { getType() };
+        } else{
+            return new Type[] { Object.class };
+        }
+    }
+
     public boolean canCreate(Type type) {
         Class myType = getType();
         return RecipeHelper.isAssignable(type, myType) || RecipeHelper.isAssignable(type,
myType);

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -26,6 +26,8 @@
 public interface Recipe extends Serializable {
     String getName();
 
+    Type[] getTypes();
+
     boolean canCreate(Type type);
 
     Object create() throws ConstructionException;

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -68,7 +68,11 @@
     public List<Recipe> getConstructorRecipes() {
         return getNestedRecipes();
     }
-    
+
+    public Type[] getTypes() {
+        return new Type[] { String.class };
+    }
+
     public boolean canCreate(Type type) {
         Object object = getReference();
         return String.class == RecipeHelper.toClass(type);

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=774504&r1=774503&r2=774504&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
Wed May 13 20:08:10 2009
@@ -57,6 +57,20 @@
         return getNestedRecipes();
     }
 
+    public Type[] getTypes() {
+        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.getTypes();
+        } else {
+            return new Type[] { object != null ? object.getClass() : Object.class };
+        }
+    }
+
     public boolean canCreate(Type type) {
         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=774504&r1=774503&r2=774504&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 13 20:08:10 2009
@@ -42,6 +42,17 @@
 
 public class WiringTest extends AbstractBlueprintTest {
 
+    // TODO: fix this test
+//    public void testAmbiguous() throws Exception {
+//        ComponentDefinitionRegistryImpl registry = parse("/test-ambiguous.xml");
+//        RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
+//        BlueprintObjectRepository repository = i.createRepository(registry);
+//        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+//
+//        Object obj1 = graph.create("ambiguous");
+//        fail("Should have failed");
+//    }
+
     public void testWiring() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
@@ -227,14 +238,6 @@
         Object obj5 = graph.create("pojoE");
         testPojoB(obj5, URI.create("urn:myuri-dynamic"), 20);
         
-        try {
-            graph.create("multipleFail");
-            fail("Did not throw exception");
-        } catch (RuntimeException e) {
-            // we expect exception 
-            // TODO: check the exception string?
-        }
-        
         Object obj6 = graph.create("multipleInt");
         testMultiple(obj6, null, 123, null);
         
@@ -262,7 +265,10 @@
         }
         
         Object obj12 = graph.create("multipleFactoryTypedNull");
-        testMultiple(obj12, "hello-boolean", -1, null);          
+        testMultiple(obj12, "hello-boolean", -1, null);
+
+        Object obj13 = graph.create("mapConstruction");
+        Object obj14 = graph.create("propsConstruction");
     }
     
     private void testPojoB(Object obj, URI uri, int intValue) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/Multiple.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/Multiple.java?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/Multiple.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/Multiple.java
Wed May 13 20:08:10 2009
@@ -18,11 +18,27 @@
  */
 package org.apache.geronimo.blueprint.pojos;
 
+import java.util.Map;
+import java.util.Properties;
+
 public class Multiple {
 
     private int intValue = -1;
     private Integer integerValue = null;
     private String stringValue = null;
+    private Map map;
+    private Properties properties;
+
+    public Multiple() {
+    }
+
+    public Multiple(Map map) {
+        this.map = map;
+    }
+
+    public Multiple(Properties props) {
+        this.properties = props;
+    }
 
     public Multiple(String arg) {   
         stringValue = arg;
@@ -36,6 +52,14 @@
         integerValue = arg;
     }
 
+    public Map getMap() {
+        return map;
+    }
+
+    public Properties getProperties() {
+        return properties;
+    }
+
     public int getInt() {
         return intValue;
     }
@@ -47,7 +71,13 @@
     public String getString() {
         return stringValue;
     }
-    
+
+    public void setAmbiguous(int v) {
+    }
+
+    public void setAmbiguous(Object v) {
+    }
+
     public static Multiple create(String arg1, Integer arg2) {
         return new Multiple(arg2.intValue());
     }

Copied: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-ambiguous.xml (from
r774245, geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-ambiguous.xml?p2=geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-ambiguous.xml&p1=geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml&r1=774245&r2=774504&rev=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-ambiguous.xml Wed May
13 20:08:10 2009
@@ -4,104 +4,8 @@
            default-init-method="init"
            default-destroy-method="destroy">
 
-    <type-converters>
-            <bean id="converter1" class="org.apache.geronimo.blueprint.pojos.ConverterA">
-                <property name="bundle" ref="bundle" />
-            </bean>
-    </type-converters>
-    
-    <service id="service1" ref="pojoB" interface="foo">
-        <service-properties>
-            <entry key="key1" value="value1"/>
-            <entry key="key2" value="value2"/>
-        </service-properties>    
-    </service>
-
-    <bean id="pojoC" class="org.apache.geronimo.blueprint.pojos.PojoB" scope = "prototype">
-        <property name="uri" value="urn:myuri" />
-    </bean>
-    
-    <bean id="pojoB" class="org.apache.geronimo.blueprint.pojos.PojoB" init-method = "init">
-        <property name="uri" value="urn:myuri" />
-    </bean>
-
-    <bean id="pojoA" class="org.apache.geronimo.blueprint.pojos.PojoA">
-        <property name="pojob" ref="pojoB"/>
-        <property name="map">
-            <map>
-                <entry key="key" value="val"/>
-                <entry key-ref="pojoB" value-ref="pojoB" />
-                <entry>
-                     <key><value type="java.lang.Integer">5</value></key>
-                     <value type="java.net.URI">http://geronimo.apache.org</value>
-                </entry>
-            </map>
-        </property>
-        <property name="set">
-            <set value-type="java.net.URI">
-                <value type="java.lang.String">set value</value>
-                <ref component="pojoB" />
-                <value>http://geronimo.apache.org</value>
-            </set>
-        </property>
-        <property name="list">
-            <list>
-                <value>list value</value>
-                <ref component="pojoC" />
-                <value type="java.lang.Integer">55</value>
-                <value type="java.net.URI">http://geronimo.apache.org</value>
-                <ref component="pojoC" />
-            </list>
-        </property>
-        <property name="props">
-            <props>
-                <prop key="key1" value="value1" />
-                <prop key="2" value="value2" />
-                <prop key="foo">bar</prop>
-            </props>
-        </property>
-        <property name="array">
-            <array>
-                <value>list value</value>
-                <ref component="pojoB" />
-                <value type="java.lang.Integer">55</value>
-                <value type="java.net.URI">http://geronimo.apache.org</value>
-            </array>
-        </property>        
-        <property name="intArray">
-            <array>
-                <value>1</value>
-                <value>50</value>
-                <value>100</value>
-            </array>
-        </property>
-        <property name="numberArray">
-            <array value-type="java.lang.Integer">
-                <value>1</value>
-                <value type="java.math.BigInteger">50</value>
-                <value type="java.lang.Long">100</value>
-                <value>200</value>
-            </array>
-        </property>
-        <property name="number">
-            <value type="java.math.BigInteger">10</value>
-        </property>
+    <bean id="ambiguous" class="org.apache.geronimo.blueprint.pojos.Multiple">
+        <property name="ambiguous" value="123"/>
     </bean>
 
-    <bean id="compound" class="org.apache.geronimo.blueprint.pojos.PojoB">
-        <property name="bean.name" value="hello bean property" />
-    </bean>
-    
-    <bean id="badIdRef" class="org.apache.geronimo.blueprint.pojos.BeanD">
-        <property name="name">
-          <idref component="doesnotexist"/>
-        </property>
-    </bean>
-    
-    <bean id="goodIdRef" class="org.apache.geronimo.blueprint.pojos.BeanD">
-        <property name="name">
-          <idref component="pojoA"/>
-        </property>
-    </bean>
-    
 </blueprint>
\ No newline at end of file

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-constructor.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-constructor.xml?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-constructor.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-constructor.xml Wed
May 13 20:08:10 2009
@@ -33,10 +33,6 @@
         <argument value="urn:myuri" />
     </bean>
     
-    <bean id="multipleFail" class="org.apache.geronimo.blueprint.pojos.Multiple">
-        <argument value="123"/>
-    </bean>
-    
     <bean id="multipleInt" class="org.apache.geronimo.blueprint.pojos.Multiple">
         <argument type="int" value="123"/>
     </bean>
@@ -77,4 +73,20 @@
         <argument type = "java.lang.Boolean"><null/></argument>
     </bean>
     
+    <bean id="mapConstruction" class="org.apache.geronimo.blueprint.pojos.Multiple">
+        <argument>
+            <map>
+                <entry key="a" value="b"/>
+            </map>
+        </argument>
+    </bean>
+
+    <bean id="propsConstruction" class="org.apache.geronimo.blueprint.pojos.Multiple">
+        <argument>
+            <props>
+                <prop key="a" value="b"/>
+            </props>
+        </argument>
+    </bean>
+
 </blueprint>

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml?rev=774504&r1=774503&r2=774504&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-wiring.xml Wed May 13
20:08:10 2009
@@ -103,5 +103,5 @@
           <idref component="pojoA"/>
         </property>
     </bean>
-    
+
 </blueprint>
\ No newline at end of file



Mime
View raw message