Author: jmarino
Date: Sat Jan 6 15:56:16 2007
New Revision: 493605
URL: http://svn.apache.org/viewvc?view=rev&rev=493605
Log:
refactoring of CompositeComponent interface to remove unnecessary
specializations
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
Sat Jan 6 15:56:16 2007
@@ -446,62 +446,24 @@
throws WiringException {
assert sourceWire.getTargetName() != null;
QualifiedName targetName = sourceWire.getTargetName();
- InboundWire targetWire = null;
+ InboundWire targetWire;
// target is a composite service, connect to it
- Service service;
if (source.isSystem()) {
- service = target.getSystemService(targetName.getPortName());
- if (service != null) {
- for (ServiceBinding binding : service.getServiceBindings()) {
- InboundWire candidate = binding.getInboundWire();
- if
(sourceWire.getBindingType().equals(candidate.getBindingType())) {
- targetWire = candidate;
- break;
- }
- }
- if (targetWire == null) {
- throw new NoCompatibleBindingsException(source.getName(),
- targetName.getPartName(),
- targetName.getPortName());
- }
- Class<?> sourceInterface =
sourceWire.getServiceContract().getInterfaceClass();
- Class<?> targetInterface =
targetWire.getServiceContract().getInterfaceClass();
- if (!sourceInterface.isAssignableFrom(targetInterface)) {
- targetWire = null;
- }
- }
+ targetWire = target.getInboundSystemWire(targetName.getPortName());
} else {
- service = target.getService(targetName.getPortName());
- if (service != null) {
- for (ServiceBinding binding : service.getServiceBindings()) {
- InboundWire candidate = binding.getInboundWire();
- if
(sourceWire.getBindingType().equals(candidate.getBindingType())) {
- targetWire = candidate;
- break;
- }
- }
- if (targetWire == null) {
- throw new NoCompatibleBindingsException(source.getName(),
- targetName.getPartName(),
- targetName.getPortName());
- }
- Class<?> sourceInterface =
sourceWire.getServiceContract().getInterfaceClass();
- Class<?> targetInterface =
targetWire.getServiceContract().getInterfaceClass();
- if (!sourceInterface.isAssignableFrom(targetInterface)) {
- targetWire = null;
- }
- }
+ targetWire = target.getInboundWire(targetName.getPortName());
}
if (targetWire == null) {
String sourceName = sourceWire.getContainer().getName();
String sourceReference = sourceWire.getReferenceName();
- throw new TargetServiceNotFoundException("Target service not
found",
+ throw new TargetServiceNotFoundException("Target service does not
exist or is not configured with a "
+ + "local binding",
sourceName,
sourceReference,
targetName.getPartName(),
targetName.getPortName());
}
- boolean optimizable = isOptimizable(source.getScope(),
service.getScope());
+ boolean optimizable = isOptimizable(source.getScope(), Scope.SYSTEM);
connect(sourceWire, targetWire, optimizable);
}
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
Sat Jan 6 15:56:16 2007
@@ -63,9 +63,11 @@
InboundWire wire;
if (child instanceof CompositeComponent) {
CompositeComponent childComposite = (CompositeComponent) child;
- child = childComposite.getService(qName.getPortName());
+ child = childComposite.getChild(qName.getPortName());
if (child == null) {
throw new ServiceRuntimeException("Service not found [" +
serviceName + "]");
+ } else if (!(child instanceof Service)) {
+ throw new ServiceRuntimeException("Child not a service [" +
serviceName + "]");
}
wire = getInboundWire(child, name, "");
} else {
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java
Sat Jan 6 15:56:16 2007
@@ -58,6 +58,8 @@
protected ConnectorImpl connector;
protected ServiceContract contract;
protected Operation<Type> operation;
+ protected InboundWire localServiceInboundWire;
+ protected InboundWireImpl serviceInboundWire;
protected void setUp() throws Exception {
super.setUp();
@@ -67,10 +69,6 @@
operation = new Operation<Type>("bar", null, null, null);
}
- protected interface Foo {
- String echo();
- }
-
protected AtomicComponent createAtomicTarget() throws Exception {
InboundInvocationChain chain = new
InboundInvocationChainImpl(operation);
chain.addInterceptor(new InvokerInterceptor());
@@ -128,11 +126,11 @@
ServiceBinding serviceBinding = new MockServiceBinding();
InboundInvocationChain targetInboundChain = new
InboundInvocationChainImpl(operation);
targetInboundChain.addInterceptor(new
SynchronousBridgingInterceptor());
- InboundWireImpl targetInboundWire = new InboundWireImpl();
- targetInboundWire.setBindingType(qName);
- targetInboundWire.setServiceContract(contract);
- targetInboundWire.addInvocationChain(operation, targetInboundChain);
- targetInboundWire.setContainer(serviceBinding);
+ serviceInboundWire = new InboundWireImpl();
+ serviceInboundWire.setBindingType(qName);
+ serviceInboundWire.setServiceContract(contract);
+ serviceInboundWire.addInvocationChain(operation, targetInboundChain);
+ serviceInboundWire.setContainer(serviceBinding);
OutboundInvocationChain targetOutboundChain = new
OutboundInvocationChainImpl(operation);
// place an invoker interceptor on the end
@@ -143,7 +141,7 @@
targetOutboundWire.setContainer(serviceBinding);
targetOutboundWire.setBindingType(qName);
- serviceBinding.setInboundWire(targetInboundWire);
+ serviceBinding.setInboundWire(serviceInboundWire);
serviceBinding.setOutboundWire(targetOutboundWire);
// manually connect the service chains
connector.connect(targetInboundChain, targetOutboundChain);
@@ -163,10 +161,10 @@
LocalServiceBinding serviceBinding = new LocalServiceBinding(TARGET,
parent);
InboundInvocationChain targetInboundChain = new
InboundInvocationChainImpl(operation);
targetInboundChain.addInterceptor(new
SynchronousBridgingInterceptor());
- InboundWire targetInboundWire = new InboundWireImpl();
- targetInboundWire.setServiceContract(contract);
- targetInboundWire.addInvocationChain(operation, targetInboundChain);
- targetInboundWire.setContainer(serviceBinding);
+ localServiceInboundWire = new InboundWireImpl();
+ localServiceInboundWire.setServiceContract(contract);
+ localServiceInboundWire.addInvocationChain(operation,
targetInboundChain);
+ localServiceInboundWire.setContainer(serviceBinding);
OutboundInvocationChain targetOutboundChain = new
OutboundInvocationChainImpl(operation);
// place an invoker interceptor on the end
@@ -176,7 +174,7 @@
targetOutboundWire.addInvocationChain(operation, targetOutboundChain);
targetOutboundWire.setContainer(serviceBinding);
- serviceBinding.setInboundWire(targetInboundWire);
+ serviceBinding.setInboundWire(localServiceInboundWire);
serviceBinding.setOutboundWire(targetOutboundWire);
// manually connect the service chains
connector.connect(targetInboundChain, targetOutboundChain);
@@ -189,10 +187,10 @@
throws TargetInvokerCreationException {
ReferenceBinding referenceBinding = new LocalReferenceBinding("local",
null);
InboundInvocationChain inboundChain = new
InboundInvocationChainImpl(operation);
- InboundWire inboundWire = new InboundWireImpl();
- inboundWire.setServiceContract(contract);
- inboundWire.setContainer(referenceBinding);
- inboundWire.addInvocationChain(operation, inboundChain);
+ InboundWire referenceInboundWire = new InboundWireImpl();
+ referenceInboundWire.setServiceContract(contract);
+ referenceInboundWire.setContainer(referenceBinding);
+ referenceInboundWire.addInvocationChain(operation, inboundChain);
OutboundInvocationChain outboundChain = new
OutboundInvocationChainImpl(operation);
// Outbound chains always contains at least one interceptor
@@ -203,12 +201,31 @@
outboundWire.addInvocationChain(operation, outboundChain);
outboundWire.setContainer(referenceBinding);
- referenceBinding.setInboundWire(inboundWire);
+ referenceBinding.setInboundWire(referenceInboundWire);
referenceBinding.setOutboundWire(outboundWire);
return referenceBinding;
}
+ protected InboundWire createLocalInboundWire(CompositeComponent parent)
throws WireConnectException {
+ InboundInvocationChain chain = new
InboundInvocationChainImpl(operation);
+ chain.addInterceptor(new SynchronousBridgingInterceptor());
+ InboundWire wire = new InboundWireImpl();
+ wire.setServiceContract(contract);
+ wire.setContainer(new LocalReferenceBinding("", parent));
+ wire.addInvocationChain(operation, chain);
+
+ OutboundInvocationChain targetOutboundChain = new
OutboundInvocationChainImpl(operation);
+ // place an invoker interceptor on the end
+ targetOutboundChain.addInterceptor(new InvokerInterceptor());
+ OutboundWire targetOutboundWire = new OutboundWireImpl();
+ targetOutboundWire.setServiceContract(contract);
+ targetOutboundWire.addInvocationChain(operation, targetOutboundChain);
+
+ // manually connect the service chains
+ connector.connect(chain, targetOutboundChain);
+ return wire;
+ }
protected static class MockInvoker implements TargetInvoker {
public Object invokeTarget(final Object payload, final short sequence)
throws InvocationTargetException {
@@ -262,6 +279,10 @@
public boolean isOptimizable() {
return false;
}
+ }
+
+ protected interface Foo {
+ String echo();
}
}
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java
Sat Jan 6 15:56:16 2007
@@ -2,6 +2,7 @@
import java.util.Collections;
+import org.apache.tuscany.spi.QualifiedName;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.component.Reference;
@@ -11,11 +12,10 @@
import org.apache.tuscany.spi.wire.Interceptor;
import org.apache.tuscany.spi.wire.Message;
import org.apache.tuscany.spi.wire.MessageImpl;
-import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
-import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
/**
* Verifies various wiring "scenarios" or paths through the connector
@@ -91,7 +91,7 @@
try {
connector.connect(reference);
fail();
- } catch (NoCompatibleBindingsException e) {
+ } catch (TargetServiceNotFoundException e) {
// expected
}
}
@@ -111,7 +111,15 @@
}
private void createLocalReferenceToServiceConfiguration() throws Exception
{
- CompositeComponent topComposite =
EasyMock.createMock(CompositeComponent.class);
+ final CompositeComponent topComposite =
EasyMock.createMock(CompositeComponent.class);
+
+ topComposite.getInboundWire(TARGET);
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ return createLocalInboundWire(topComposite);
+ }
+ });
+ service = createLocalService(topComposite);
topComposite.getChild(TARGET);
EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
@@ -124,7 +132,7 @@
EasyMock.expect(parent.getParent()).andReturn(topComposite);
EasyMock.replay(parent);
- service = createLocalService(topComposite);
+ //service = createLocalService(topComposite);
reference = createLocalReference(parent, TARGET_NAME);
}
@@ -148,10 +156,11 @@
private void createLocalReferenceToSiblingCompositeServiceConfiguration()
throws Exception {
final CompositeComponent sibling =
EasyMock.createMock(CompositeComponent.class);
- sibling.getService(TARGET_SERVICE);
+ //final InboundWire wire = createLocalInboundWire(sibling);
+ sibling.getInboundWire(TARGET_SERVICE);
EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
- return service;
+ return localServiceInboundWire;
}
});
EasyMock.replay(sibling);
@@ -175,10 +184,10 @@
private void
createLocalReferenceToSiblingCompositeServiceConfigurationNoMatchingBinding()
throws Exception {
final CompositeComponent sibling =
EasyMock.createMock(CompositeComponent.class);
- sibling.getService(TARGET_SERVICE);
+ sibling.getInboundWire(TARGET_SERVICE);
EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
- return service;
+ return null;
}
});
EasyMock.replay(sibling);
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
Sat Jan 6 15:56:16 2007
@@ -1,3 +1,21 @@
+/*
+ * 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.tuscany.core.builder;
import org.apache.tuscany.spi.component.AtomicComponent;
@@ -31,12 +49,9 @@
* @version $Rev$ $Date$
*/
public class ServiceConnectorTestCase extends AbstractConnectorImplTestCase {
- private AtomicComponent atomicTarget;
private CompositeComponent parent;
- private CompositeComponent compositeTarget;
private InboundInvocationChain inboundChain;
private ServiceBinding sourceServiceBinding;
- private Reference referenceTarget;
public void testConnectServiceToAtomicComponent() throws Exception {
configureAtomicTarget();
@@ -104,7 +119,7 @@
inboundWire.setServiceContract(contract);
inboundWire.addInvocationChain(operation, inboundChain);
- atomicTarget = EasyMock.createMock(AtomicComponent.class);
+ AtomicComponent atomicTarget =
EasyMock.createMock(AtomicComponent.class);
EasyMock.expect(atomicTarget.getInboundWire(EasyMock.isA(String.class))).andReturn(inboundWire).atLeastOnce();
EasyMock.expect(atomicTarget.getScope()).andReturn(Scope.COMPOSITE);
EasyMock.expect(atomicTarget.createTargetInvoker(EasyMock.isA(String.class),
@@ -126,9 +141,10 @@
inboundWire.setServiceContract(contract);
inboundWire.addInvocationChain(operation, inboundChain);
- compositeTarget = EasyMock.createMock(CompositeComponent.class);
+ CompositeComponent compositeTarget =
EasyMock.createMock(CompositeComponent.class);
Service service = createLocalService(compositeTarget);
-
EasyMock.expect(compositeTarget.getService(TARGET_SERVICE)).andReturn(service);
+ ServiceBinding binding = service.getServiceBindings().get(0);
+
EasyMock.expect(compositeTarget.getInboundWire(TARGET_SERVICE)).andReturn(binding.getInboundWire());
EasyMock.replay(compositeTarget);
inboundWire.setContainer(compositeTarget);
@@ -141,7 +157,7 @@
private void configureReferenceTarget() throws Exception {
ReferenceBinding binding = createLocalReferenceBinding(TARGET_NAME);
- referenceTarget = new ReferenceImpl(TARGET, parent, contract);
+ Reference referenceTarget = new ReferenceImpl(TARGET, parent,
contract);
referenceTarget.addReferenceBinding(binding);
// put a terminating interceptor on the outbound wire of the reference
for testing an invocation
binding.getOutboundWire().getInvocationChains().get(operation).addInterceptor(new
InvokerInterceptor());
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
Sat Jan 6 15:56:16 2007
@@ -3,6 +3,7 @@
import org.osoa.sca.CompositeContext;
import org.osoa.sca.RequestContext;
import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.CompositeComponent;
@@ -210,7 +211,7 @@
Service service = new ServiceImpl("Foo", null, null);
service.addServiceBinding(serviceBinding);
CompositeComponent child =
EasyMock.createMock(CompositeComponent.class);
- EasyMock.expect(child.getService("Bar")).andReturn(service);
+ EasyMock.expect(child.getChild("Bar")).andReturn(service);
EasyMock.replay(child);
CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
EasyMock.expect(composite.getChild("Foo")).andReturn(child);
@@ -229,6 +230,26 @@
EasyMock.verify(wire);
EasyMock.verify(child);
EasyMock.verify(serviceBinding);
+ }
+
+ public void testCompositeLocateNotAService() throws Exception {
+ CompositeComponent child =
EasyMock.createMock(CompositeComponent.class);
+
EasyMock.expect(child.getChild("Bar")).andReturn(EasyMock.createNiceMock(AtomicComponent.class));
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService wireService = EasyMock.createNiceMock(WireService.class);
+ CompositeContextImpl context = new CompositeContextImpl(composite,
wireService);
+ try {
+ context.locateService(FooService.class, "Foo/Bar");
+ //fail
+ } catch (ServiceRuntimeException e) {
+ //expected
+ }
+ EasyMock.verify(composite);
+ EasyMock.verify(child);
}
private class FooService {
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java
Sat Jan 6 15:56:16 2007
@@ -59,55 +59,6 @@
Assert.assertEquals(1, composite.getChildren().size());
}
- public void testGetServices() throws Exception {
- CompositeComponent composite = new CompositeComponentImpl("parent",
null, null, null);
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn("foo").atLeastOnce();
- EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
- service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
- EasyMock.replay(service);
- composite.register(service);
- composite.register(getReference("bar"));
- Assert.assertEquals(1, composite.getServices().size());
- }
-
- public void testGetService() throws Exception {
- CompositeComponent composite = new CompositeComponentImpl("parent",
null, null, null);
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn("foo").atLeastOnce();
- EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
- service.start();
- service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
- EasyMock.replay(service);
- composite.register(service);
- composite.start();
- assertNotNull(composite.getService("foo"));
- }
-
- public void testServiceNotFound() throws Exception {
- CompositeComponent composite = new CompositeComponentImpl("parent",
null, null, null);
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn("foo").atLeastOnce();
- EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
- service.start();
- service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
- EasyMock.replay(service);
-
- composite.register(service);
- composite.start();
- assertNull(composite.getService("bar"));
- }
-
- public void testNotService() throws Exception {
- CompositeComponent composite = new CompositeComponentImpl("parent",
null, null, null);
- composite.register(getReference("foo"));
- composite.start();
- assertNull(composite.getService("foo"));
- }
-
public void testReferencesServices() throws Exception {
CompositeComponent composite = new CompositeComponentImpl("parent",
null, null, null);
Service service = EasyMock.createMock(Service.class);
@@ -118,7 +69,6 @@
EasyMock.replay(service);
composite.register(service);
composite.register(getReference("bar"));
- Assert.assertEquals(1, composite.getReferences().size());
}
public void testOnEvent() {
Modified:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java
Sat Jan 6 15:56:16 2007
@@ -19,12 +19,10 @@
package org.apache.tuscany.core.implementation.composite;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.apache.tuscany.spi.component.AtomicComponent;
import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.Service;
import org.apache.tuscany.spi.wire.InboundWire;
import junit.framework.TestCase;
@@ -73,41 +71,6 @@
assertNull(parent.getSystemChild("source"));
assertTrue(parent.getChild("source") instanceof AtomicComponent);
EasyMock.verify(component);
- }
-
-
- public void testGetService() throws Exception {
- CompositeComponent parent = new CompositeComponentImpl("foo", null,
null, null);
- parent.start();
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn("source").atLeastOnce();
- EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
- InboundWire wire = TestUtils.createInboundWire(Source.class);
- wire.setContainer(service);
- service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
- EasyMock.replay(service);
- parent.register(service);
- assertNotNull(parent.getService("source"));
- assertNull(parent.getSystemService("source"));
- EasyMock.verify(service);
- }
-
- public void testSystemGetService() throws Exception {
- CompositeComponent parent = new CompositeComponentImpl("foo", null,
null, null);
- parent.start();
- Service service = EasyMock.createMock(Service.class);
- EasyMock.expect(service.getName()).andReturn("source").atLeastOnce();
- EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce();
- InboundWire wire = TestUtils.createInboundWire(Source.class);
- wire.setContainer(service);
- service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
- EasyMock.replay(service);
- parent.register(service);
- assertNull(parent.getService("source"));
- assertNotNull(parent.getSystemService("source"));
- EasyMock.verify(service);
}
Modified:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/CompositeComponent.java
Sat Jan 6 15:56:16 2007
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.spi.component;
+import java.util.Collection;
import java.util.List;
import org.w3c.dom.Document;
@@ -110,34 +111,19 @@
List<SCAObject> getSystemChildren();
/**
- * Returns the serviceBindings contained by the composite
- */
- List<Service> getServices();
-
- /**
- * Returns the system serviceBindings contained by the composite
- */
- List<Service> getSystemServices();
-
- /**
- * Returns the service associated with the given name
- */
- Service getService(String name);
-
- /**
- * Returns the system service associated with the given name
- */
- Service getSystemService(String name);
-
- /**
- * Returns the references contained by the composite
+ * Returns the internal system wire associated with the given service name
or null if not found
+ *
+ * @param serviceName the service name
+ * @return the system wire or null if not found
*/
- List<Reference> getReferences();
+ InboundWire getInboundSystemWire(String serviceName);
/**
- * Returns the system references contained by the composite
+ * Returns all internal wires for system services contained by this
composite
+ *
+ * @return all internal wires for system services contained by this
composite
*/
- List<Reference> getSystemReferences();
+ Collection<InboundWire> getInboundSystemWires();
/**
* Invoked by child components to return an wire to a target based on
matching type. Resolved targets may be
Modified:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
Sat Jan 6 15:56:16 2007
@@ -26,36 +26,29 @@
import org.apache.tuscany.spi.model.PropertyValue;
/**
- *
* @version Provides support for property accessors.
- *
*/
public abstract class AbstractComponentExtension extends AbstractSCAObject
implements Component {
- /** Default property values. */
+ /**
+ * Default property values.
+ */
private Map<String, PropertyValue<?>> defaultPropertyValues;
-
+
/**
* Initializes component name and parent.
- *
- * @param name Name of the component.
+ *
+ * @param name Name of the component.
* @param parent Parent of the component.
- * @param componentDefinition Definition of this component.
*/
public AbstractComponentExtension(String name, CompositeComponent parent) {
super(name, parent);
}
- /**
- * @see
org.apache.tuscany.spi.component.Component#getDefaultPropertyValues()
- */
public Map<String, PropertyValue<?>> getDefaultPropertyValues() {
return defaultPropertyValues;
}
- /**
- * @see
org.apache.tuscany.spi.component.Component#setDefaultPropertyValues(java.util.Map)
- */
public void setDefaultPropertyValues(Map<String, PropertyValue<?>>
defaultPropertyValues) {
this.defaultPropertyValues = defaultPropertyValues;
}
Modified:
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
Sat Jan 6 15:56:16 2007
@@ -135,26 +135,10 @@
return Collections.unmodifiableList(new
ArrayList<SCAObject>(systemChildren.values()));
}
- public List<Service> getSystemServices() {
- return Collections.unmodifiableList(systemServices);
- }
-
- public List<Reference> getSystemReferences() {
- return Collections.unmodifiableList(systemReferenceBindings);
- }
-
public List<SCAObject> getChildren() {
return Collections.unmodifiableList(new
ArrayList<SCAObject>(children.values()));
}
- public List<Service> getServices() {
- return Collections.unmodifiableList(services);
- }
-
- public List<Reference> getReferences() {
- return Collections.unmodifiableList(references);
- }
-
public void register(SCAObject child) throws
ComponentRegistrationException {
assert child instanceof Service || child instanceof Reference || child
instanceof Component;
if (child.isSystem()) {
@@ -221,11 +205,42 @@
}
public InboundWire getInboundWire(String serviceName) {
- SCAObject object = children.get(serviceName);
- if (!(object instanceof Service)) {
- return null;
+ Service service;
+ if (serviceName == null) {
+ if (services.size() != 1) {
+ return null;
+ }
+ service = services.get(0);
+ } else {
+ SCAObject object = children.get(serviceName);
+ if (!(object instanceof Service)) {
+ return null;
+ }
+ service = (Service) object;
+ }
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ InboundWire wire = binding.getInboundWire();
+ if (Wire.LOCAL_BINDING.equals(wire.getBindingType())) {
+ return wire;
+ }
+ }
+ return null;
+ }
+
+ public InboundWire getInboundSystemWire(String serviceName) {
+ Service service;
+ if (serviceName == null) {
+ if (systemServices.size() != 1) {
+ return null;
+ }
+ service = systemServices.get(0);
+ } else {
+ SCAObject object = systemChildren.get(serviceName);
+ if (!(object instanceof Service)) {
+ return null;
+ }
+ service = (Service) object;
}
- Service service = (Service) object;
for (ServiceBinding binding : service.getServiceBindings()) {
InboundWire wire = binding.getInboundWire();
if (Wire.LOCAL_BINDING.equals(wire.getBindingType())) {
@@ -247,32 +262,16 @@
}
}
- public Service getService(String name) {
- if (name == null) {
- if (services.size() != 1) {
- return null;
- }
- return services.get(0);
- }
- SCAObject object = children.get(name);
- if (object instanceof Service) {
- return (Service) object;
- }
- return null;
- }
-
- public Service getSystemService(String name) {
- if (name == null) {
- if (systemServices.size() != 1) {
- return null;
+ public Collection<InboundWire> getInboundSystemWires() {
+ synchronized (systemServices) {
+ List<InboundWire> map = new ArrayList<InboundWire>();
+ for (Service service : systemServices) {
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ map.add(binding.getInboundWire());
+ }
}
- return systemServices.get(0);
- }
- SCAObject object = systemChildren.get(name);
- if (object instanceof Service) {
- return (Service) object;
+ return map;
}
- return null;
}
public InboundWire resolveAutowire(Class<?> instanceInterface) throws
TargetResolutionException {
@@ -427,22 +426,21 @@
}
}
- protected void registerAutowireInternal(Class<?> interfaze, ServiceBinding
binding)
+ protected void registerAutowireInternal(Class<?> interfaze, InboundWire
wire, boolean isSystem)
throws InvalidAutowireInterface {
if (interfaze == null) {
// The ServiceContract is not from Java
return;
}
- if (binding.isSystem()) {
+ if (isSystem()) {
if (systemAutowireInternal.containsKey(interfaze)) {
return;
}
- systemAutowireInternal.put(interfaze, binding.getInboundWire());
+ systemAutowireInternal.put(interfaze, wire);
} else {
if (autowireInternal.containsKey(interfaze)) {
return;
}
- InboundWire wire = binding.getInboundWire();
if
(!interfaze.isAssignableFrom(wire.getServiceContract().getInterfaceClass())) {
String iName = interfaze.getName();
throw new InvalidAutowireInterface("Matching inbound wire not
found for interface", iName);
@@ -522,17 +520,15 @@
}
protected void registerAutowire(CompositeComponent component) throws
InvalidAutowireInterface {
- List<Service> services = component.getServices();
- for (Service service : services) {
- // TODO autowire should allow multiple interfaces
- List<ServiceBinding> bindings = service.getServiceBindings();
- if (bindings.size() == 0) {
- return;
- }
- // pick the first binding until autowire allows multiple interfaces
- ServiceBinding binding = bindings.get(0);
- Class clazz =
binding.getInboundWire().getServiceContract().getInterfaceClass();
- registerAutowireInternal(clazz, binding);
+ Collection<InboundWire> wires = component.getInboundWires();
+ for (InboundWire wire : wires) {
+ Class<?> clazz = wire.getServiceContract().getInterfaceClass();
+ registerAutowireInternal(clazz, wire, false);
+ }
+ wires = component.getInboundWires();
+ for (InboundWire wire : wires) {
+ Class<?> clazz = wire.getServiceContract().getInterfaceClass();
+ registerAutowireInternal(clazz, wire, true);
}
}
Modified:
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
(original)
+++
incubator/tuscany/java/sca/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
Sat Jan 6 15:56:16 2007
@@ -41,29 +41,46 @@
*/
public class CompositeComponentExtensionTestCase extends TestCase {
private CompositeComponent composite;
+ private ServiceContract<?> contract;
- public void testDefaultService() throws Exception {
+ public void testDefaultInboundWire() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+
EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+
EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ EasyMock.replay(wire);
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+
EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce();
+ EasyMock.replay(binding);
Service service = EasyMock.createMock(Service.class);
EasyMock.expect(service.getName()).andReturn("service").atLeastOnce();
EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
+ List<ServiceBinding> bindings = new ArrayList<ServiceBinding>();
+ bindings.add(binding);
+ EasyMock.expectLastCall().andReturn(bindings).atLeastOnce();
EasyMock.replay(service);
composite.register(service);
- assertEquals(service, composite.getService(null));
- assertNull(composite.getSystemService(null));
+ assertEquals(wire, composite.getInboundWire(null));
}
- public void testSystemService() throws Exception {
+ public void testDefaultSystemInboundWire() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+
EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+
EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ EasyMock.replay(wire);
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+
EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce();
+ EasyMock.replay(binding);
Service service = EasyMock.createMock(Service.class);
EasyMock.expect(service.getName()).andReturn("service").atLeastOnce();
EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce();
service.getServiceBindings();
-
EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce();
+ List<ServiceBinding> bindings = new ArrayList<ServiceBinding>();
+ bindings.add(binding);
+ EasyMock.expectLastCall().andReturn(bindings).atLeastOnce();
EasyMock.replay(service);
composite.register(service);
- assertNull(composite.getService(null));
- assertEquals(service, composite.getSystemService(null));
+ assertEquals(wire, composite.getInboundSystemWire(null));
}
public void testMoreThanOneServiceGetDefault() throws Exception {
@@ -83,8 +100,8 @@
composite.register(service1);
composite.register(service2);
- assertNull(composite.getService(null));
- assertNull(composite.getSystemService(null));
+ assertNull(composite.getInboundWire(null));
+ assertNull(composite.getInboundSystemWire(null));
}
public void testInboundWire() throws Exception {
@@ -111,8 +128,35 @@
assertNotNull(composite.getInboundWire("service"));
}
+ public void testInboundSystemWire() throws Exception {
+ ServiceContract<?> contract = new ServiceContract(Object.class) {
+ };
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING);
+ wire.getServiceContract();
+ EasyMock.expectLastCall().andReturn(contract).atLeastOnce();
+ EasyMock.replay(wire);
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+
EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce();
+ EasyMock.replay(binding);
+
+ Service service = EasyMock.createMock(Service.class);
+ EasyMock.expect(service.getName()).andReturn("service").atLeastOnce();
+ EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce();
+ List<ServiceBinding> bindings = new ArrayList<ServiceBinding>();
+ bindings.add(binding);
+ service.getServiceBindings();
+ EasyMock.expectLastCall().andReturn(bindings).atLeastOnce();
+ EasyMock.replay(service);
+ composite.register(service);
+ assertNotNull(composite.getInboundSystemWire("service"));
+ }
+
protected void setUp() throws Exception {
super.setUp();
+ contract = new ServiceContract(Object.class) {
+
+ };
composite = new CompositeComponentExtension("foo", null, null, null) {
public TargetInvoker createTargetInvoker(String targetName,
Operation operation, InboundWire callbackWire)
Modified:
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/ServiceInvocationTestCase.java
Sat Jan 6 15:56:16 2007
@@ -67,7 +67,7 @@
chain.setTargetInvoker(composite.createTargetInvoker("foo",
chain.getOperation(), null));
}
composite.register(service);
- InboundWire wire =
composite.getService("fooService").getServiceBindings().get(0).getInboundWire();
+ InboundWire wire = composite.getInboundWire("fooService");
TestBean serviceInstance = wireService.createProxy(TestBean.class,
wire);
assertEquals("bar", serviceInstance.echo("bar"));
}
Modified:
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java?view=diff&rev=493605&r1=493604&r2=493605
==============================================================================
---
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
(original)
+++
incubator/tuscany/java/sca/services/containers/container.spring/src/test/java/org/apache/tuscany/container/spring/impl/SpringCompositeBuilderTestCase.java
Sat Jan 6 15:56:16 2007
@@ -95,8 +95,7 @@
DeploymentContext context = createNiceMock(DeploymentContext.class);
CompositeComponent component = (CompositeComponent)
builder.build(parent, definition, context);
component.start();
- ServiceBinding fooServiceBinding =
component.getService("fooServiceBinding").getServiceBindings().get(0);
- TestBean bean = wireService.createProxy(TestBean.class,
fooServiceBinding.getInboundWire());
+ TestBean bean = wireService.createProxy(TestBean.class,
component.getInboundWire("fooServiceBinding"));
assertEquals("call foo", bean.echo("call foo"));
verify(registry);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]