tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1102004 - in /tuscany/sca-java-2.x/trunk/modules/node-impl: META-INF/MANIFEST.MF src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
Date Wed, 11 May 2011 18:05:03 GMT
Author: rfeng
Date: Wed May 11 18:05:03 2011
New Revision: 1102004

URL: http://svn.apache.org/viewvc?rev=1102004&view=rev
Log:
Allows the lookup of services by interface (service name == null) from a node

Modified:
    tuscany/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF
    tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
    tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF?rev=1102004&r1=1102003&r2=1102004&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/META-INF/MANIFEST.MF Wed May 11 18:05:03
2011
@@ -26,6 +26,8 @@ Import-Package: javax.management;resolut
  org.apache.tuscany.sca.definitions.xml;version="2.0.0",
  org.apache.tuscany.sca.deployment;version="2.0.0",
  org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
  org.apache.tuscany.sca.management;version="2.0.0",
  org.apache.tuscany.sca.monitor;version="2.0.0",
  org.apache.tuscany.sca.node;version="2.0.0",

Modified: tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=1102004&r1=1102003&r2=1102004&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
Wed May 11 18:05:03 2011
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
 import javax.xml.stream.XMLOutputFactory;
 
 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.Endpoint;
 import org.apache.tuscany.sca.assembly.Service;
@@ -41,6 +42,8 @@ import org.apache.tuscany.sca.core.Exten
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.monitor.Monitor;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
@@ -261,22 +264,36 @@ public class NodeImpl implements Node, N
     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;
+        String componentName = null;
+        String serviceName = null;
+        if (name != null) {
+            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
         Component component = null;
 
         for (Component compositeComponent : domainComposite.getComponents()) {
+            if (componentName == null) {
+                for (ComponentService service : compositeComponent.getServices()) {
+                    Interface intf = service.getInterfaceContract().getInterface();
+                    if (intf instanceof JavaInterface) {
+                        JavaInterface ji = (JavaInterface)intf;
+                        if (ji.getJavaClass() == businessInterface) {
+                            return ((RuntimeComponent)compositeComponent).getComponentContext()
+                                .createSelfReference(businessInterface, service);
+                        }
+                    }
+                }
+            }
             if (compositeComponent.getName().equals(componentName)) {
                 component = compositeComponent;
                 break;

Modified: tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java?rev=1102004&r1=1102003&r2=1102004&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
Wed May 11 18:05:03 2011
@@ -116,6 +116,8 @@ public class NodeImplTestCase {
         node.start();
         HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld");
         Assert.assertEquals("Hello, Node", hw.hello("Node"));
+        hw = node.getService(HelloWorld.class, null);
+        Assert.assertEquals("Hello, Node", hw.hello("Node"));
         String address = node.getEndpointAddress("HelloWorld");
         Assert.assertNotNull(address);
         address = node.getEndpointAddress("HelloWorld/HelloWorld");
@@ -123,7 +125,7 @@ public class NodeImplTestCase {
         address = node.getEndpointAddress("HelloWorld/HelloWorld/HelloWorld");
         Assert.assertNotNull(address);
         address = node.getEndpointAddress("HelloWorld/HelloWorld1");
-        Assert.assertNull(address);        
+        Assert.assertNull(address);      
         node.stop();
     }
 



Mime
View raw message