Author: jboynes
Date: Sat Apr 15 16:41:04 2006
New Revision: 394402
URL: http://svn.apache.org/viewcvs?rev=394402&view=rev
Log:
refactor SystemCompositeContextImpl to remove duplicate configurations list
added testcase for duplicate registration as this was not being caught
previously
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java?rev=394402&r1=394401&r2=394402&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
Sat Apr 15 16:41:04 2006
@@ -95,6 +95,14 @@
builderRegistry.register(builder);
}
}
+
+/*
+ try {
+
systemContext.registerJavaObject(ContextFactoryBuilderRegistry.class.getName(),
ContextFactoryBuilderRegistry.class, builderRegistry);
+ } catch (ConfigurationException e) {
+ throw new AssertionError();
+ }
+*/
}
/**
@@ -122,11 +130,6 @@
return;
}
systemContext.start();
- try {
-
systemContext.registerJavaObject(ContextFactoryBuilderRegistry.class.getName(),
ContextFactoryBuilderRegistry.class, builderRegistry);
- } catch (ConfigurationException e) {
- throw new AssertionError();
- }
rootContext.start();
lifecycleState = RUNNING;
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java?rev=394402&r1=394401&r2=394402&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java
Sat Apr 15 16:41:04 2006
@@ -22,7 +22,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.tuscany.common.TuscanyRuntimeException;
import org.apache.tuscany.core.builder.BuilderConfigException;
import org.apache.tuscany.core.builder.ContextFactory;
import org.apache.tuscany.core.config.ConfigurationException;
@@ -79,9 +78,6 @@
* @version $Rev$ $Date$
*/
public class SystemCompositeContextImpl extends AbstractCompositeContext
implements SystemCompositeContext {
-
- protected List<ContextFactory<Context>> configurations = new
ArrayList<ContextFactory<Context>>();
-
// a mapping of service type to component name
private Map<Class, NameToScope> autowireIndex = new
ConcurrentHashMap<Class, NameToScope>();
@@ -127,7 +123,7 @@
Map<Scope, List<ContextFactory<Context>>>
configurationsByScope = new HashMap<Scope, List<ContextFactory<Context>>>();
if (configurations != null) {
- for (ContextFactory<Context> contextFactory :
configurations) {
+ for (ContextFactory<Context> contextFactory :
configurations.values()) {
// FIXME scopes are defined at the interface level
Scope scope = contextFactory.getScope();
// ensure duplicate names were not added before the
context was started
@@ -279,32 +275,6 @@
ScopeContext scope = scopeContexts.get(configuration.getScope());
NameToScope mapping = new NameToScope(new
QualifiedName(componentName), scope, false, false);
autowireIndex.put(service, mapping);
- }
-
- protected void registerConfiguration(ContextFactory<Context> factory)
throws ConfigurationException {
- factory.prepare(this);
- if (lifecycleState == RUNNING) {
- if (scopeIndex.get(factory.getName()) != null) {
- throw new DuplicateNameException(factory.getName());
- }
- try {
- ScopeContext scope = scopeContexts.get(factory.getScope());
- if (scope == null) {
- ConfigurationException e = new
MissingScopeException("Component has an unknown scope");
- e.addContextName(factory.getName());
- e.addContextName(getName());
- throw e;
- }
- scope.registerFactory(factory);
- scopeIndex.put(factory.getName(), scope);
- } catch (TuscanyRuntimeException e) {
- e.addContextName(getName());
- throw e;
- }
- } else {
- configurations.add(factory);
- }
-
}
public Composite getComposite() {
Modified:
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java?rev=394402&r1=394401&r2=394402&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
(original)
+++
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemObjectRegistrationTestCase.java
Sat Apr 15 16:41:04 2006
@@ -20,6 +20,7 @@
import junit.framework.TestCase;
import org.apache.tuscany.core.config.ConfigurationException;
import org.apache.tuscany.core.context.SystemCompositeContext;
+import org.apache.tuscany.core.context.DuplicateNameException;
import org.apache.tuscany.core.context.event.ModuleStart;
import org.apache.tuscany.core.runtime.RuntimeContext;
import org.apache.tuscany.core.runtime.RuntimeContextImpl;
@@ -35,6 +36,17 @@
MockComponent instance = new MockComponent();
systemContext.registerJavaObject("foo", MockComponent.class, instance);
assertSame(instance,
systemContext.getContext("foo").getInstance(null));
+ }
+
+ public void testDuplicateRegistration() throws ConfigurationException {
+ MockComponent instance = new MockComponent();
+ systemContext.registerJavaObject("foo", MockComponent.class, instance);
+ try {
+ systemContext.registerJavaObject("foo", MockComponent.class,
instance);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
}
protected void setUp() throws Exception {