You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/05/14 13:30:26 UTC
svn commit: r774734 - 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/
Author: gnodet
Date: Thu May 14 11:30:25 2009
New Revision: 774734
URL: http://svn.apache.org/viewvc?rev=774734&view=rev
Log:
Remove ObjectRecipe and move the needed things in BlueprintObjectRecipe
Use JavaBeans properties to more easily follow the spec
Use Recipe in map/array/collection recipes instead of plain values to avoid the call to RecipeHelper.convert() which does not call the ConversionService
Remove some unused code
Removed:
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/ParameterNameLoader.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ParameterNames.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/ReflectionUtil.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/BlueprintObjectRecipe.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/ServiceRegistrationProxy.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/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/Option.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/RecipeHelper.java
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -47,6 +47,7 @@
import org.osgi.service.blueprint.context.BlueprintContext;
import org.osgi.service.blueprint.reflect.ReferenceMetadata;
import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+import org.osgi.service.blueprint.reflect.Listener;
/**
* Abstract class for service reference recipes.
@@ -262,6 +263,14 @@
private Set<Method> unbindMethodsOneArg = new HashSet<Method>();
private Set<Method> unbindMethodsTwoArgs = new HashSet<Method>();
+ public void setListener(Object listener) {
+ this.listener = listener;
+ }
+
+ public void setMetadata(org.osgi.service.blueprint.reflect.Listener metadata) {
+ this.metadata = metadata;
+ }
+
public void init(Collection<Class> classes) {
Set<Class> clazzes = new HashSet<Class>(classes);
clazzes.add(Object.class);
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -18,26 +18,35 @@
*/
package org.apache.geronimo.blueprint.context;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+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.ReflectionUtils;
+import org.apache.xbean.recipe.AbstractRecipe;
import org.apache.xbean.recipe.ConstructionException;
import org.apache.xbean.recipe.ExecutionContext;
-import org.apache.xbean.recipe.ObjectRecipe;
+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.apache.xbean.recipe.Option;
-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.ReflectionUtils;
-import org.apache.geronimo.blueprint.BeanProcessor;
import org.osgi.service.blueprint.reflect.BeanArgument;
import org.osgi.service.blueprint.reflect.CollectionMetadata;
import org.osgi.service.blueprint.reflect.MapMetadata;
@@ -50,7 +59,12 @@
* @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
* @version $Rev$, $Date$
*/
-public class BlueprintObjectRecipe extends ObjectRecipe {
+public class BlueprintObjectRecipe extends AbstractRecipe {
+
+ private String typeName;
+ private Class typeClass;
+ private final LinkedHashMap<String,Object> properties = new LinkedHashMap<String,Object>();
+ private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
private final BlueprintContextImpl blueprintContext;
private boolean keepRecipe = false;
@@ -58,23 +72,56 @@
private String destroyMethod;
private List<String> explicitDependencies;
- private Object factory; // could be Recipe or actual object
+ private Recipe factory; // could be Recipe or actual object
private String factoryMethod;
private List<Object> arguments;
private List<BeanArgument> beanArguments;
private boolean reorderArguments;
public BlueprintObjectRecipe(BlueprintContextImpl blueprintContext, Class typeName) {
- super(typeName);
+ this.typeClass = typeName;
this.blueprintContext = blueprintContext;
allow(Option.LAZY_ASSIGNMENT);
}
+ public void allow(Option option){
+ options.add(option);
+ }
+
+ public void disallow(Option option){
+ options.remove(option);
+ }
+
+ public Set<Option> getOptions() {
+ return Collections.unmodifiableSet(options);
+ }
+
+ public Object getProperty(String name) {
+ return properties.get(name);
+ }
+
+ public Map<String, Object> getProperties() {
+ return new LinkedHashMap<String, Object>(properties);
+ }
+
+ public void setProperty(String name, Object value) {
+ properties.put(name, value);
+ }
+
+ public void setAllProperties(Map<?,?> map) {
+ if (map == null) throw new NullPointerException("map is null");
+ for (Map.Entry<?, ?> entry : map.entrySet()) {
+ String name = (String) entry.getKey();
+ Object value = entry.getValue();
+ setProperty(name, value);
+ }
+ }
+
public void setFactoryMethod(String method) {
this.factoryMethod = method;
}
- public void setFactoryComponent(Object factory) {
+ public void setFactoryComponent(Recipe factory) {
this.factory = factory;
}
@@ -163,7 +210,7 @@
obj = new TypedRecipe();
} else if (obj instanceof Recipe) {
if (shouldPreinstantiate(argument.getValue())) {
- obj = RecipeHelper.convert(Object.class, obj, refAllowed);
+ obj = ((Recipe) obj).create(Object.class, refAllowed);
}
}
}
@@ -181,7 +228,7 @@
for (int i = 0; i < arguments.size(); i++) {
Object argument = arguments.get(i);
if (argument instanceof Recipe) {
- argument = RecipeHelper.convert(parameterTypes[i], argument, refAllowed);
+ argument = ((Recipe) argument).create(parameterTypes[i], refAllowed);
}
args.add(argument);
}
@@ -230,7 +277,7 @@
if (factory != null) {
// look for instance method on factory object
- Object factoryObj = RecipeHelper.convert(Object.class, factory, refAllowed);
+ 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
@@ -314,10 +361,10 @@
return method;
}
- @Override
public boolean canCreate(Type type) {
if (factoryMethod == null) {
- return super.canCreate(type);
+ 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
@@ -388,4 +435,120 @@
processor.afterDestroy(obj, getName());
}
}
+
+ public Type[] getTypes() {
+ Class type = getType();
+ if (type != null) {
+ return new Type[] { getType() };
+ } else{
+ return new Type[] { Object.class };
+ }
+ }
+
+ public void setProperties(Object instance) throws ConstructionException {
+ // clone the properties so they can be used again
+ Map<String,Object> propertyValues = new LinkedHashMap<String,Object>(properties);
+ setProperties(propertyValues, instance, instance.getClass());
+ }
+
+ public Class getType() {
+ if (typeClass != null || typeName != 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);
+ }
+ }
+
+ return type;
+ }
+
+ return null;
+ }
+
+ private void setProperties(Map<String, Object> propertyValues, Object instance, Class clazz) {
+ // set remaining properties
+ for (Map.Entry<String, Object> entry : propertyValues.entrySet()) {
+ String propertyName = entry.getKey();
+ Object propertyValue = entry.getValue();
+
+ setProperty(instance, clazz, propertyName, propertyValue);
+ }
+
+ }
+
+ private void setProperty(Object instance, Class clazz, String propertyName, Object propertyValue) {
+ String[] names = propertyName.split("\\.");
+ for (int i = 0; i < names.length - 1; i++) {
+ Method getter = getPropertyDescriptor(clazz, names[i]).getReadMethod();
+ if (getter != null) {
+ try {
+ instance = getter.invoke(instance);
+ clazz = instance.getClass();
+ } catch (Exception e) {
+ Throwable t = e;
+ if (e instanceof InvocationTargetException) {
+ InvocationTargetException invocationTargetException = (InvocationTargetException) e;
+ if (invocationTargetException.getCause() != null) {
+ t = invocationTargetException.getCause();
+ }
+ }
+ throw new ConstructionException("Error getting property: " + names[i] + " on bean " + getName() + " when setting property " + propertyName + " on class " + clazz.getName(), t);
+ }
+ } else {
+ throw new ConstructionException("No getter for " + names[i] + " property");
+ }
+ }
+ Method setter = getPropertyDescriptor(clazz, names[names.length - 1]).getWriteMethod();
+ if (setter != null) {
+ // convert the value to type of setter/field
+ Type type = setter.getGenericParameterTypes()[0];
+ // Instanciate value
+ if (propertyValue instanceof Recipe) {
+ propertyValue = ((Recipe) propertyValue).create(type, false);
+ }
+ try {
+ propertyValue = blueprintContext.getConversionService().convert(propertyValue, toClass(type));
+ } catch (Exception e) {
+ String valueType = propertyValue == null ? "null" : propertyValue.getClass().getName();
+ String memberType = type instanceof Class ? ((Class) type).getName() : type.toString();
+ throw new ConstructionException("Unable to convert property value" +
+ " from " + valueType +
+ " to " + memberType +
+ " for injection " + setter, e);
+ }
+ try {
+ // set value
+ setter.invoke(instance, propertyValue);
+ } catch (Exception e) {
+ Throwable t = e;
+ if (e instanceof InvocationTargetException) {
+ InvocationTargetException invocationTargetException = (InvocationTargetException) e;
+ if (invocationTargetException.getCause() != null) {
+ t = invocationTargetException.getCause();
+ }
+ }
+ throw new ConstructionException("Error setting property: " + setter, t);
+ }
+ } else {
+ throw new ConstructionException("No setter for " + names[names.length - 1] + " property");
+ }
+ }
+
+ PropertyDescriptor getPropertyDescriptor(Class clazz, String name) {
+ try {
+ BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+ for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+ if (pd.getName().equals(name)) {
+ return pd;
+ }
+ }
+ throw new ConstructionException("Unable to find property descriptor " + name + " on class " + clazz.getName());
+ } catch (IntrospectionException e) {
+ throw new ConstructionException("Unable to find property descriptor " + name + " on class " + clazz.getName(), e);
+ }
+ }
+
}
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -140,9 +140,11 @@
public void stop() {
super.stop();
- List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(collection.getDispatchers());
- for (ServiceDispatcher dispatcher : dispatchers) {
- untrack(dispatcher.reference);
+ if (collection != null) {
+ List<ServiceDispatcher> dispatchers = new ArrayList<ServiceDispatcher>(collection.getDispatchers());
+ for (ServiceDispatcher dispatcher : dispatchers) {
+ untrack(dispatcher.reference);
+ }
}
}
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -32,8 +32,6 @@
import org.apache.xbean.recipe.ArrayRecipe;
import org.apache.xbean.recipe.CollectionRecipe;
import org.apache.xbean.recipe.MapRecipe;
-import org.apache.xbean.recipe.ObjectRecipe;
-import org.apache.xbean.recipe.Option;
import org.apache.xbean.recipe.Recipe;
import org.apache.xbean.recipe.ReferenceNameRecipe;
import org.apache.xbean.recipe.Repository;
@@ -162,9 +160,8 @@
return recipe;
}
- private ObjectRecipe createServiceRecipe(ServiceMetadata serviceExport) throws Exception {
+ private BlueprintObjectRecipe createServiceRecipe(ServiceMetadata serviceExport) throws Exception {
BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, ServiceRegistrationProxy.class);
- recipe.allow(Option.PRIVATE_PROPERTIES);
recipe.setName(getName(serviceExport.getId()));
recipe.setExplicitDependencies(serviceExport.getExplicitDependencies());
recipe.setInitMethod("init");
@@ -211,7 +208,7 @@
recipe.setExplicitDependencies(local.getExplicitDependencies());
for (BeanProperty property : local.getProperties()) {
Object value = getValue(property.getValue(), null);
- recipe.setCompoundProperty(property.getName(), value);
+ recipe.setProperty(property.getName(), value);
}
if (BeanMetadata.SCOPE_PROTOTYPE.equals(local.getScope())) {
recipe.setKeepRecipe(true);
@@ -243,16 +240,14 @@
}
private Recipe createRecipe(RegistrationListener listener) throws Exception {
- ObjectRecipe recipe = new ObjectRecipe(ServiceRegistrationProxy.Listener.class);
- recipe.allow(Option.PRIVATE_PROPERTIES);
+ BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, ServiceRegistrationProxy.Listener.class);
recipe.setProperty("listener", getValue(listener.getListenerComponent(), null));
recipe.setProperty("metadata", listener);
return recipe;
}
private Recipe createRecipe(Listener listener) throws Exception {
- ObjectRecipe recipe = new ObjectRecipe(AbstractServiceReferenceRecipe.Listener.class);
- recipe.allow(Option.PRIVATE_PROPERTIES);
+ BlueprintObjectRecipe recipe = new BlueprintObjectRecipe(blueprintContext, AbstractServiceReferenceRecipe.Listener.class);
recipe.setProperty("listener", getValue(listener.getListenerComponent(), null));
recipe.setProperty("metadata", listener);
return recipe;
@@ -310,8 +305,8 @@
Class valueType = loadClass(mapValue.getValueTypeName());
MapRecipe mr = new MapRecipe(HashMap.class);
for (MapEntry entry : mapValue.getEntries()) {
- Object key = getValue(entry.getKey(), keyType);
- Object val = getValue(entry.getValue(), valueType);
+ Recipe key = getValue(entry.getKey(), keyType);
+ Recipe val = getValue(entry.getValue(), valueType);
mr.put(key, val);
}
return mr;
@@ -319,8 +314,8 @@
PropsMetadata mapValue = (PropsMetadata) v;
MapRecipe mr = new MapRecipe(Properties.class);
for (MapEntry entry : mapValue.getEntries()) {
- Object key = getValue(entry.getKey(), String.class);
- Object val = getValue(entry.getValue(), String.class);
+ Recipe key = getValue(entry.getKey(), String.class);
+ Recipe val = getValue(entry.getValue(), String.class);
mr.put(key, val);
}
return mr;
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java?rev=774734&r1=774733&r2=774734&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/ServiceRegistrationProxy.java Thu May 14 11:30:25 2009
@@ -53,6 +53,26 @@
private ServiceRegistration registration = null;
private Map registrationProperties = null;
+ public void setBlueprintContext(BlueprintContextImpl blueprintContext) {
+ this.blueprintContext = blueprintContext;
+ }
+
+ public void setService(Object service) {
+ this.service = service;
+ }
+
+ public void setServiceProperties(Map serviceProperties) {
+ this.serviceProperties = serviceProperties;
+ }
+
+ public void setMetadata(ServiceMetadata metadata) {
+ this.metadata = metadata;
+ }
+
+ public void setListeners(List<Listener> listeners) {
+ this.listeners = listeners;
+ }
+
protected Object getService() {
return service;
}
@@ -192,7 +212,15 @@
private List<Method> registerMethods;
private List<Method> unregisterMethods;
private boolean initialized = false;
-
+
+ public void setListener(Object listener) {
+ this.listener = listener;
+ }
+
+ public void setMetadata(RegistrationListener metadata) {
+ this.metadata = metadata;
+ }
+
private synchronized void init(ServiceRegistrationProxy registration) {
if (initialized) {
return;
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -58,7 +58,7 @@
if (value == null) {
return null;
} else if (value instanceof Recipe) {
- obj = RecipeHelper.convert(Object.class, value, lazyRefAllowed);
+ obj = ((Recipe) value).create(Object.class, lazyRefAllowed);
}
try {
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -23,13 +23,12 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.HashSet;
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
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -28,24 +28,24 @@
* @version $Rev$ $Date$
*/
public class ArrayRecipe extends AbstractRecipe {
- private final List<Object> list;
+ private final List<Recipe> list;
private String typeName;
private Class typeClass;
private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
public ArrayRecipe() {
- list = new ArrayList<Object>();
+ list = new ArrayList<Recipe>();
}
public ArrayRecipe(String type) {
- list = new ArrayList<Object>();
+ list = new ArrayList<Recipe>();
this.typeName = type;
}
public ArrayRecipe(Class type) {
if (type == null) throw new NullPointerException("type is null");
- this.list = new ArrayList<Object>();
+ this.list = new ArrayList<Recipe>();
this.typeClass = type;
}
@@ -53,7 +53,7 @@
if (collectionRecipe == null) throw new NullPointerException("setRecipe is null");
this.typeName = collectionRecipe.typeName;
this.typeClass = collectionRecipe.typeClass;
- list = new ArrayList<Object>(collectionRecipe.list);
+ list = new ArrayList<Recipe>(collectionRecipe.list);
}
public void allow(Option option) {
@@ -122,8 +122,8 @@
boolean refAllowed = options.contains(Option.LAZY_ASSIGNMENT);
int index = 0;
- for (Object value : list) {
- value = RecipeHelper.convert(type, value, refAllowed);
+ for (Recipe recipe : list) {
+ Object value = recipe.create(type, refAllowed);
if (value instanceof Reference) {
Reference reference = (Reference) value;
@@ -163,11 +163,11 @@
return type;
}
- public void add(Object value) {
+ public void add(Recipe value) {
list.add(value);
}
- public void addAll(Collection<?> value) {
+ public void addAll(Collection<Recipe> value) {
list.addAll(value);
}
@@ -179,7 +179,7 @@
list.remove(value);
}
- public List<Object> getAll() {
+ public List<Recipe> getAll() {
return Collections.unmodifiableList(list);
}
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -33,30 +33,30 @@
* @version $Rev: 6685 $ $Date: 2005-12-28T00:29:37.967210Z $
*/
public class CollectionRecipe extends AbstractRecipe {
- private final List<Object> list;
+ 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<Object>();
+ list = new ArrayList<Recipe>();
}
public CollectionRecipe(String type) {
- list = new ArrayList<Object>();
+ list = new ArrayList<Recipe>();
this.typeName = type;
}
public CollectionRecipe(Class type) {
if (type == null) throw new NullPointerException("type is null");
- this.list = new ArrayList<Object>();
+ this.list = new ArrayList<Recipe>();
this.typeClass = type;
}
- public CollectionRecipe(Collection<?> collection) {
+ public CollectionRecipe(Collection<Recipe> collection) {
if (collection == null) throw new NullPointerException("collection is null");
- this.list = new ArrayList<Object>(collection);
+ 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())) {
@@ -76,7 +76,7 @@
if (collectionRecipe == null) throw new NullPointerException("setRecipe is null");
this.typeName = collectionRecipe.typeName;
this.typeClass = collectionRecipe.typeClass;
- list = new ArrayList<Object>(collectionRecipe.list);
+ list = new ArrayList<Recipe>(collectionRecipe.list);
}
public void allow(Option option) {
@@ -159,8 +159,8 @@
boolean refAllowed = options.contains(Option.LAZY_ASSIGNMENT);
int index = 0;
- for (Object value : list) {
- value = RecipeHelper.convert(componentType, value, refAllowed);
+ for (Recipe recipe : list) {
+ Object value = recipe.create(componentType, refAllowed);
if (value instanceof Reference) {
Reference reference = (Reference) value;
@@ -220,23 +220,23 @@
}
}
- public void add(Object value) {
+ public void add(Recipe value) {
list.add(value);
}
- public void addAll(Collection<?> value) {
+ public void addAll(Collection<Recipe> value) {
list.addAll(value);
}
- public void remove(Object value) {
+ public void remove(Recipe value) {
list.remove(value);
}
- public void removeAll(Object value) {
+ public void removeAll(Recipe value) {
list.remove(value);
}
- public List<Object> getAll() {
+ public List<Recipe> getAll() {
return Collections.unmodifiableList(list);
}
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -36,30 +36,30 @@
* @version $Rev: 6687 $ $Date: 2005-12-28T21:08:56.733437Z $
*/
public class MapRecipe extends AbstractRecipe {
- private final List<Object[]> entries;
+ private final List<Recipe[]> entries;
private String typeName;
private Class typeClass;
private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
public MapRecipe() {
- entries = new ArrayList<Object[]>();
+ entries = new ArrayList<Recipe[]>();
}
public MapRecipe(String type) {
this.typeName = type;
- entries = new ArrayList<Object[]>();
+ entries = new ArrayList<Recipe[]>();
}
public MapRecipe(Class type) {
if (type == null) throw new NullPointerException("type is null");
this.typeClass = type;
- entries = new ArrayList<Object[]>();
+ entries = new ArrayList<Recipe[]>();
}
- public MapRecipe(Map<?,?> map) {
+ public MapRecipe(Map<Recipe,Recipe> map) {
if (map == null) throw new NullPointerException("map is null");
- entries = new ArrayList<Object[]>(map.size());
+ 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())) {
@@ -78,7 +78,7 @@
if (mapRecipe == null) throw new NullPointerException("mapRecipe is null");
this.typeName = mapRecipe.typeName;
this.typeClass = mapRecipe.typeClass;
- entries = new ArrayList<Object[]>(mapRecipe.entries);
+ entries = new ArrayList<Recipe[]>(mapRecipe.entries);
}
public void allow(Option option){
@@ -166,9 +166,9 @@
// add map entries
boolean refAllowed = options.contains(Option.LAZY_ASSIGNMENT);
- for (Object[] entry : entries) {
- Object key = RecipeHelper.convert(keyType, entry[0], refAllowed);
- Object value = RecipeHelper.convert(valueType, entry[1], refAllowed);
+ for (Recipe[] entry : entries) {
+ Object key = entry[0].create(keyType, refAllowed);
+ Object value = entry[1].create(valueType, refAllowed);
if (key instanceof Reference) {
// when the key reference and optional value reference are both resolved
@@ -230,16 +230,16 @@
}
}
- public void put(Object key, Object value) {
+ public void put(Recipe key, Recipe value) {
if (key == null) throw new NullPointerException("key is null");
- entries.add(new Object[] { key, value});
+ entries.add(new Recipe[] { key, value});
}
- public void putAll(Map<?,?> map) {
+ public void putAll(Map<Recipe,Recipe> map) {
if (map == null) throw new NullPointerException("map is null");
- for (Map.Entry<?,?> entry : map.entrySet()) {
- Object key = entry.getKey();
- Object value = entry.getValue();
+ for (Map.Entry<Recipe,Recipe> entry : map.entrySet()) {
+ Recipe key = entry.getKey();
+ Recipe value = entry.getValue();
put(key, value);
}
}
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Option.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Option.java?rev=774734&r1=774733&r2=774734&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Option.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/xbean/recipe/Option.java Thu May 14 11:30:25 2009
@@ -20,14 +20,5 @@
* @version $Rev$ $Date$
*/
public enum Option {
- PRIVATE_PROPERTIES,
- STATIC_PROPERTIES,
- FIELD_INJECTION,
- IGNORE_MISSING_PROPERTIES,
- CASE_INSENSITIVE_PROPERTIES,
LAZY_ASSIGNMENT,
- PRIVATE_CONSTRUCTOR,
- PRIVATE_FACTORY,
- CASE_INSENSITIVE_FACTORY,
- NAMED_PARAMETERS
}
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -39,14 +39,6 @@
private RecipeHelper() {
}
- public static Recipe getCaller() {
- LinkedList<Recipe> stack = ExecutionContext.getContext().getStack();
- if (stack.size() < 2) {
- return null;
- }
- return stack.get(stack.size() - 2);
- }
-
public static Class loadClass(String name) throws ClassNotFoundException {
ClassLoader classLoader = ExecutionContext.getContext().getClassLoader();
Class<?> type = Class.forName(name, true, classLoader);
@@ -156,33 +148,6 @@
return expected.isAssignableFrom(actual);
}
- public static Object convert(Type expectedType, Object value, boolean lazyRefAllowed) {
- if (value instanceof Recipe) {
- Recipe recipe = (Recipe) value;
- value = recipe.create(expectedType, lazyRefAllowed);
- }
-
- //if (value instanceof String && (expectedType != Object.class)) {
- // String stringValue = (String) value;
- // value = PropertyEditors.getValue(expectedType, stringValue);
- //}
- return value;
- }
-
- public static boolean isAssignableFrom(List<? extends Class<?>> expectedTypes, List<? extends Class<?>> actualTypes) {
- if (expectedTypes.size() != actualTypes.size()) {
- return false;
- }
- for (int i = 0; i < expectedTypes.size(); i++) {
- Class expectedType = expectedTypes.get(i);
- Class actualType = actualTypes.get(i);
- if (expectedType != actualType && !isAssignableFrom(expectedType, actualType)) {
- return false;
- }
- }
- return true;
- }
-
public static boolean isAssignable(Type expectedType, Type actualType) {
Class expectedClass = toClass(expectedType);
Class actualClass = toClass(actualType);
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=774734&r1=774733&r2=774734&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 Thu May 14 11:30:25 2009
@@ -42,16 +42,18 @@
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 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);
+ try {
+ graph.create("ambiguous");
+ fail("Should have failed");
+ } catch (Exception e) {
+ // Expected
+ }
+ }
public void testWiring() throws Exception {
ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");