summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/endpoint
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/endpoint')
-rw-r--r--java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java60
-rw-r--r--java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry8
2 files changed, 53 insertions, 15 deletions
diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
index 83522f4599..c57fc579c8 100644
--- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
+++ b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointRegistryImpl.java
@@ -54,6 +54,50 @@ public class EndpointRegistryImpl implements EndpointRegistry {
logger.info("EndpointRegistry: Add endpoint reference - " + endpointReference.toString());
}
+ /**
+ * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName)
+ * @param uri
+ * @return
+ */
+ private String[] parse(String uri) {
+ String[] names = new String[3];
+ int index = uri.lastIndexOf('#');
+ if (index == -1) {
+ names[0] = uri;
+ } else {
+ names[0] = uri.substring(0, index);
+ String str = uri.substring(index + 1);
+ if (str.startsWith("service-binding(") && str.endsWith(")")) {
+ str = str.substring("service-binding(".length(), str.length() - 1);
+ String[] parts = str.split("/");
+ if (parts.length != 2) {
+ throw new IllegalArgumentException("Invalid service-binding URI: " + uri);
+ }
+ names[1] = parts[0];
+ names[2] = parts[1];
+ } else if (str.startsWith("service(") && str.endsWith(")")) {
+ str = str.substring("service(".length(), str.length() - 1);
+ names[1] = str;
+ } else {
+ throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri);
+ }
+ }
+ return names;
+ }
+
+ private boolean matches(String target, String uri) {
+ String[] parts1 = parse(target);
+ String[] parts2 = parse(uri);
+ for (int i = 0; i < parts1.length; i++) {
+ if (parts1[i] == null || parts1[i].equals(parts2[i])) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
public List<Endpoint2> findEndpoint(EndpointReference2 endpointReference) {
List<Endpoint2> foundEndpoints = new ArrayList<Endpoint2>();
@@ -63,20 +107,14 @@ public class EndpointRegistryImpl implements EndpointRegistry {
Endpoint2 targetEndpoint = endpointReference.getTargetEndpoint();
for (Endpoint2 endpoint : endpoints) {
// TODO: implement more complete matching
- if (endpoint.getComponentName().equals(targetEndpoint.getComponentName())) {
- if ((targetEndpoint.getServiceName() != null) && (endpoint.getServiceName().equals(targetEndpoint
- .getServiceName()))) {
- foundEndpoints.add(endpoint);
- logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint.toString());
- } else if (targetEndpoint.getServiceName() == null) {
- foundEndpoints.add(endpoint);
- logger.info("EndpointRegistry: Found endpoint with matching component - " + endpoint
- .toString());
- }
- // else the service name doesn't match
+ if (matches(targetEndpoint.getURI(), endpoint.getURI())) {
+ foundEndpoints.add(endpoint);
+ logger.info("EndpointRegistry: Found endpoint with matching service - " + endpoint);
}
+ // else the service name doesn't match
}
}
+
return foundEndpoints;
}
diff --git a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
index 26ee8ce362..75a909199e 100644
--- a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
+++ b/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry
@@ -5,14 +5,14 @@
# 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.
+# under the License.
-org.apache.tuscany.sca.endpoint.impl.EndpointRegistryImpl \ No newline at end of file
+org.apache.tuscany.sca.endpoint.impl.EndpointRegistryImpl;ranking=100 \ No newline at end of file