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/18 15:32:12 UTC
svn commit: r775944 - in
/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache:
geronimo/blueprint/ geronimo/blueprint/context/ xbean/recipe/
Author: gnodet
Date: Mon May 18 13:32:11 2009
New Revision: 775944
URL: http://svn.apache.org/viewvc?rev=775944&view=rev
Log:
Remove unused fields typeName on recipes
Check listeners methods on creation
Allow override of default objects in the repository
Implement grace period timer logic
Additional fixes to method disambiguation for TCK
Modified:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintExtender.java
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/BlueprintObjectRecipe.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/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/UnaryServiceReferenceRecipe.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/MapRecipe.java
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintExtender.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintExtender.java?rev=775944&r1=775943&r2=775944&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintExtender.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/BlueprintExtender.java Mon May 18 13:32:11 2009
@@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -52,17 +53,22 @@
private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintExtender.class);
- private final ExecutorService executors = Executors.newSingleThreadExecutor();
- private final Map<Bundle, BlueprintContextImpl> contextMap = new HashMap<Bundle, BlueprintContextImpl>();
+ private ExecutorService executors;
+ private Timer timer;
+ private Map<Bundle, BlueprintContextImpl> contextMap;
private BlueprintContextEventSender sender;
private NamespaceHandlerRegistry handlers;
public void start(BundleContext context) {
LOGGER.debug("Starting blueprint extender...");
- context.addBundleListener(this);
sender = new DefaultBlueprintContextEventSender(context);
handlers = new NamespaceHandlerRegistryImpl(context);
+ executors = Executors.newSingleThreadExecutor();
+ timer = new Timer("BlueprintExtender-Timer", true);
+ contextMap = new HashMap<Bundle, BlueprintContextImpl>();
+
+ context.addBundleListener(this);
Bundle[] bundles = context.getBundles();
for (Bundle b : bundles) {
@@ -88,6 +94,7 @@
this.sender.destroy();
this.handlers.destroy();
executors.shutdown();
+ timer.cancel();
LOGGER.debug("Blueprint extender stopped");
}
@@ -149,7 +156,7 @@
// the bundle to be fully started
boolean compatible = lazyActivation || isCompatible(bundle);
if (compatible) {
- final BlueprintContextImpl blueprintContext = new BlueprintContextImpl(bundle.getBundleContext(), sender, handlers, executors, urls, lazyActivation);
+ final BlueprintContextImpl blueprintContext = new BlueprintContextImpl(bundle.getBundleContext(), sender, handlers, executors, timer, urls, lazyActivation);
contextMap.put(bundle, blueprintContext);
// run synchronous when bundle is lazy activated
blueprintContext.run(lazyActivation ? false: true);
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -48,6 +48,8 @@
import org.osgi.service.blueprint.reflect.ReferenceMetadata;
import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
import org.osgi.service.blueprint.reflect.Listener;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
/**
* Abstract class for service reference recipes.
@@ -107,6 +109,15 @@
return tracker.isSatisfied();
}
+ @Override
+ public List<Recipe> getNestedRecipes() {
+ List<Recipe> recipes = super.getNestedRecipes();
+ if (listenersRecipe != null) {
+ recipes.add(listenersRecipe);
+ }
+ return recipes;
+ }
+
protected String getOsgiFilter() {
if (filter == null) {
List<String> members = new ArrayList<String>();
@@ -253,6 +264,8 @@
public static class Listener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Listener.class);
+
/* Inject by ObjectRecipe */
private Object listener;
/* Inject by ObjectRecipe */
@@ -281,6 +294,9 @@
for (Class clazz : clazzes) {
bindMethodsTwoArgs.addAll(ReflectionUtils.findCompatibleMethods(listenerClass, bindName, new Class[] { clazz, Map.class }));
}
+ if (bindMethodsOneArg.size() + bindMethodsTwoArgs.size() == 0) {
+ throw new ConstructionException("No matching methods found for listener bind method: " + bindName);
+ }
}
String unbindName = metadata.getUnbindMethodName();
if (unbindName != null) {
@@ -288,6 +304,9 @@
for (Class clazz : clazzes) {
unbindMethodsTwoArgs.addAll(ReflectionUtils.findCompatibleMethods(listenerClass, unbindName, new Class[] { clazz, Map.class }));
}
+ if (unbindMethodsOneArg.size() + unbindMethodsTwoArgs.size() == 0) {
+ throw new ConstructionException("No matching methods found for listener bind method: " + bindName);
+ }
}
}
@@ -304,7 +323,7 @@
try {
method.invoke(listener, reference);
} catch (Exception e) {
- e.printStackTrace(); // TODO: log
+ LOGGER.info("Error calling listener method " + method, e);
}
}
Map<String, Object> props = null;
@@ -318,7 +337,7 @@
try {
method.invoke(listener, service, props);
} catch (Exception e) {
- e.printStackTrace(); // TODO: log
+ LOGGER.info("Error calling listener method " + method, e);
}
}
}
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -30,7 +30,10 @@
import java.util.Set;
import java.util.Properties;
import java.util.HashMap;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeoutException;
import org.apache.geronimo.blueprint.BlueprintConstants;
import org.apache.geronimo.blueprint.utils.HeaderParser;
@@ -103,6 +106,7 @@
private final ComponentDefinitionRegistryImpl componentDefinitionRegistry;
private final ConversionServiceImpl conversionService;
private final ExecutorService executors;
+ private final Timer timer;
private Set<URI> namespaces;
private State state = State.Unknown;
private Parser parser;
@@ -117,8 +121,9 @@
private Map<ServiceMetadata, TriggerService> triggerServices;
private long timeout = 5 * 60 * 1000;
private boolean waitForDependencies = true;
+ private TimerTask timerTask;
- public BlueprintContextImpl(BundleContext bundleContext, BlueprintContextEventSender sender, NamespaceHandlerRegistry handlers, ExecutorService executors, List<URL> urls, boolean lazyActivation) {
+ public BlueprintContextImpl(BundleContext bundleContext, BlueprintContextEventSender sender, NamespaceHandlerRegistry handlers, ExecutorService executors, Timer timer, List<URL> urls, boolean lazyActivation) {
this.bundleContext = bundleContext;
this.sender = sender;
this.handlers = handlers;
@@ -126,6 +131,7 @@
this.conversionService = new ConversionServiceImpl(this);
this.componentDefinitionRegistry = new ComponentDefinitionRegistryImpl();
this.executors = executors;
+ this.timer = timer;
this.lazyActivation = lazyActivation;
this.triggerServices = new HashMap<ServiceMetadata, TriggerService>();
this.beanProcessors = new ArrayList<BeanProcessor>();
@@ -210,12 +216,23 @@
instantiator = new BlueprintObjectInstantiator(new RecipeBuilder(this).createRepository());
checkReferences();
trackServiceReferences();
+ timerTask = new TimerTask() {
+ public void run() {
+ synchronized (BlueprintContextImpl.this) {
+ Throwable t = new TimeoutException();
+ state = State.Failed;
+ // TODO: clean up
+ LOGGER.error("Unable to start blueprint context for bundle " + bundleContext.getBundle().getSymbolicName(), t);
+ sender.sendFailure(getBundleContext().getBundle(), t);
+ }
+ }
+ };
+ timer.schedule(timerTask, timeout);
if (checkAllSatisfiables() || !waitForDependencies) {
state = State.InitialReferencesSatisfied;
} else {
// TODO: pass correct parameters
// TODO: do we need to send one event for each missing reference ?
- // TODO: create a timer, then fail after it elapsed
sender.sendWaiting(getBundleContext().getBundle(), null, null);
state = State.WaitForInitialReferences;
}
@@ -233,7 +250,6 @@
BlueprintObjectRepository repository = (BlueprintObjectRepository) instantiator.getRepository();
BlueprintObjectRepository tmpRepo = new RecipeBuilder(this).createRepository();
- BlueprintObjectInstantiator oldInstantiator = instantiator;
instantiator = new BlueprintObjectInstantiator(new RecipeBuilder(this).createRepository());
untrackServiceReferences();
@@ -283,6 +299,7 @@
case WaitForTrigger:
return;
case Create:
+ timerTask.cancel();
instantiateComponents();
// Register the BlueprintContext in the OSGi registry
@@ -669,7 +686,10 @@
public synchronized void destroy() {
state = State.Destroyed;
sender.sendDestroying(getBundleContext().getBundle());
-
+
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
if (registration != null) {
registration.unregister();
}
@@ -701,3 +721,75 @@
}
}
}
+
+
+/* TODO: fix the following deadlock
+
+ [bnd] "pool-3-thread-1" prio=5 tid=0x01018790 nid=0x8a2c00 in Object.wait() [0xb0f90000..0xb0f90d90]
+ [bnd] at java.lang.Object.wait(Native Method)
+ [bnd] - waiting on <0x25671928> (a java.lang.Object)
+ [bnd] at org.apache.geronimo.blueprint.context.UnaryServiceReferenceRecipe.getService(UnaryServiceReferenceRecipe.java:197)
+ [bnd] - locked <0x25671928> (a java.lang.Object)
+ [bnd] at org.apache.geronimo.blueprint.context.UnaryServiceReferenceRecipe.access$000(UnaryServiceReferenceRecipe.java:55)
+ [bnd] at org.apache.geronimo.blueprint.context.UnaryServiceReferenceRecipe$ServiceDispatcher.loadObject(UnaryServiceReferenceRecipe.java:225)
+ [bnd] at org.osgi.test.cases.blueprint.services.ServiceManager$$EnhancerByCGLIB$$f740783d.getActiveServices(<generated>)
+ [bnd] at org.osgi.test.cases.blueprint.components.serviceimport.NullReferenceList.init(NullReferenceList.java:43)
+ [bnd] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ [bnd] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ [bnd] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ [bnd] at java.lang.reflect.Method.invoke(Method.java:585)
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintObjectRecipe.internalCreate(BlueprintObjectRecipe.java:586)
+ [bnd] at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:95)
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintObjectInstantiator.createInstance(BlueprintObjectInstantiator.java:83)
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintObjectInstantiator.createAll(BlueprintObjectInstantiator.java:65)
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintContextImpl.instantiateComponents(BlueprintContextImpl.java:541)
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintContextImpl.run(BlueprintContextImpl.java:303)
+ [bnd] - locked <0x25730658> (a org.apache.geronimo.blueprint.context.BlueprintContextImpl)
+ [bnd] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
+ [bnd] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
+ [bnd] at java.util.concurrent.FutureTask.run(FutureTask.java:123)
+ [bnd] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
+ [bnd] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
+ [bnd] at java.lang.Thread.run(Thread.java:613)
+ [bnd]
+ [bnd] "main" prio=5 tid=0x01001460 nid=0xb0801000 waiting for monitor entry [0xb07ff000..0xb0800148]
+ [bnd] at org.apache.geronimo.blueprint.context.BlueprintContextImpl.destroy(BlueprintContextImpl.java:687)
+ [bnd] - waiting to lock <0x25730658> (a org.apache.geronimo.blueprint.context.BlueprintContextImpl)
+ [bnd] at org.apache.geronimo.blueprint.BlueprintExtender.destroyContext(BlueprintExtender.java:121)
+ [bnd] at org.apache.geronimo.blueprint.BlueprintExtender.bundleChanged(BlueprintExtender.java:113)
+ [bnd] at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:916)
+ [bnd] at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:220)
+ [bnd] at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
+ [bnd] at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1350)
+ [bnd] at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1301)
+ [bnd] at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:470)
+ [bnd] at org.eclipse.osgi.framework.internal.core.AbstractBundle.uninstallWorker(AbstractBundle.java:784)
+ [bnd] at org.eclipse.osgi.framework.internal.core.AbstractBundle.uninstall(AbstractBundle.java:764)
+ [bnd] at org.osgi.test.cases.blueprint.framework.BlueprintMetadata.cleanup(BlueprintMetadata.java:670)
+ [bnd] at org.osgi.test.cases.blueprint.framework.EventSet.stop(EventSet.java:97)
+ [bnd] at org.osgi.test.cases.blueprint.framework.TestPhase.stopEventSets(TestPhase.java:119)
+ [bnd] at org.osgi.test.cases.blueprint.framework.TestPhase.cleanup(TestPhase.java:98)
+ [bnd] at org.osgi.test.cases.blueprint.framework.BaseTestController.cleanup(BaseTestController.java:219)
+ [bnd] at org.osgi.test.cases.blueprint.framework.StandardTestController.cleanup(StandardTestController.java:177)
+ [bnd] at org.osgi.test.cases.blueprint.framework.BaseTestController.terminate(BaseTestController.java:340)
+ [bnd] at org.osgi.test.cases.blueprint.framework.BaseTestController.run(BaseTestController.java:363)
+ [bnd] at org.osgi.test.cases.blueprint.tests.TestReferenceCollection.testEmptyListCollectionServiceListener(TestReferenceCollection.java:527)
+ [bnd] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ [bnd] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ [bnd] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ [bnd] at java.lang.reflect.Method.invoke(Method.java:585)
+ [bnd] at junit.framework.TestCase.runTest(TestCase.java:164)
+ [bnd] at junit.framework.TestCase.runBare(TestCase.java:130)
+ [bnd] at junit.framework.TestResult$1.protect(TestResult.java:106)
+ [bnd] at junit.framework.TestResult.runProtected(TestResult.java:124)
+ [bnd] at junit.framework.TestResult.run(TestResult.java:109)
+ [bnd] at junit.framework.TestCase.run(TestCase.java:120)
+ [bnd] at junit.framework.TestSuite.runTest(TestSuite.java:230)
+ [bnd] at junit.framework.TestSuite.run(TestSuite.java:225)
+ [bnd] at junit.framework.TestSuite.runTest(TestSuite.java:230)
+ [bnd] at junit.framework.TestSuite.run(TestSuite.java:225)
+ [bnd] at aQute.junit.runtime.Target.doTesting(Target.java:157)
+ [bnd] at aQute.junit.runtime.Target.run(Target.java:40)
+ [bnd] at aQute.junit.runtime.Target.main(Target.java:33)
+
+*/
\ No newline at end of file
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -323,20 +323,28 @@
// Find a direct match with no conversion
if (TCK_COMPLIANCE && matches.size() != 1) {
Map<Method, List<Object>> nmatches = new HashMap<Method, List<Object>>();
+ int bestExactMatch = -1;
for (Method mth : methods) {
boolean found = true;
+ int exactMatch = 0;
List<Object> match = new ArrayList<Object>();
for (int i = 0; i < args.size(); i++) {
if (types.get(i) != null) {
- if (!toClass(mth.getParameterTypes()[i]).isAssignableFrom(types.get(i))) {
+ if (!mth.getParameterTypes()[i].isAssignableFrom(types.get(i))) {
found = false;
break;
}
+ if (mth.getParameterTypes()[i] == types.get(i)) {
+ exactMatch++;
+ }
} else {
if (!mth.getParameterTypes()[i].isInstance(args.get(i))) {
found = false;
break;
}
+ if (args.get(i) != null && mth.getParameterTypes()[i] == args.get(i).getClass()) {
+ exactMatch++;
+ }
}
try {
Object val = convert(args.get(i), mth.getGenericParameterTypes()[i]);
@@ -346,7 +354,11 @@
break;
}
}
- if (found) {
+ if (found && exactMatch >= bestExactMatch) {
+ if (exactMatch > bestExactMatch) {
+ bestExactMatch = exactMatch;
+ nmatches.clear();
+ }
nmatches.put(mth, match);
}
}
@@ -411,8 +423,10 @@
// Find a direct match with no conversion
if (TCK_COMPLIANCE && matches.size() != 1) {
Map<Constructor, List<Object>> nmatches = new HashMap<Constructor, List<Object>>();
+ int bestExactMatch = -1;
for (Constructor cns : constructors) {
boolean found = true;
+ int exactMatch = 0;
List<Object> match = new ArrayList<Object>();
for (int i = 0; i < args.size(); i++) {
if (types.get(i) != null) {
@@ -420,11 +434,17 @@
found = false;
break;
}
+ if (cns.getParameterTypes()[i] == types.get(i)) {
+ exactMatch++;
+ }
} else {
if (!cns.getParameterTypes()[i].isInstance(args.get(i))) {
found = false;
break;
}
+ if (args.get(i) != null && cns.getParameterTypes()[i] == args.get(i).getClass()) {
+ exactMatch++;
+ }
}
try {
Object val = convert(args.get(i), cns.getGenericParameterTypes()[i]);
@@ -434,7 +454,11 @@
break;
}
}
- if (found) {
+ if (found && exactMatch >= bestExactMatch) {
+ if (exactMatch > bestExactMatch) {
+ bestExactMatch = exactMatch;
+ nmatches.clear();
+ }
nmatches.put(cns, match);
}
}
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java?rev=775944&r1=775943&r2=775944&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java Mon May 18 13:32:11 2009
@@ -37,18 +37,21 @@
*/
public class BlueprintObjectRepository implements Repository {
+ private Map<String, Object> defaults;
private Map<String, Recipe> recipes;
private Map<String, Object> instances;
private List<DestroyCallback> destroyList;
public BlueprintObjectRepository() {
recipes = new TreeMap<String, Recipe>();
+ defaults = new TreeMap<String, Object>();
instances = new TreeMap<String, Object>();
destroyList = new ArrayList<DestroyCallback>();
}
public BlueprintObjectRepository(BlueprintObjectRepository source) {
recipes = new TreeMap<String, Recipe>(source.recipes);
+ defaults = new TreeMap<String, Object>();
instances = new TreeMap<String, Object>(source.instances);
destroyList = new ArrayList<DestroyCallback>();
}
@@ -62,11 +65,11 @@
}
public boolean contains(String name) {
- return recipes.containsKey(name) || instances.containsKey(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);
+ return instances.get(name) != null ? instances.get(name) : (recipes.get(name) != null ? recipes.get(name) : defaults.get(name));
}
public Object getInstance(String name) {
@@ -81,6 +84,7 @@
Set<String> names = new HashSet<String>();
names.addAll(recipes.keySet());
names.addAll(instances.keySet());
+ names.addAll(defaults.keySet());
return names;
}
@@ -102,6 +106,10 @@
}
}
+ public void putDefault(String name, Object instance) {
+ defaults.put(name, instance);
+ }
+
public void putRecipe(String name, Recipe recipe) {
recipes.put(name, recipe);
}
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -85,12 +85,12 @@
this.registry = blueprintContext.getComponentDefinitionRegistry();
}
- private void addBuiltinComponents(Repository repository) {
+ private void addBuiltinComponents(BlueprintObjectRepository repository) {
if (blueprintContext != null) {
- repository.add("blueprintContext", blueprintContext);
- repository.add("bundleContext", blueprintContext.getBundleContext());
- repository.add("bundle", blueprintContext.getBundleContext().getBundle());
- repository.add("conversionService", blueprintContext.getConversionService());
+ repository.putDefault("blueprintContext", blueprintContext);
+ repository.putDefault("bundleContext", blueprintContext.getBundleContext());
+ repository.putDefault("bundle", blueprintContext.getBundleContext().getBundle());
+ repository.putDefault("conversionService", blueprintContext.getConversionService());
}
}
@@ -293,7 +293,7 @@
Class cl = collectionMetadata.getCollectionClass();
Class type = loadClass(collectionMetadata.getValueTypeName());
if (cl == Object[].class) {
- ArrayRecipe ar = new ArrayRecipe();
+ ArrayRecipe ar = new ArrayRecipe(type);
for (Metadata lv : collectionMetadata.getValues()) {
ar.add(getValue(lv, type));
}
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -260,7 +260,7 @@
try {
method.invoke(listener, args);
} catch (Exception e) {
- LOGGER.info("Error calling listener", e);
+ LOGGER.info("Error calling listener method " + method, e);
}
}
}
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -127,6 +127,9 @@
}
private Object createProxy() throws Exception {
+ // TODO: we should use the bundle to load classes, not this weird proxyClassLoader
+ // TODO: find another way to handle ServiceReference injection instead of implementing the ServiceReferenceAccessor
+ // TODO: class which may not be available from the bundle classloader
Enhancer e = new Enhancer();
e.setClassLoader(proxyClassLoader);
e.setSuperclass(getTargetClass(metadata.getInterfaceNames()));
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -29,7 +29,6 @@
*/
public class ArrayRecipe extends AbstractRecipe {
private final List<Recipe> list;
- private String typeName;
private Class typeClass;
private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
@@ -37,21 +36,13 @@
list = new ArrayList<Recipe>();
}
- public ArrayRecipe(String type) {
- list = new ArrayList<Recipe>();
- this.typeName = type;
- }
-
public ArrayRecipe(Class type) {
- if (type == null) throw new NullPointerException("type is null");
-
this.list = new ArrayList<Recipe>();
this.typeClass = type;
}
public ArrayRecipe(ArrayRecipe collectionRecipe) {
if (collectionRecipe == null) throw new NullPointerException("setRecipe is null");
- this.typeName = collectionRecipe.typeName;
this.typeClass = collectionRecipe.typeClass;
list = new ArrayList<Recipe>(collectionRecipe.list);
}
@@ -85,13 +76,6 @@
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 };
}
@@ -138,16 +122,8 @@
expectedClass = expectedClass.getComponentType();
}
Class type = expectedClass;
- if (typeClass != null || typeName != null) {
+ if (typeClass != null ) {
type = typeClass;
- if (type == null) {
- try {
- type = RecipeHelper.loadClass(typeName);
- } catch (ClassNotFoundException e) {
- throw new ConstructionException("Type class could not be found: " + typeName);
- }
- }
-
// in case where expectedType is a subclass of the assigned type
if (type.isAssignableFrom(expectedClass)) {
type = expectedClass;
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=775944&r1=775943&r2=775944&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 Mon May 18 13:32:11 2009
@@ -37,7 +37,6 @@
*/
public class MapRecipe extends AbstractRecipe {
private final List<Recipe[]> entries;
- private String typeName;
private Class typeClass;
private final EnumSet<Option> options = EnumSet.noneOf(Option.class);
@@ -45,11 +44,6 @@
entries = new ArrayList<Recipe[]>();
}
- public MapRecipe(String type) {
- this.typeName = type;
- entries = new ArrayList<Recipe[]>();
- }
-
public MapRecipe(Class type) {
if (type == null) throw new NullPointerException("type is null");
this.typeClass = type;
@@ -76,7 +70,6 @@
public MapRecipe(MapRecipe mapRecipe) {
if (mapRecipe == null) throw new NullPointerException("mapRecipe is null");
- this.typeName = mapRecipe.typeName;
this.typeClass = mapRecipe.typeClass;
entries = new ArrayList<Recipe[]>(mapRecipe.entries);
}
@@ -190,16 +183,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)) {