Author: slaws
Date: Wed Sep 10 05:45:05 2008
New Revision: 693821
URL: http://svn.apache.org/viewvc?rev=693821&view=rev
Log:
TUSCANY-2587 - changing the way that promoted service names are formed so that
component and service name can be easily extracted if required
Modified:
tuscany/branches/sca-java-1.3.2/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
tuscany/branches/sca-java-1.3.2/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java
tuscany/branches/sca-java-1.3.2/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
tuscany/branches/sca-java-1.3.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
Modified:
tuscany/branches/sca-java-1.3.2/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
(original)
+++
tuscany/branches/sca-java-1.3.2/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
Wed Sep 10 05:45:05 2008
@@ -75,13 +75,13 @@
Component componentD = TestUtils.getComponent(domainComposite,
"ComponentD");
if (!nonWiring) {
- // Should create component service $promoted$.Service1 on
innermost component
+ // Should create component service $promoted$Service1 on innermost
component
// ComponentD, with <binding.ws> and uri="/Service1"
// No other services on ComponentD should have <binding.ws>
WebServiceBinding wsBinding = null;
for (ComponentService service : componentD.getServices()) {
WebServiceBinding wsb =
service.getBinding(WebServiceBinding.class);
- if ("$promoted$.Service1".equals(service.getName())) {
+ if ("$promoted$Service1".equals(service.getName())) {
wsBinding = wsb;
} else {
assert wsb == null;
@@ -89,16 +89,16 @@
}
assert "/Service1".equals(wsBinding.getURI());
- // Should create WSDL document for ComponentD/$promoted$.Service1
with endpoint uri="/Service1"
+ // Should create WSDL document for ComponentD/$promoted$Service1
with endpoint uri="/Service1"
Definition def = wsBinding.getWSDLDocument();
javax.wsdl.Service svc = def.getService(new
QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
Port port = svc.getPort("Service3Port");
assert "/Service1".equals(TestUtils.getPortAddress(port));
} else {
- // Should not create component service $promoted$.Service1 on
innermost component ComponentD
+ // Should not create component service $promoted$Service1 on
innermost component ComponentD
// No component services on ComponentD should have <binding.ws>
for (ComponentService service : componentD.getServices()) {
- assert !"$promoted$.Service1".equals(service.getName());
+ assert !"$promoted$Service1".equals(service.getName());
assert service.getBinding(WebServiceBinding.class) == null;
}
}
@@ -168,25 +168,25 @@
Component componentD = TestUtils.getComponent(domainComposite,
"ComponentD");
if (!nonWiring) {
- // Should create component service $promoted$.ComponentB.Service2
on innermost component
+ // Should create component service
$promoted$ComponentB$slash$Service2 on innermost component
// ComponentD, with <binding.ws> and uri="/ComponentB/Service2"
wsBinding = null;
for (ComponentService service : componentD.getServices()) {
- if
("$promoted$.ComponentB.Service2".equals(service.getName())) {
+ if
("$promoted$ComponentB$slash$Service2".equals(service.getName())) {
wsBinding = service.getBinding(WebServiceBinding.class);
}
}
assert "/ComponentB/Service2".equals(wsBinding.getURI());
- // Should create WSDL document for
ComponentD/$promoted$.ComponentB.Service2 with endpoint
uri="/ComponentB/Service2"
+ // Should create WSDL document for
ComponentD/$promoted$ComponentB$slash$Service2 with endpoint
uri="/ComponentB/Service2"
def = wsBinding.getWSDLDocument();
svc = def.getService(new
QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
port = svc.getPort("Service3Port");
assert
"/ComponentB/Service2".equals(TestUtils.getPortAddress(port));
} else {
- // Should not create component service
$promoted$.ComponentB.Service2 on innermost component ComponentD
+ // Should not create component service
$promoted$ComponentB$slash$Service2 on innermost component ComponentD
for (ComponentService service : componentD.getServices()) {
- assert
!"$promoted$.ComponentB.Service2".equals(service.getName());
+ assert
!"$promoted$ComponentB$slash$Service2".equals(service.getName());
}
}
@@ -204,17 +204,17 @@
}
if (!nonWiring) {
- // Should create component service $promoted$.Service1 on
innermost component
+ // Should create component service $promoted$Service1 on innermost
component
// ComponentD, with <binding.ws> and uri="/Service1"
wsBinding = null;
for (ComponentService service : componentD.getServices()) {
- if ("$promoted$.Service1".equals(service.getName())) {
+ if ("$promoted$Service1".equals(service.getName())) {
wsBinding = service.getBinding(WebServiceBinding.class);
}
}
assert "/Service1".equals(wsBinding.getURI());
- // Should create WSDL document for ComponentD/$promoted$.Service1
with endpoint uri="/Service1"
+ // Should create WSDL document for ComponentD/$promoted$Service1
with endpoint uri="/Service1"
def = wsBinding.getWSDLDocument();
svc = def.getService(new
QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
port = svc.getPort("Service3Port");
@@ -222,15 +222,15 @@
} else {
// Should not create component service $promoted$.Service1 on
innermost component ComponentD
for (ComponentService service : componentD.getServices()) {
- assert !"$promoted$.Service1".equals(service.getName());
+ assert !"$promoted$Service1".equals(service.getName());
}
}
- // No services on ComponentD should have <binding.ws>, except for
$promoted$.Service1
- // and $promoted$.ComponentB.Service2
+ // No services on ComponentD should have <binding.ws>, except for
$promoted$Service1
+ // and $promoted$ComponentB$slash$Service2
for (ComponentService service : componentD.getServices()) {
- if (!"$promoted$.Service1".equals(service.getName()) &&
- !"$promoted$.ComponentB.Service2".equals(service.getName())) {
+ if (!"$promoted$Service1".equals(service.getName()) &&
+
!"$promoted$ComponentB$slash$Service2".equals(service.getName())) {
assert service.getBinding(WebServiceBinding.class) == null;
}
}
@@ -334,25 +334,25 @@
assert "/ComponentB/Service2".equals(TestUtils.getPortAddress(port));
if (!nonWiring) {
- // Should create component service $promoted$.ComponentB.Service2
on innermost component
+ // Should create component service
$promoted$ComponentB$slash$Service2 on innermost component
// ComponentD, with <binding.ws> and uri="/ComponentB/Service2"
wsBinding = null;
for (ComponentService service : componentD.getServices()) {
- if
("$promoted$.ComponentB.Service2".equals(service.getName())) {
+ if
("$promoted$ComponentB$slash$Service2".equals(service.getName())) {
wsBinding = service.getBinding(WebServiceBinding.class);
}
}
assert "/ComponentB/Service2".equals(wsBinding.getURI());
- // Should create WSDL document for
ComponentD/$promoted$.ComponentB.Service2 with endpoint
uri="/ComponentB/Service2"
+ // Should create WSDL document for
ComponentD/$promoted$ComponentB$slash$Service2 with endpoint
uri="/ComponentB/Service2"
def = wsBinding.getWSDLDocument();
svc = def.getService(new
QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
port = svc.getPort("Service3Port");
assert
"/ComponentB/Service2".equals(TestUtils.getPortAddress(port));
} else {
- // Should not create component service
$promoted$.ComponentB.Service2 on innermost component ComponentD
+ // Should not create component service
$promoted$ComponentB$slash$Service2 on innermost component ComponentD
for (ComponentService service : componentD.getServices()) {
- assert
!"$promoted$.ComponentB.Service2".equals(service.getName());
+ assert
!"$promoted$ComponentB$slash$Service2".equals(service.getName());
}
}
@@ -370,17 +370,17 @@
}
if (!nonWiring) {
- // Should create component service $promoted$.Service1 on
innermost component
+ // Should create component service $promoted$Service1 on innermost
component
// ComponentD, with <binding.ws> and uri="/Service1"
wsBinding = null;
for (ComponentService service : componentD.getServices()) {
- if ("$promoted$.Service1".equals(service.getName())) {
+ if ("$promoted$Service1".equals(service.getName())) {
wsBinding = service.getBinding(WebServiceBinding.class);
}
}
assert "/Service1".equals(wsBinding.getURI());
- // Should create WSDL document for ComponentD/$promoted$.Service1
with endpoint uri="/Service1"
+ // Should create WSDL document for ComponentD/$promoted$Service1
with endpoint uri="/Service1"
def = wsBinding.getWSDLDocument();
svc = def.getService(new
QName("http://builder.itest.sca.tuscany.apache.org/", "Service3Service"));
port = svc.getPort("Service3Port");
@@ -388,7 +388,7 @@
} else {
// Should not create component service $promoted$.Service1 on
innermost component ComponentD
for (ComponentService service : componentD.getServices()) {
- assert !"$promoted$.Service1".equals(service.getName());
+ assert !"$promoted$Service1".equals(service.getName());
}
}
@@ -396,8 +396,8 @@
// $promoted$.Service1 and $promoted$.ComponentB.Service2
for (ComponentService service : componentD.getServices()) {
if (!"Service3".equals(service.getName()) &&
- !"$promoted$.Service1".equals(service.getName()) &&
- !"$promoted$.ComponentB.Service2".equals(service.getName())) {
+ !"$promoted$Service1".equals(service.getName()) &&
+
!"$promoted$ComponentB$slash$Service2".equals(service.getName())) {
assert service.getBinding(WebServiceBinding.class) == null;
}
}
Modified:
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
Wed Sep 10 05:45:05 2008
@@ -72,7 +72,7 @@
// Create a new component service to represent this
// component service on the promoted component
ComponentService newComponentService =
assemblyFactory.createComponentService();
- newComponentService.setName("$promoted$." +
component.getName() + "." + componentService.getName());
+ newComponentService.setName("$promoted$" +
component.getName() + "$slash$" + componentService.getName());
promotedComponent.getServices().add(newComponentService);
newComponentService.setService(promotedService.getService());
newComponentService.getBindings().addAll(componentService.getBindings());
Modified:
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
Wed Sep 10 05:45:05 2008
@@ -54,7 +54,7 @@
// Create a new component service to represent this composite
// service on the promoted component
ComponentService newComponentService =
assemblyFactory.createComponentService();
- newComponentService.setName("$promoted$." +
compositeService.getName());
+ newComponentService.setName("$promoted$" +
compositeService.getName());
promotedComponent.getServices().add(newComponentService);
newComponentService.setService(promotedService.getService());
newComponentService.getBindings().addAll(compositeService.getBindings());
Modified:
tuscany/branches/sca-java-1.3.2/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestNode.java
Wed Sep 10 05:45:05 2008
@@ -1,232 +1,232 @@
-/*
- * 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.sca.binding.sca.axis2;
-
-import java.net.URL;
-import java.util.logging.Logger;
-
-import javax.xml.namespace.QName;
-
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.Component;
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.CompositeService;
-import org.apache.tuscany.sca.assembly.SCABinding;
-import org.apache.tuscany.sca.assembly.SCABindingFactory;
-import org.apache.tuscany.sca.assembly.xml.Constants;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.contribution.service.ContributionService;
-import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
-import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.osoa.sca.ServiceReference;
-import org.osoa.sca.ServiceRuntimeException;
-
-/**
- * The very minimum node implementation to get these tests going without
creating a dependency on
- * any runtime/hosting implementation
- *
- * @version $Rev: 552343 $ $Date: 2007-09-20 14:53:40 +0100 (Thu, 20 Sep 2007)
$
- */
-public class TestNode {
-
- private static final Logger logger =
Logger.getLogger(TestNode.class.getName());
-
- private String nodeName;
- private ReallySmallRuntime nodeRuntime;
-
- private ClassLoader cl = TestNode.class.getClassLoader();
-
- private Composite nodeComposite = null;
- private Composite appComposite = null;
-
- public TestNode(String nodeName)
- throws Exception {
- this.nodeName = nodeName;
-
- try {
-
- // create and start domainA
- nodeRuntime = new ReallySmallRuntime(cl);
- nodeRuntime.start();
-
- // Create an in-memory domain level composite
- AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
- nodeComposite = assemblyFactory.createComposite();
- nodeComposite.setName(new QName(Constants.SCA10_NS, "domain"));
- nodeComposite.setURI("http://localhost");
-
- // add the top level composite into the composite activator
-
nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);
-
- // add a contribution to the domain
- ContributionService contributionService =
nodeRuntime.getContributionService();
-
- // find the current directory as a URL. This is where our
contribution
- // will come from
- URL contributionURL =
Thread.currentThread().getContextClassLoader().getResource(nodeName + "/");
-
- // Contribute the SCA application
- Contribution contribution =
contributionService.contribute("http://calculator", contributionURL, null,
false);
- appComposite = contribution.getDeployables().get(0);
-
- // Add the deployable composite to the domain
- nodeComposite.getIncludes().add(appComposite);
- nodeRuntime.buildComposite(appComposite);
- nodeRuntime.getCompositeActivator().activate(appComposite);
-
-
- } catch (Exception ex) {
- System.err.println("Exception when creating node " +
ex.getMessage());
- ex.printStackTrace(System.err);
- throw ex;
- }
- }
-
- public void start() {
-
- try {
- nodeRuntime.getCompositeActivator().start(appComposite);
- } catch (Exception ex) {
- System.err.println("Exception when creating domain " +
ex.getMessage());
- ex.printStackTrace(System.err);
- }
-
- }
-
- public void stop() {
- try {
- nodeRuntime.stop();
- } catch (Exception ex) {
- System.err.println("Exception when creating domain " +
ex.getMessage());
- ex.printStackTrace(System.err);
- }
- }
-
- public <B> B getService(Class<B> businessInterface, String serviceName) {
- ServiceReference<B> serviceReference =
getServiceReference(businessInterface, serviceName);
- if (serviceReference == null) {
- throw new ServiceRuntimeException("Service not found: " +
serviceName);
- }
- return serviceReference.getService();
- }
-
- private <B> ServiceReference<B> createServiceReference(Class<B>
businessInterface, String targetURI) {
- try {
- AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
- Composite composite = assemblyFactory.createComposite();
- composite.setName(new QName(Constants.SCA10_TUSCANY_NS,
"default"));
- RuntimeComponent component =
(RuntimeComponent)assemblyFactory.createComponent();
- component.setName("default");
- component.setURI("default");
-
nodeRuntime.getCompositeActivator().configureComponentContext(component);
- composite.getComponents().add(component);
- RuntimeComponentReference reference =
(RuntimeComponentReference)assemblyFactory.createComponentReference();
- reference.setName("default");
- ModelFactoryExtensionPoint factories =
-
nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
- JavaInterfaceFactory javaInterfaceFactory =
factories.getFactory(JavaInterfaceFactory.class);
- InterfaceContract interfaceContract =
javaInterfaceFactory.createJavaInterfaceContract();
-
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
- reference.setInterfaceContract(interfaceContract);
- component.getReferences().add(reference);
- reference.setComponent(component);
- SCABindingFactory scaBindingFactory =
factories.getFactory(SCABindingFactory.class);
- SCABinding binding = scaBindingFactory.createSCABinding();
- binding.setURI(targetURI);
- reference.getBindings().add(binding);
- return new ServiceReferenceImpl<B>(businessInterface, component,
reference, binding, nodeRuntime
- .getProxyFactory(), nodeRuntime.getCompositeActivator());
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- public <B> ServiceReference<B> getServiceReference(Class<B>
businessInterface, String name) {
-
- // Extract the component name
- String componentName;
- String serviceName;
- int i = name.indexOf('/');
- if (i != -1) {
- componentName = name.substring(0, i);
- serviceName = name.substring(i + 1);
-
- } else {
- componentName = name;
- serviceName = null;
- }
-
- // Lookup the component in the domain
-
- Component component = null;
-
- for (Composite composite: nodeComposite.getIncludes()) {
- for (Component componentLoop: composite.getComponents()) {
- if (componentLoop.getName().equals(componentName)) {
- component = componentLoop;
- break;
- }
- }
- }
- if (component == null) {
- // The component is not local in the partition, try to create a
remote service ref
- return createServiceReference(businessInterface, name);
- }
- RuntimeComponentContext componentContext = null;
-
- // If the component is a composite, then we need to find the
- // non-composite component that provides the requested service
- if (component.getImplementation() instanceof Composite) {
- for (ComponentService componentService : component.getServices()) {
- if (serviceName == null ||
serviceName.equals(componentService.getName())) {
- CompositeService compositeService =
(CompositeService)componentService.getService();
- if (compositeService != null) {
- if (serviceName != null) {
- serviceName = "$promoted$." + component.getName()
+ "." + serviceName;
- }
- componentContext =
-
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
- return
componentContext.createSelfReference(businessInterface, compositeService
- .getPromotedService());
- }
- break;
- }
- }
- // No matching service is found
- throw new ServiceRuntimeException("Composite service not found: "
+ name);
- } else {
- componentContext =
((RuntimeComponent)component).getComponentContext();
- if (serviceName != null) {
- return componentContext.createSelfReference(businessInterface,
serviceName);
- } else {
- return componentContext.createSelfReference(businessInterface);
- }
- }
- }
-
-}
-
+/*
+ * 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.sca.binding.sca.axis2;
+
+import java.net.URL;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * The very minimum node implementation to get these tests going without
creating a dependency on
+ * any runtime/hosting implementation
+ *
+ * @version $Rev: 552343 $ $Date: 2007-09-20 14:53:40 +0100 (Thu, 20 Sep 2007)
$
+ */
+public class TestNode {
+
+ private static final Logger logger =
Logger.getLogger(TestNode.class.getName());
+
+ private String nodeName;
+ private ReallySmallRuntime nodeRuntime;
+
+ private ClassLoader cl = TestNode.class.getClassLoader();
+
+ private Composite nodeComposite = null;
+ private Composite appComposite = null;
+
+ public TestNode(String nodeName)
+ throws Exception {
+ this.nodeName = nodeName;
+
+ try {
+
+ // create and start domainA
+ nodeRuntime = new ReallySmallRuntime(cl);
+ nodeRuntime.start();
+
+ // Create an in-memory domain level composite
+ AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
+ nodeComposite = assemblyFactory.createComposite();
+ nodeComposite.setName(new QName(Constants.SCA10_NS, "domain"));
+ nodeComposite.setURI("http://localhost");
+
+ // add the top level composite into the composite activator
+
nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite);
+
+ // add a contribution to the domain
+ ContributionService contributionService =
nodeRuntime.getContributionService();
+
+ // find the current directory as a URL. This is where our
contribution
+ // will come from
+ URL contributionURL =
Thread.currentThread().getContextClassLoader().getResource(nodeName + "/");
+
+ // Contribute the SCA application
+ Contribution contribution =
contributionService.contribute("http://calculator", contributionURL, null,
false);
+ appComposite = contribution.getDeployables().get(0);
+
+ // Add the deployable composite to the domain
+ nodeComposite.getIncludes().add(appComposite);
+ nodeRuntime.buildComposite(appComposite);
+ nodeRuntime.getCompositeActivator().activate(appComposite);
+
+
+ } catch (Exception ex) {
+ System.err.println("Exception when creating node " +
ex.getMessage());
+ ex.printStackTrace(System.err);
+ throw ex;
+ }
+ }
+
+ public void start() {
+
+ try {
+ nodeRuntime.getCompositeActivator().start(appComposite);
+ } catch (Exception ex) {
+ System.err.println("Exception when creating domain " +
ex.getMessage());
+ ex.printStackTrace(System.err);
+ }
+
+ }
+
+ public void stop() {
+ try {
+ nodeRuntime.stop();
+ } catch (Exception ex) {
+ System.err.println("Exception when creating domain " +
ex.getMessage());
+ ex.printStackTrace(System.err);
+ }
+ }
+
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ ServiceReference<B> serviceReference =
getServiceReference(businessInterface, serviceName);
+ if (serviceReference == null) {
+ throw new ServiceRuntimeException("Service not found: " +
serviceName);
+ }
+ return serviceReference.getService();
+ }
+
+ private <B> ServiceReference<B> createServiceReference(Class<B>
businessInterface, String targetURI) {
+ try {
+ AssemblyFactory assemblyFactory = nodeRuntime.getAssemblyFactory();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(Constants.SCA10_TUSCANY_NS,
"default"));
+ RuntimeComponent component =
(RuntimeComponent)assemblyFactory.createComponent();
+ component.setName("default");
+ component.setURI("default");
+
nodeRuntime.getCompositeActivator().configureComponentContext(component);
+ composite.getComponents().add(component);
+ RuntimeComponentReference reference =
(RuntimeComponentReference)assemblyFactory.createComponentReference();
+ reference.setName("default");
+ ModelFactoryExtensionPoint factories =
+
nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
+ JavaInterfaceFactory javaInterfaceFactory =
factories.getFactory(JavaInterfaceFactory.class);
+ InterfaceContract interfaceContract =
javaInterfaceFactory.createJavaInterfaceContract();
+
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
+ reference.setInterfaceContract(interfaceContract);
+ component.getReferences().add(reference);
+ reference.setComponent(component);
+ SCABindingFactory scaBindingFactory =
factories.getFactory(SCABindingFactory.class);
+ SCABinding binding = scaBindingFactory.createSCABinding();
+ binding.setURI(targetURI);
+ reference.getBindings().add(binding);
+ return new ServiceReferenceImpl<B>(businessInterface, component,
reference, binding, nodeRuntime
+ .getProxyFactory(), nodeRuntime.getCompositeActivator());
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B>
businessInterface, String name) {
+
+ // Extract the component name
+ String componentName;
+ String serviceName;
+ int i = name.indexOf('/');
+ if (i != -1) {
+ componentName = name.substring(0, i);
+ serviceName = name.substring(i + 1);
+
+ } else {
+ componentName = name;
+ serviceName = null;
+ }
+
+ // Lookup the component in the domain
+
+ Component component = null;
+
+ for (Composite composite: nodeComposite.getIncludes()) {
+ for (Component componentLoop: composite.getComponents()) {
+ if (componentLoop.getName().equals(componentName)) {
+ component = componentLoop;
+ break;
+ }
+ }
+ }
+ if (component == null) {
+ // The component is not local in the partition, try to create a
remote service ref
+ return createServiceReference(businessInterface, name);
+ }
+ RuntimeComponentContext componentContext = null;
+
+ // If the component is a composite, then we need to find the
+ // non-composite component that provides the requested service
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentService componentService : component.getServices()) {
+ if (serviceName == null ||
serviceName.equals(componentService.getName())) {
+ CompositeService compositeService =
(CompositeService)componentService.getService();
+ if (compositeService != null) {
+ if (serviceName != null) {
+ serviceName = "$promoted$" + component.getName() +
"$slash$" + serviceName;
+ }
+ componentContext =
+
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ return
componentContext.createSelfReference(businessInterface, compositeService
+ .getPromotedService());
+ }
+ break;
+ }
+ }
+ // No matching service is found
+ throw new ServiceRuntimeException("Composite service not found: "
+ name);
+ } else {
+ componentContext =
((RuntimeComponent)component).getComponentContext();
+ if (serviceName != null) {
+ return componentContext.createSelfReference(businessInterface,
serviceName);
+ } else {
+ return componentContext.createSelfReference(businessInterface);
+ }
+ }
+ }
+
+}
+
Modified:
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java
Wed Sep 10 05:45:05 2008
@@ -65,7 +65,7 @@
Definition definition =
wsdlReader.readWSDL("http://localhost:8086/AccountService?wsdl");
assertNotNull(definition);
- Service service = definition.getService(new
QName("http://account2/AccountService/$promoted$.ep1", "AccountService"));
+ Service service = definition.getService(new
QName("http://account2/AccountService/$promoted$ep1", "AccountService"));
Port port = service.getPort("AccountSoapPort");
String endpoint = getEndpoint(port);
Modified:
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java
Wed Sep 10 05:45:05 2008
@@ -65,7 +65,7 @@
Definition definition =
wsdlReader.readWSDL("http://localhost:8085/AccountService?wsdl");
assertNotNull(definition);
- Service service = definition.getService(new
QName("http://accounts/AccountService/$promoted$.ep1", "AccountService"));
+ Service service = definition.getService(new
QName("http://accounts/AccountService/$promoted$ep1", "AccountService"));
Port port = service.getPort("AccountSoapPort");
String endpoint = getEndpoint(port);
Modified:
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java
Wed Sep 10 05:45:05 2008
@@ -65,7 +65,7 @@
Definition definition =
wsdlReader.readWSDL("http://localhost:8085/services/HelloWorldWebService?wsdl");
assertNotNull(definition);
- Service service = definition.getService(new
QName("http://helloworld/HelloWorldService/$promoted$.ep1",
+ Service service = definition.getService(new
QName("http://helloworld/HelloWorldService/$promoted$ep1",
"HelloWorldService"));
Port port = service.getPort("HelloWorldSoapPort");
Modified:
tuscany/branches/sca-java-1.3.2/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
Wed Sep 10 05:45:05 2008
@@ -203,7 +203,7 @@
CompositeService compositeService =
(CompositeService)componentService.getService();
if (compositeService != null) {
if (serviceName != null) {
- serviceName = "$promoted$." + component.getName()
+ "." + serviceName;
+ serviceName = "$promoted$" + component.getName() +
"$slash$" + serviceName;
}
componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
Modified:
tuscany/branches/sca-java-1.3.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.3.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=693821&r1=693820&r2=693821&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.3.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
(original)
+++
tuscany/branches/sca-java-1.3.2/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
Wed Sep 10 05:45:05 2008
@@ -655,7 +655,7 @@
CompositeService compositeService =
(CompositeService)componentService.getService();
if (compositeService != null) {
if (serviceName != null) {
- serviceName = "$promoted$." + component.getName()
+ "." + serviceName;
+ serviceName = "$promoted$" + component.getName() +
"$slash$" + serviceName;
}
componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();