Author: jmarino
Date: Fri Jan 5 10:30:05 2007
New Revision: 493121
URL: http://svn.apache.org/viewvc?view=rev&rev=493121
Log:
start to add support for ComponentContext with managed code
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
(with props)
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
(with props)
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
(with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
(with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
(with props)
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
(with props)
Removed:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/launcher/CompositeContextImplTestCase.java
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
Added:
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=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,115 @@
+/*
+ * 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.implementation.composite;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.SCA;
+import org.osoa.sca.ServiceRuntimeException;
+
+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.ReferenceBinding;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * Base implementation of the [EMAIL PROTECTED] org.osoa.sca.CompositeContext}
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractCompositeContext extends SCA implements
CompositeContext {
+ protected final CompositeComponent composite;
+ protected final WireService wireService;
+
+ public AbstractCompositeContext(final CompositeComponent composite, final
WireService wireService) {
+ this.composite = composite;
+ this.wireService = wireService;
+ }
+
+ public String getCompositeName() {
+ return composite.getName();
+ }
+
+ public String getCompositeURI() {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T locateService(Class<T> serviceInterface, String serviceName)
throws ServiceRuntimeException {
+ String name = serviceInterface.getName();
+ QualifiedName qName = new QualifiedName(serviceName);
+ SCAObject child = composite.getChild(qName.getPartName());
+ InboundWire wire;
+ if (child instanceof CompositeComponent) {
+ CompositeComponent childComposite = (CompositeComponent) child;
+ child = childComposite.getService(qName.getPortName());
+ if (child == null) {
+ throw new ServiceRuntimeException("Service not found [" +
serviceName + "]");
+ }
+ wire = getInboundWire(child, name, "");
+ } else {
+ wire = getInboundWire(child, name, qName.getPortName());
+ }
+ if (wire.isOptimizable()
+ && wire.getServiceContract().getInterfaceClass() != null
+ &&
serviceInterface.isAssignableFrom(wire.getServiceContract().getInterfaceClass()))
{
+ try {
+ return serviceInterface.cast(wire.getTargetService());
+ } catch (TargetResolutionException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ return wireService.createProxy(serviceInterface, wire);
+ }
+
+ protected InboundWire getInboundWire(SCAObject child, String name, String
serviceName) {
+ InboundWire wire = null;
+ if (child instanceof AtomicComponent) {
+ wire = ((AtomicComponent) child).getInboundWire(name);
+ if (wire == null) {
+ String qName = serviceName + QualifiedName.NAME_SEPARATOR +
name;
+ throw new ServiceRuntimeException("Service not found [" +
qName + "]");
+ }
+ } else if (child instanceof Service) {
+ Service service = (Service) child;
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ if
(Wire.LOCAL_BINDING.equals(binding.getInboundWire().getBindingType())) {
+ wire = binding.getInboundWire();
+ break;
+ }
+ }
+ if (wire == null) {
+ throw new ServiceRuntimeException("Local binding for service
not found [" + name + "]");
+ }
+ } else if (child instanceof ReferenceBinding) {
+ wire = ((ReferenceBinding) child).getInboundWire();
+ } else if (child == null) {
+ throw new ServiceRuntimeException("Service not found [" +
serviceName + "]");
+ } else {
+ throw new ServiceRuntimeException("Invalid service type [" +
child.getClass().getName() + "]");
+ }
+ return wire;
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java?view=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.implementation.composite;
+
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * The default implementation of a [EMAIL PROTECTED]
org.osoa.sca.CompositeContext} injected on a component implementation
+ * instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ManagedCompositeContext extends AbstractCompositeContext {
+
+ /**
+ * Constructor.
+ *
+ * @param composite the parent composite of the component whose instance
the current context is injected on
+ * @param wireService the wire service to use for generating proxies
+ */
+ public ManagedCompositeContext(final CompositeComponent composite, final
WireService wireService) {
+ super(composite, wireService);
+ }
+
+ public String getCompositeName() {
+ return composite.getName();
+ }
+
+ public String getCompositeURI() {
+ throw new UnsupportedOperationException();
+ }
+
+ public RequestContext getRequestContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ServiceReference createServiceReferenceForSession(Object self) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ServiceReference createServiceReferenceForSession(Object self,
String serviceName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ServiceReference newSession(String serviceName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public ServiceReference newSession(String serviceName, Object sessionId) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void start() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void stop() {
+ throw new UnsupportedOperationException();
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedCompositeContext.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java?view=diff&rev=493121&r1=493120&r2=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java
Fri Jan 5 10:30:05 2007
@@ -25,15 +25,20 @@
import org.osoa.sca.RequestContext;
import org.osoa.sca.annotations.Context;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
import
org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
import org.apache.tuscany.spi.implementation.java.JavaMappedService;
import org.apache.tuscany.spi.implementation.java.PojoComponentType;
import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.wire.WireService;
+
+import org.apache.tuscany.core.injection.ContextObjectFactory;
import org.apache.tuscany.core.util.JavaIntrospectionHelper;
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
/**
* Processes [EMAIL PROTECTED] @Context} annotations on a component
implementation and adds a [EMAIL PROTECTED] JavaMappedProperty} to the
@@ -42,8 +47,15 @@
* @version $Rev$ $Date$
*/
public class ContextProcessor extends ImplementationProcessorExtension {
+ private WireService wireService;
+
+ @Autowire
+ public void setWireService(WireService wireService) {
+ this.wireService = wireService;
+ }
- public void visitMethod(CompositeComponent parent, Method method,
+ public void visitMethod(CompositeComponent parent,
+ Method method,
PojoComponentType<JavaMappedService,
JavaMappedReference, JavaMappedProperty<?>> type,
DeploymentContext context)
throws ProcessingException {
@@ -59,35 +71,41 @@
if (name.startsWith("set")) {
name = JavaIntrospectionHelper.toPropertyName(name);
}
- JavaMappedProperty property = new JavaMappedProperty();
- property.setName(name);
- property.setMember(method);
- throw new UnsupportedOperationException();
- // TODO pass in composite context
- //SingletonObjectFactory factory = new
SingletonObjectFactory(compositeContext);
- //property.setDefaultValueFactory(factory);
- //type.getProperties().put(name,property);
+ Resource resource = new Resource();
+ resource.setName(name);
+ resource.setMember(method);
+ resource.setObjectFactory(new ContextObjectFactory(parent,
wireService));
+ type.getResources().put(name, resource);
} else if (RequestContext.class.equals(paramType)) {
String name = method.getName();
if (name.startsWith("set")) {
name = JavaIntrospectionHelper.toPropertyName(name);
}
- JavaMappedProperty property = new JavaMappedProperty();
- property.setName(name);
- property.setMember(method);
+ Resource resource = new Resource();
+ resource.setName(name);
+ resource.setMember(method);
throw new UnsupportedOperationException();
- // TODO pass in request context
- //property.setDefaultValueFactory(factory);
- //type.getProperties().put(name,property);
} else {
throw new UnknownContextTypeException(paramType.getName());
}
-
}
public void visitField(CompositeComponent parent, Field field,
PojoComponentType<JavaMappedService,
JavaMappedReference, JavaMappedProperty<?>> type,
DeploymentContext context) throws
ProcessingException {
- super.visitField(parent, field, type, context);
+ if (field.getAnnotation(Context.class) == null) {
+ return;
+ }
+ Class<?> paramType = field.getType();
+ if (CompositeContext.class.equals(paramType)) {
+ String name = field.getName();
+ Resource resource = new Resource();
+ resource.setName(name);
+ resource.setMember(field);
+ resource.setObjectFactory(new ContextObjectFactory(parent,
wireService));
+ type.getResources().put(name, resource);
+ } else {
+ throw new UnknownContextTypeException(paramType.getName());
+ }
}
}
Added:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java?view=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.injection;
+
+import org.osoa.sca.CompositeContext;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.wire.WireService;
+
+import
org.apache.tuscany.core.implementation.composite.ManagedCompositeContext;
+
+/**
+ * Creates instances of [EMAIL PROTECTED]
org.apache.tuscany.core.implementation.composite.ManagedCompositeContext} for
injection
+ * on component implementation instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContextObjectFactory implements ObjectFactory<CompositeContext> {
+ private CompositeComponent composite;
+ private WireService wireService;
+
+ public ContextObjectFactory(CompositeComponent composite, WireService
wireService) {
+ assert composite != null;
+ assert wireService != null;
+ this.composite = composite;
+ this.wireService = wireService;
+ }
+
+ public CompositeContext getInstance() throws ObjectCreationException {
+ return new ManagedCompositeContext(composite, wireService);
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java?view=diff&rev=493121&r1=493120&r2=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
(original)
+++
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
Fri Jan 5 10:30:05 2007
@@ -18,37 +18,24 @@
*/
package org.apache.tuscany.core.launcher;
-import org.osoa.sca.CompositeContext;
import org.osoa.sca.RequestContext;
-import org.osoa.sca.SCA;
import org.osoa.sca.ServiceReference;
-import org.osoa.sca.ServiceRuntimeException;
-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.ReferenceBinding;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.component.Service;
-import org.apache.tuscany.spi.component.ServiceBinding;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.Wire;
import org.apache.tuscany.spi.wire.WireService;
+import
org.apache.tuscany.core.implementation.composite.AbstractCompositeContext;
+
/**
- * Default implementation of the [EMAIL PROTECTED]
org.osoa.sca.CompositeContext}
+ * Default implementation of the [EMAIL PROTECTED]
org.osoa.sca.CompositeContext} for non-managed code
*
* @version $Rev$ $Date$
*/
-public class CompositeContextImpl extends SCA implements CompositeContext {
- protected final CompositeComponent composite;
- protected final WireService wireService;
+public class CompositeContextImpl extends AbstractCompositeContext {
public CompositeContextImpl(final CompositeComponent composite, final
WireService wireService) {
- this.composite = composite;
- this.wireService = wireService;
+ super(composite, wireService);
}
public void start() {
@@ -59,41 +46,6 @@
setCompositeContext(null);
}
- public String getCompositeName() {
- return composite.getName();
- }
-
- public String getCompositeURI() {
- throw new UnsupportedOperationException();
- }
-
- public <T> T locateService(Class<T> serviceInterface, String serviceName)
throws ServiceRuntimeException {
- String name = serviceInterface.getName();
- QualifiedName qName = new QualifiedName(serviceName);
- SCAObject child = composite.getChild(qName.getPartName());
- InboundWire wire;
- if (child instanceof CompositeComponent) {
- CompositeComponent childComposite = (CompositeComponent) child;
- child = childComposite.getService(qName.getPortName());
- if (child == null) {
- throw new ServiceRuntimeException("Service not found [" +
serviceName + "]");
- }
- wire = getInboundWire(child, name, "");
- } else {
- wire = getInboundWire(child, name, qName.getPortName());
- }
- if (wire.isOptimizable()
- && wire.getServiceContract().getInterfaceClass() != null
- &&
serviceInterface.isAssignableFrom(wire.getServiceContract().getInterfaceClass()))
{
- try {
- return serviceInterface.cast(wire.getTargetService());
- } catch (TargetResolutionException e) {
- throw new ServiceRuntimeException(e);
- }
- }
- return wireService.createProxy(serviceInterface, wire);
- }
-
public ServiceReference createServiceReferenceForSession(Object arg0) {
throw new UnsupportedOperationException();
}
@@ -113,34 +65,4 @@
public ServiceReference newSession(String arg0, Object arg1) {
throw new UnsupportedOperationException();
}
-
- private InboundWire getInboundWire(SCAObject child, String name, String
serviceName) {
- InboundWire wire = null;
- if (child instanceof AtomicComponent) {
- wire = ((AtomicComponent) child).getInboundWire(name);
- if (wire == null) {
- String qName = serviceName + QualifiedName.NAME_SEPARATOR +
name;
- throw new ServiceRuntimeException("Service not found [" +
qName + "]");
- }
- } else if (child instanceof Service) {
- Service service = (Service) child;
- for (ServiceBinding binding : service.getServiceBindings()) {
- if
(Wire.LOCAL_BINDING.equals(binding.getInboundWire().getBindingType())) {
- wire = binding.getInboundWire();
- break;
- }
- }
- if (wire == null) {
- throw new ServiceRuntimeException("Local binding for service
not found [" + name + "]");
- }
- } else if (child instanceof ReferenceBinding) {
- wire = ((ReferenceBinding) child).getInboundWire();
- } else if (child == null) {
- throw new ServiceRuntimeException("Service not found [" +
serviceName + "]");
- } else {
- throw new ServiceRuntimeException("Invalid service type [" +
child.getClass().getName() + "]");
- }
- return wire;
- }
-
}
Added:
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=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,273 @@
+package org.apache.tuscany.core.implementation.composite;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.WireService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractCompositeContextTestCase extends TestCase {
+
+ public void testGetName() throws Exception {
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getName()).andReturn("foo");
+ EasyMock.replay(composite);
+ WireService wireService = EasyMock.createNiceMock(WireService.class);
+ CompositeContext context = new TestCompositeContext(composite,
wireService);
+ assertEquals("foo", context.getCompositeName());
+ }
+
+ public void testAtomicLocate() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ AtomicComponent child = EasyMock.createMock(AtomicComponent.class);
+
EasyMock.expect(child.getInboundWire(AbstractCompositeContextTestCase.FooService.class.getName()))
+ .andReturn(wire);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService wireService = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+
wireService.createProxy(EasyMock.eq(AbstractCompositeContextTestCase.FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(wireService);
+ CompositeContext context = new TestCompositeContext(composite,
wireService);
+ context.locateService(FooService.class, "Foo");
+ EasyMock.verify(wireService);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ }
+
+ /**
+ * Verifies the locateService checks for wire optimizations and if
possible, avoids proxying the target instance
+ */
+ public void testOptimizedAtomicLocate() throws Exception {
+ ServiceContract<?> contract = new
JavaServiceContract(AbstractCompositeContextTestCase.FooService.class);
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getTargetService()).andReturn(new
AbstractCompositeContextTestCase.FooService());
+
EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.replay(wire);
+ AtomicComponent child = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(child.getInboundWire(FooService.class.getName()))
+ .andReturn(wire);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService wireService = EasyMock.createMock(WireService.class);
+ EasyMock.replay(wireService);
+ CompositeContextImpl context = new CompositeContextImpl(composite,
wireService);
+ context.locateService(FooService.class, "Foo");
+ EasyMock.verify(wireService);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ }
+
+ public void testCannotOptimizeAtomicLocate() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract(Object.class);
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+
EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.replay(wire);
+ AtomicComponent child = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(child.getInboundWire(FooService.class.getName()))
+ .andReturn(wire);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService service = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+ service.createProxy(EasyMock.eq(FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(service);
+
+ CompositeContextImpl context = new CompositeContextImpl(composite,
service);
+
context.locateService(AbstractCompositeContextTestCase.FooService.class, "Foo");
+ EasyMock.verify(service);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ }
+
+ public void testNoWireJavaInterfaceAtomicLocate() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract();
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getServiceContract()).andReturn(contract);
+ EasyMock.replay(wire);
+ AtomicComponent child = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(child.getInboundWire(FooService.class.getName()))
+ .andReturn(wire);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService service = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+
service.createProxy(EasyMock.eq(AbstractCompositeContextTestCase.FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(service);
+
+ CompositeContextImpl context = new CompositeContextImpl(composite,
service);
+ context.locateService(FooService.class, "Foo");
+ EasyMock.verify(service);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ }
+
+ public void testServiceLocate() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+
EasyMock.expect(wire.getBindingType()).andReturn(InboundWire.LOCAL_BINDING);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.setService(EasyMock.isA(Service.class));
+
EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce();
+ EasyMock.replay(binding);
+ Service child = new ServiceImpl("Foo", null, null);
+ child.addServiceBinding(binding);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService service = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+
service.createProxy(EasyMock.eq(AbstractCompositeContextTestCase.FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(service);
+ CompositeContextImpl context = new CompositeContextImpl(composite,
service);
+
context.locateService(AbstractCompositeContextTestCase.FooService.class, "Foo");
+ EasyMock.verify(service);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(binding);
+ }
+
+ public void testReferenceLocate() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ReferenceBinding child = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(child.getInboundWire()).andReturn(wire);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService service = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+
service.createProxy(EasyMock.eq(AbstractCompositeContextTestCase.FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(service);
+ CompositeContextImpl context = new CompositeContextImpl(composite,
service);
+
context.locateService(AbstractCompositeContextTestCase.FooService.class, "Foo");
+ EasyMock.verify(service);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ }
+
+ public void testCompositeLocate() throws Exception {
+ InboundWire wire = EasyMock.createMock(InboundWire.class);
+
EasyMock.expect(wire.getBindingType()).andReturn(InboundWire.LOCAL_BINDING);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ServiceBinding serviceBinding =
EasyMock.createMock(ServiceBinding.class);
+ serviceBinding.setService(EasyMock.isA(Service.class));
+
EasyMock.expect(serviceBinding.getInboundWire()).andReturn(wire).atLeastOnce();
+ EasyMock.replay(serviceBinding);
+ Service service = new ServiceImpl("Foo", null, null);
+ service.addServiceBinding(serviceBinding);
+ CompositeComponent child =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(child.getService("Bar")).andReturn(service);
+ EasyMock.replay(child);
+ CompositeComponent composite =
EasyMock.createMock(CompositeComponent.class);
+ EasyMock.expect(composite.getChild("Foo")).andReturn(child);
+ EasyMock.replay(composite);
+
+ WireService wireService = EasyMock.createMock(WireService.class);
+ EasyMock.expect(
+
wireService.createProxy(EasyMock.eq(AbstractCompositeContextTestCase.FooService.class),
EasyMock.eq(wire)))
+ .andReturn(new AbstractCompositeContextTestCase.FooService() {
+ });
+ EasyMock.replay(wireService);
+ CompositeContextImpl context = new CompositeContextImpl(composite,
wireService);
+
context.locateService(AbstractCompositeContextTestCase.FooService.class,
"Foo/Bar");
+ EasyMock.verify(wireService);
+ EasyMock.verify(composite);
+ EasyMock.verify(wire);
+ EasyMock.verify(child);
+ EasyMock.verify(serviceBinding);
+ }
+
+ private class FooService {
+
+ }
+
+ private class TestCompositeContext extends AbstractCompositeContext {
+
+ public TestCompositeContext(final CompositeComponent composite, final
WireService wireService) {
+ super(composite, wireService);
+ }
+
+ public void start() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ public RequestContext getRequestContext() {
+ return null;
+ }
+
+ public ServiceReference createServiceReferenceForSession(Object self) {
+ return null;
+ }
+
+ public ServiceReference createServiceReferenceForSession(Object self,
String serviceName) {
+ return null;
+ }
+
+ public ServiceReference newSession(String serviceName) {
+ return null;
+ }
+
+ public ServiceReference newSession(String serviceName, Object
sessionId) {
+ return null;
+ }
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContextTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java?view=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,166 @@
+/*
+ * 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.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.annotations.Context;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.wire.WireService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private CompositeComponent composite;
+
+ public void testMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext",
CompositeContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ processor.visitMethod(composite, method, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+
+ public void testField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ processor.visitField(composite, field, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(composite, method, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ try {
+ processor.visitField(composite, field, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext",
CompositeContext.class, String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(composite, method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(composite, method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext",
CompositeContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ processor.visitMethod(composite, method, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference,
JavaMappedProperty<?>>();
+ processor.visitField(composite, field, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new ContextProcessor();
+ processor.setWireService(EasyMock.createNiceMock(WireService.class));
+ composite = EasyMock.createNiceMock(CompositeComponent.class);
+ }
+
+ private class Foo {
+ @Context
+ protected CompositeContext context;
+
+ @Context
+ protected Object badContext;
+
+ protected CompositeContext noContext;
+
+ @Context
+ public void setContext(CompositeContext context) {
+
+ }
+
+ @Context
+ public void setContext(String context) {
+
+ }
+
+ @Context
+ public void setContext(CompositeContext context, String string) {
+
+ }
+
+ @Context
+ public void setContext() {
+
+ }
+
+ public void noContext(CompositeContext context) {
+
+ }
+
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java?view=auto&rev=493121
==============================================================================
---
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
(added)
+++
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
Fri Jan 5 10:30:05 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.injection;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.wire.WireService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextObjectFactoryTestCase extends TestCase {
+
+ public void testCreation() throws Exception {
+ CompositeComponent composite =
EasyMock.createNiceMock(CompositeComponent.class);
+ WireService wireService = EasyMock.createNiceMock(WireService.class);
+ ContextObjectFactory factory = new ContextObjectFactory(composite,
wireService);
+ assertNotNull(factory.getInstance());
+ }
+}
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ContextObjectFactoryTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]