geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r776242 [2/2] - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/ main/java/org/apache/geronimo/blueprint/context/ main/java/org/apache/geronimo/blueprint/utils/ main/java/org/apache/xbean/recipe/ t...
Date Tue, 19 May 2009 08:58:46 GMT
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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -17,27 +17,22 @@
 package org.apache.xbean.recipe;
 
 import java.lang.reflect.Array;
-import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 
-import org.osgi.service.blueprint.convert.ConversionService;
-import org.apache.geronimo.blueprint.utils.ConversionUtils;
-
 /**
  * @version $Rev$ $Date$
  */
 public class ArrayRecipe extends AbstractRecipe {
+
     private final List<Recipe> list;
     private Class typeClass;
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
-    private final ConversionService conversionService;
 
-    public ArrayRecipe(ConversionService conversionService, Class type) {
-        this.conversionService = conversionService;
+    public ArrayRecipe(Class type) {
         this.list = new ArrayList<Recipe>();
         this.typeClass = type;
     }
@@ -68,7 +63,7 @@
         return Collections.emptyList();
     }
 
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
+    protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
         Class type = typeClass != null ? typeClass : Object.class;
 
         // create array instance
@@ -91,7 +86,7 @@
             Object value;
             if (recipe != null) {
                 try {
-                    value = ConversionUtils.convert(recipe.create(Object.class, refAllowed),
type, conversionService);
+                    value = convert(recipe.create(refAllowed), type);
                 } catch (Exception e) {
                     throw new ConstructionException("Unable to convert value " + recipe +
" to type " + type, e);
                 }
@@ -112,23 +107,6 @@
         return array;
     }
 
-    private Class getType(Type expectedType) {       
-        Class expectedClass = RecipeHelper.toClass(expectedType);
-        if (expectedClass.isArray()) {
-            expectedClass = expectedClass.getComponentType();
-        }
-        Class type = expectedClass;
-        if (typeClass != null ) {
-            type = typeClass;
-            // in case where expectedType is a subclass of the assigned type
-            if (type.isAssignableFrom(expectedClass)) {
-                type = expectedClass;
-            }
-        }
-
-        return type;
-    }
-
     public void add(Recipe value) {
         list.add(value);
     }

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -20,11 +20,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Dictionary;
 import java.util.EnumSet;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -34,51 +32,14 @@
  */
 public class CollectionRecipe extends AbstractRecipe {
     private final List<Recipe> list;
-    private String typeName;
     private Class typeClass;
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
 
-    public CollectionRecipe() {
-        list = new ArrayList<Recipe>();
-    }
-
-    public CollectionRecipe(String type) {
-        list = new ArrayList<Recipe>();
-        this.typeName = type;
-    }
-
     public CollectionRecipe(Class type) {
-        if (type == null) throw new NullPointerException("type is null");
         this.list = new ArrayList<Recipe>();
         this.typeClass = type;
     }
 
-    public CollectionRecipe(Collection<Recipe> collection) {
-        if (collection == null) throw new NullPointerException("collection is null");
-
-        this.list = new ArrayList<Recipe>(collection);
-
-        // If the specified collection has a default constructor we will recreate the collection,
otherwise we use a the default
-        if (RecipeHelper.hasDefaultConstructor(collection.getClass())) {
-            this.typeClass = collection.getClass();
-        } else if (collection instanceof SortedSet) {
-            this.typeClass = SortedSet.class;
-        } else if (collection instanceof Set) {
-            this.typeClass = Set.class;
-        } else if (collection instanceof List) {
-            this.typeClass = List.class;
-        } else {
-            this.typeClass = Collection.class;
-        }
-    }
-
-    public CollectionRecipe(CollectionRecipe collectionRecipe) {
-        if (collectionRecipe == null) throw new NullPointerException("setRecipe is null");
-        this.typeName = collectionRecipe.typeName;
-        this.typeClass = collectionRecipe.typeClass;
-        list = new ArrayList<Recipe>(collectionRecipe.list);
-    }
-
     public void allow(Option option) {
         options.add(option);
     }
@@ -105,8 +66,8 @@
         return Collections.emptyList();
     }
 
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
-        Class type = getType(expectedType);
+    protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
+        Class type = getType(Object.class);
 
         if (!RecipeHelper.hasDefaultConstructor(type)) {
             throw new ConstructionException("Type does not have a default constructor " +
type.getName());
@@ -129,18 +90,20 @@
             ExecutionContext.getContext().addObject(getName(), instance);
         }
 
-        // get component type
-        Type[] typeParameters = RecipeHelper.getTypeParameters(Collection.class, expectedType);
-        Type componentType = Object.class;
-        if (typeParameters != null && typeParameters.length == 1 && typeParameters[0]
instanceof Class) {
-            componentType = typeParameters[0];
-        }
-
         boolean refAllowed = options.contains(Option.LAZY_ASSIGNMENT);
 
         int index = 0;
         for (Recipe recipe : list) {
-            Object value = recipe != null ? recipe.create(componentType, refAllowed) : recipe;
+            Object value;
+            if (recipe != null) {
+                try {
+                    value = recipe.create(refAllowed);
+                } catch (Exception e) {
+                    throw new ConstructionException("Unable to convert value " + recipe +
" to type " + type, e);
+                }
+            } else {
+                value = null;
+            }
 
             if (value instanceof Reference) {
                 Reference reference = (Reference) value;
@@ -163,16 +126,8 @@
 
     private Class getType(Type expectedType) {
         Class expectedClass = RecipeHelper.toClass(expectedType);
-        if (typeClass != null || typeName != null) {
+        if (typeClass != null) {
             Class type = typeClass;
-            if (type == null) {
-                try {
-                    type = RecipeHelper.loadClass(typeName);
-                } catch (ClassNotFoundException e) {
-                    throw new ConstructionException("Type class could not be found: " + typeName);
-                }
-            }
-
             // if expectedType is a subclass of the assigned type,
             // we use it assuming it has a default constructor
             if (type.isAssignableFrom(expectedClass)) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultExecutionContext.java?rev=776242&r1=776241&r2=776242&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultExecutionContext.java
Tue May 19 08:58:45 2009
@@ -17,7 +17,18 @@
  */
 package org.apache.xbean.recipe;
 
-import java.util.*;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.geronimo.blueprint.utils.ConversionUtils;
+import org.osgi.service.blueprint.convert.ConversionService;
 
 public class DefaultExecutionContext extends ExecutionContext {
     /**
@@ -25,6 +36,8 @@
      */
     private Repository repository;
 
+    private ConversionService conversionService;
+
     /**
      * Contains partial objects.
      */
@@ -43,12 +56,14 @@
      */
     private final SortedMap<String, List<Reference>> unresolvedRefs = new TreeMap<String,
List<Reference>>();
 
-    public DefaultExecutionContext() {
-        this(new DefaultRepository());
+    public DefaultExecutionContext(ConversionService conversionService) {
+        this(conversionService, new DefaultRepository());
     }
 
-    public DefaultExecutionContext(Repository repository) {
+    public DefaultExecutionContext(ConversionService conversionService, Repository repository)
{
+        if (conversionService == null) throw new NullPointerException("conversionService
is null");
         if (repository == null) throw new NullPointerException("repository is null");
+        this.conversionService = conversionService;
         this.repository = repository;
     }
 
@@ -158,9 +173,7 @@
         return unresolvedRefs;
     }
 
-    public ClassLoader getClassLoader() {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader == null) classLoader = getClass().getClassLoader();
-        return classLoader;
+    public Object convert(Object value, Type type) throws Exception {
+        return ConversionUtils.convert(value, type, conversionService);
     }
 }

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultRepository.java?rev=776242&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultRepository.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/DefaultRepository.java
Tue May 19 08:58:45 2009
@@ -0,0 +1,127 @@
+/**
+ *
+ * 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.xbean.recipe;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.geronimo.blueprint.Destroyable;
+
+/**
+ * 
+ */
+public class DefaultRepository implements Repository {
+
+    private Map<String, Object> defaults;
+    private Map<String, Recipe> recipes;
+    private Map<String, Object> instances;
+    private List<Destroyable> destroyList;
+
+    public DefaultRepository() {
+        recipes = new TreeMap<String, Recipe>();
+        defaults = new TreeMap<String, Object>();
+        instances = new TreeMap<String, Object>();
+        destroyList = new ArrayList<Destroyable>();
+    }
+    
+    public DefaultRepository(DefaultRepository source) {
+        recipes = new TreeMap<String, Recipe>(source.recipes);
+        defaults = new TreeMap<String, Object>();
+        instances = new TreeMap<String, Object>(source.instances);
+        destroyList = new ArrayList<Destroyable>();
+    }
+
+    public void set(String name, Object instance) {
+        if (instance instanceof Recipe) {
+            recipes.put(name, (Recipe) instance);
+        } else {
+            instances.put(name, instance);
+        }
+    }
+    
+    public boolean contains(String name) {
+        return recipes.containsKey(name) || instances.containsKey(name) || defaults.containsKey(name);
+    }
+
+    public Object get(String name) {
+        return instances.get(name) != null ? instances.get(name) : (recipes.get(name) !=
null ? recipes.get(name) : defaults.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());
+        names.addAll(defaults.keySet());
+        return names;
+    }
+
+    public void add(String name, Object instance) {
+        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 {
+            Recipe recipe = recipes.get(name);
+            if (recipe != null) {
+                Destroyable destroy = recipe.getDestroyable(instance);
+                if (destroy != null) {
+                    destroyList.add(destroy);
+                }
+            }
+            instances.put(name, instance);
+        }
+    }
+
+    public void putDefault(String name, Object instance) {
+        defaults.put(name, instance);
+    }
+
+    public void putRecipe(String name, Recipe recipe) {
+        recipes.put(name, recipe);
+    }
+
+    public void putInstance(String name, Object instance) {
+        instances.put(name, instance);
+    }
+
+    public void destroy() {
+        // destroy objects in reverse creation order
+        ListIterator<Destroyable> reverse = destroyList.listIterator(destroyList.size());
+        while(reverse.hasPrevious()) {
+            reverse.previous().destroy();
+        }
+
+        destroyList.clear();
+        instances.clear();
+    }
+    
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ExecutionContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ExecutionContext.java?rev=776242&r1=776241&r2=776242&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ExecutionContext.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ExecutionContext.java
Tue May 19 08:58:45 2009
@@ -20,8 +20,10 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.lang.reflect.Type;
 
 public abstract class ExecutionContext {
+
     private static final ThreadLocal<ExecutionContext> context = new ThreadLocal<ExecutionContext>();
 
     public static boolean isContextSet() {
@@ -89,9 +91,7 @@
      */
     public abstract void addObject(String name, Object object, boolean partialObject);
     
-    public void addObject(String name, Object object) {
-        addObject(name, object, false);
-    }
+    public abstract void addObject(String name, Object object);
 
     /**
      * Adds a reference to an object to this context.  If an object is already registered
under
@@ -109,15 +109,9 @@
      */
     public abstract Map<String, List<Reference>> getUnresolvedRefs();
 
-    /**
-     * Gets the class loader used for loading of all classes during the
-     * life of this execution context
-     * @return the class loader for loading classes in this context
-     */
-    public abstract ClassLoader getClassLoader();
-    
     public abstract boolean containsCreatedObject(String name);
     
     public abstract Object getCreatedObject(String name);
-    
+
+    public abstract Object convert(Object value, Type type) throws Exception;
 }

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -32,6 +32,10 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import org.osgi.service.blueprint.convert.ConversionService;
+import org.apache.geronimo.blueprint.utils.ConversionUtils;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContext;
+
 /**
  * @version $Rev: 6687 $ $Date: 2005-12-28T21:08:56.733437Z $
  */
@@ -40,38 +44,10 @@
     private Class typeClass;
     private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
 
-    public MapRecipe() {
-        entries = new ArrayList<Recipe[]>();
-    }
-
     public MapRecipe(Class type) {
         if (type == null) throw new NullPointerException("type is null");
         this.typeClass = type;
-        entries = new ArrayList<Recipe[]>();
-    }
-
-    public MapRecipe(Map<Recipe,Recipe> map) {
-        if (map == null) throw new NullPointerException("map is null");
-
-        entries = new ArrayList<Recipe[]>(map.size());
-
-        // If the specified set has a default constructor we will recreate the set, otherwise
we use a LinkedHashMap or TreeMap
-        if (RecipeHelper.hasDefaultConstructor(map.getClass())) {
-            this.typeClass = map.getClass();
-        } else if (map instanceof SortedMap) {
-            this.typeClass = TreeMap.class;
-        } else if (map instanceof ConcurrentMap) {
-            this.typeClass = ConcurrentHashMap.class;
-        } else {
-            this.typeClass = LinkedHashMap.class;
-        }
-        putAll(map);
-    }
-
-    public MapRecipe(MapRecipe mapRecipe) {
-        if (mapRecipe == null) throw new NullPointerException("mapRecipe is null");
-        this.typeClass = mapRecipe.typeClass;
-        entries = new ArrayList<Recipe[]>(mapRecipe.entries);
+        this.entries = new ArrayList<Recipe[]>();
     }
 
     public void allow(Option option){
@@ -107,8 +83,8 @@
         return Collections.emptyList();
     }
 
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
-        Class mapType = getType(expectedType);
+    protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
+        Class mapType = getType(Object.class);
 
         if (!RecipeHelper.hasDefaultConstructor(mapType)) {
             throw new ConstructionException("Type does not have a default constructor " +
mapType.getName());
@@ -130,19 +106,6 @@
             throw new ConstructionException("Specified map type does not implement the Map
interface: " + mapType.getName());
         }
 
-        // get component type
-        Type keyType = Object.class;
-        Type valueType = Object.class;
-        Type[] typeParameters = RecipeHelper.getTypeParameters(Map.class, expectedType);
-        if (typeParameters != null && typeParameters.length == 2) {
-            if (typeParameters[0] instanceof Class) {
-                keyType = typeParameters[0];
-            }
-            if (typeParameters[1] instanceof Class) {
-                valueType = typeParameters[1];
-            }
-        }
-
         // add to execution context if name is specified
         if (getName() != null) {
             ExecutionContext.getContext().addObject(getName(), instance);
@@ -151,8 +114,8 @@
         // add map entries
         boolean refAllowed = options.contains(Option.LAZY_ASSIGNMENT);
         for (Recipe[] entry : entries) {
-            Object key = entry[0].create(keyType, refAllowed);
-            Object value = entry[1] != null ? entry[1].create(valueType, refAllowed) : null;
+            Object key = entry[0].create(refAllowed);
+            Object value = entry[1] != null ? entry[1].create(refAllowed) : null;
 
             if (key instanceof Reference) {
                 // when the key reference and optional value reference are both resolved

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectGraph.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectGraph.java?rev=776242&r1=776241&r2=776242&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectGraph.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ObjectGraph.java
Tue May 19 08:58:45 2009
@@ -25,16 +25,19 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Iterator;
+import java.lang.reflect.Type;
+
+import org.osgi.service.blueprint.convert.ConversionService;
 
 public class ObjectGraph {
-    private Repository repository;
 
-    public ObjectGraph() {
-        this(new DefaultRepository());
-    }
+    private ConversionService conversionService;
+    private Repository repository;
 
-    public ObjectGraph(Repository repository) {
+    public ObjectGraph(ConversionService conversionService, Repository repository) {
+        if (conversionService == null) throw new NullPointerException("conversionService
is null");
         if (repository == null) throw new NullPointerException("repository is null");
+        this.conversionService = conversionService;
         this.repository = repository;
     }
 
@@ -64,7 +67,7 @@
         // setup execution context
         boolean createNewContext = !ExecutionContext.isContextSet();
         if (createNewContext) {
-            ExecutionContext.setContext(new DefaultExecutionContext(repository));
+            ExecutionContext.setContext(new DefaultExecutionContext(conversionService, repository));
         }
         WrapperExecutionContext wrapperContext = new WrapperExecutionContext(ExecutionContext.getContext());
         ExecutionContext.setContext(wrapperContext);
@@ -90,7 +93,7 @@
                 String name = entry.getKey();
                 Recipe recipe = entry.getValue();
                 if (!wrapperContext.containsObject(name) || wrapperContext.getObject(name)
instanceof Recipe) {
-                    recipe.create(Object.class, false);
+                    recipe.create(false);
                 }
             }
 
@@ -272,6 +275,10 @@
             constructedObject.put(name, object);
         }
 
+        public void addObject(String name, Object object) {
+            addObject(name, object, false);
+        }
+
         public void addReference(Reference reference) {
             executionContext.addReference(reference);
         }
@@ -280,10 +287,6 @@
             return executionContext.getUnresolvedRefs();
         }
 
-        public ClassLoader getClassLoader() {
-            return executionContext.getClassLoader();
-        }
-
         public boolean containsCreatedObject(String name) {
             return executionContext.containsCreatedObject(name);
         }
@@ -291,5 +294,9 @@
         public Object getCreatedObject(String name) {
             return executionContext.getCreatedObject(name);
         }
+
+        public Object convert(Object value, Type type) throws Exception {
+            return executionContext.convert(value, type);
+        }
     }
 }

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -20,17 +20,21 @@
 import java.util.List;
 import java.lang.reflect.Type;
 
+import org.apache.geronimo.blueprint.Destroyable;
+
 /**
  * @version $Rev: 6680 $ $Date: 2005-12-24T04:38:27.427468Z $
  */
-public interface Recipe extends Serializable {
+public interface Recipe {
+
     String getName();
 
     Object create() throws ConstructionException;
-    Object create(ClassLoader classLoader) throws ConstructionException;
-    Object create(Type expectedType, boolean lazyRefAllowed) throws ConstructionException;
+    Object create(boolean lazyRefAllowed) throws ConstructionException;
 
     List<Recipe> getNestedRecipes();
 
     List<Recipe> getConstructorRecipes();
+
+    Destroyable getDestroyable(Object instance);
 }

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -39,12 +39,6 @@
     private RecipeHelper() {
     }
 
-    public static Class loadClass(String name) throws ClassNotFoundException {
-        ClassLoader classLoader = ExecutionContext.getContext().getClassLoader();
-        Class<?> type = Class.forName(name, true, classLoader);
-        return type;
-    }
-
     public static boolean hasDefaultConstructor(Class type) {
         if (!Modifier.isPublic(type.getModifiers())) {
             return false;
@@ -62,21 +56,6 @@
         return false;
     }
 
-    public static boolean isSimpleType(Object o) {
-        return  o == null ||
-                o instanceof Boolean ||
-                o instanceof Character ||
-                o instanceof Byte ||
-                o instanceof Short ||
-                o instanceof Integer ||
-                o instanceof Long ||
-                o instanceof Float ||
-                o instanceof Double ||
-                o instanceof String ||
-                o instanceof Recipe;
-
-    }
-
     public static boolean isInstance(Type t, Object instance) {
         Class type = toClass(t);
         if (type.isPrimitive()) {

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -27,6 +27,7 @@
 import org.apache.xbean.recipe.NoSuchObjectException;
 import org.apache.xbean.recipe.Recipe;
 import org.apache.xbean.recipe.RecipeHelper;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContext;
 
 /*
  * The ReferenceNameRecipe is used to inject the reference name into the object (as a String).
@@ -69,7 +70,7 @@
         return getNestedRecipes();
     }
 
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
+    protected Object internalCreate(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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -21,12 +21,11 @@
 import java.util.List;
 import java.lang.reflect.Type;
 
+import org.apache.geronimo.blueprint.ExtendedBlueprintContext;
+
 public class ReferenceRecipe extends AbstractRecipe {
     private String referenceName;
 
-    public ReferenceRecipe() {
-    }
-
     public ReferenceRecipe(String referenceName) {
         this.referenceName = referenceName;
     }
@@ -57,7 +56,7 @@
         return getNestedRecipes();
     }
 
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
+    protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
         if (referenceName == null) {
             throw new ConstructionException("Reference name has not been set");
         }
@@ -83,7 +82,7 @@
                     object = reference;
                 } else {
                     Recipe recipe = (Recipe) object;
-                    object = recipe.create(expectedType, false);
+                    object = recipe.create(false);
                 }
 
             }

Copied: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ValueRecipe.java
(from r775978, 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/xbean/recipe/ValueRecipe.java?p2=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ValueRecipe.java&p1=geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ValueRecipe.java&r1=775978&r2=776242&rev=776242&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/xbean/recipe/ValueRecipe.java
Tue May 19 08:58:45 2009
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.geronimo.blueprint.context;
+package org.apache.xbean.recipe;
 
 import java.lang.reflect.Type;
 
@@ -25,6 +25,7 @@
 import org.apache.xbean.recipe.RecipeHelper;
 import org.apache.xbean.recipe.Recipe;
 import org.apache.geronimo.blueprint.convert.ConversionServiceImpl;
+import org.apache.geronimo.blueprint.ExtendedBlueprintContext;
 import org.osgi.service.blueprint.convert.ConversionService;
 import org.osgi.service.blueprint.reflect.ValueMetadata;
 
@@ -36,27 +37,18 @@
  */
 public class ValueRecipe extends AbstractRecipe {
 
-    private ConversionService conversionService;
     private ValueMetadata value;
     private Class type;
 
-    public ValueRecipe(ConversionService conversionService, ValueMetadata value, Class type)
{
-        this.conversionService = conversionService;
+    public ValueRecipe(ValueMetadata value, Class type) {
         this.value = value;
         this.type = type;
     }
 
-    private static Class determineType(Class type, Type defaultType) {
-        // TODO: check if type is assignable from defaultType?
-        return (type != null) ? type : RecipeHelper.toClass(defaultType);
-    }
-
     @Override
-    protected Object internalCreate(Type expectedType, boolean lazyRefAllowed) throws ConstructionException
{
-        Class myType = determineType(type, expectedType);
-
+    protected Object internalCreate(boolean lazyRefAllowed) throws ConstructionException
{
         try {
-            return conversionService.convert(value.getStringValue(), myType);
+            return convert(value.getStringValue(), type != null ? type : Object.class);
         } catch (Exception e) {            
             throw new ConstructionException(e);
         }

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ValueRecipe.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ValueRecipe.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ValueRecipe.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=776242&r1=776241&r2=776242&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
Tue May 19 08:58:45 2009
@@ -29,7 +29,7 @@
 
 import org.apache.geronimo.blueprint.CallbackTracker.Callback;
 import org.apache.geronimo.blueprint.context.BlueprintObjectInstantiator;
-import org.apache.geronimo.blueprint.context.BlueprintObjectRepository;
+import org.apache.xbean.recipe.DefaultRepository;
 import org.apache.geronimo.blueprint.context.RecipeBuilder;
 import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.geronimo.blueprint.pojos.BeanD;
@@ -38,6 +38,8 @@
 import org.apache.geronimo.blueprint.pojos.PojoB;
 import org.apache.geronimo.blueprint.pojos.PojoGenerics;
 import org.apache.geronimo.blueprint.pojos.PojoListener;
+import org.apache.geronimo.blueprint.pojos.BeanF;
+import org.apache.geronimo.blueprint.convert.ConversionServiceImpl;
 import org.apache.xbean.recipe.Repository;
 import org.osgi.framework.ServiceRegistration;
 
@@ -46,8 +48,8 @@
     public void testWiring() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
-        BlueprintObjectRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        DefaultRepository repository = i.createRepository();
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
         
         Object obj1 = graph.create("pojoA");
         assertNotNull(obj1);
@@ -136,8 +138,8 @@
     public void testCompoundProperties() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
-        BlueprintObjectRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        DefaultRepository repository = i.createRepository();
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
         
         Object obj5 = graph.create("compound");
         assertNotNull(obj5);
@@ -150,8 +152,8 @@
     public void testIdRefs() throws Exception {
         ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
-        BlueprintObjectRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        DefaultRepository repository = i.createRepository();
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
         
         try {
             graph.create("badIdRef");
@@ -174,8 +176,8 @@
 
         ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
-        BlueprintObjectRepository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        DefaultRepository repository = i.createRepository();
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
         Map instances = graph.createAll("c", "d", "e");
         
         List<Callback> callback = CallbackTracker.getCallbacks();
@@ -206,8 +208,8 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-constructor.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
-        
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
+
         Object obj1 = graph.create("pojoA");
         assertNotNull(obj1);
         assertTrue(obj1 instanceof PojoA);
@@ -265,6 +267,17 @@
         // TODO: check the below tests when the incoherence between TCK / spec is solved
 //        Object obj13 = graph.create("mapConstruction");
 //        Object obj14 = graph.create("propsConstruction");
+
+        BeanF obj15 = (BeanF) graph.create("booleanWrapped");
+        assertNotNull(obj15.getWrapped());
+        assertEquals(false, (boolean) obj15.getWrapped());
+        assertNull(obj15.getPrim());
+
+        // TODO: check the below tests when the incoherence between TCK / spec is solved
+//        BeanF obj16 = (BeanF) graph.create("booleanPrim");
+//        assertNotNull(obj16.getPrim());
+//        assertEquals(false, (boolean) obj16.getPrim());
+//        assertNull(obj16.getWrapped());
     }
     
     private void testPojoB(Object obj, URI uri, int intValue) {
@@ -287,7 +300,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
         
         List<Integer> expectedList = new ArrayList<Integer>();
         expectedList.add(new Integer(10));
@@ -338,7 +351,7 @@
         ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
         RecipeBuilder i = new RecipeBuilder(new TestBlueprintContext(registry));
         Repository repository = i.createRepository();
-        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(repository);
+        BlueprintObjectInstantiator graph = new BlueprintObjectInstantiator(new ConversionServiceImpl(null),
repository);
 
         // this should pass (we allow circular dependencies for components without init method)
         Object obj1 = graph.create("a");

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanF.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanF.java?rev=776242&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanF.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanF.java
Tue May 19 08:58:45 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.pojos;
+
+public class BeanF {
+
+    private Boolean wrapped;
+    private Boolean prim;
+
+    public BeanF(Boolean wrapped) {
+        this.wrapped = wrapped;
+    }
+
+    public BeanF(boolean prim) {
+        this.prim = prim;
+    }
+
+    public Boolean getWrapped() {
+        return wrapped;
+    }
+
+    public Boolean getPrim() {
+        return prim;
+    }
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-circular.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-circular.xml?rev=776242&r1=776241&r2=776242&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-circular.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-circular.xml Tue May
19 08:58:45 2009
@@ -48,10 +48,10 @@
         <service-properties>
             <entry key="key1" value="value1"/>
             <entry key="key2" value="value2"/>
-        </service-properties>    
+        </service-properties>
         <registration-listener ref="listener"
            registration-method="register"
            unregistration-method="unregister"/>
     </service>
-    
+
 </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=776242&r1=776241&r2=776242&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 Tue
May 19 08:58:45 2009
@@ -89,4 +89,12 @@
         </argument>
     </bean>
 
+    <bean id="booleanPrim" class="org.apache.geronimo.blueprint.pojos.BeanF">
+        <argument><value type="boolean">no</value></argument>
+    </bean>
+
+    <bean id="booleanWrapped" class="org.apache.geronimo.blueprint.pojos.BeanF">
+        <argument type="java.lang.Boolean" value="no" />
+    </bean>
+
 </blueprint>



Mime
View raw message