diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-16 07:57:59 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-16 07:57:59 +0000 |
commit | a4187b8f961397e1591aa870b1b948869226936e (patch) | |
tree | 9bfae86dfe24ab0e7d07dab59e5fcf0b40b0271c /sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany | |
parent | a12ba1c79bc32a37b554b37df92df629484ae600 (diff) |
Add a matches method to Endpoint to find servic uris that match the endpoint uri
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@923614 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany')
2 files changed, 74 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java index df4aaf3b98..c43d775945 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java @@ -128,4 +128,11 @@ public interface Endpoint extends Base, PolicySubject, Cloneable, Serializable { */ Object clone() throws CloneNotSupportedException; + /** + * Tests if the URI of this endpoint matches the service URI + * @param serviceName the service URI to test + * @return true if the endpoint URI matches the service URI + */ + boolean matches(String serviceURI); + } diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java index d518230a92..26663528f7 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java @@ -203,4 +203,71 @@ public class EndpointImpl implements Endpoint { public void setRemote(boolean remote) { this.remote = remote; } + + public boolean matches(String serviceURI) { + String[] parts1 = parseServiceURI(serviceURI); + String[] parts2 = parseStructuralURI(getURI()); + for (int i = 0; i < parts1.length; i++) { + if (parts1[i] == null || parts1[i].equals(parts2[i])) { + continue; + } else { + return false; + } + } + return true; + } + + /** + * Parse the service URI into an array of names. The service URI is in one of the following formats: + * <ul> + * <li>componentName + * <li>componentName/serviceName + * <li>componentName/serviceName/bindingName + * </ul> + * @param serviceURI + * @return + */ + private static String[] parseServiceURI(String serviceURI) { + if (serviceURI.contains("#")) { + return parseStructuralURI(serviceURI); + } + String[] names = new String[3]; + String[] segments = serviceURI.split("/"); + for (int i = 0; i < names.length && i < segments.length; i++) { + names[i] = segments[i]; + } + return names; + } + + /** + * Parse the structural URI into an array of parts (componentURI, serviceName, bindingName) + * @param structuralURI + * @return [0]: componentURI [1]: serviceName [2]: bindingName + */ + private static String[] parseStructuralURI(String structuralURI) { + String[] names = new String[3]; + int index = structuralURI.lastIndexOf('#'); + if (index == -1) { + names[0] = structuralURI; + } else { + names[0] = structuralURI.substring(0, index); + String str = structuralURI.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: " + structuralURI); + } + 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 structural URI: " + structuralURI); + } + } + return names; + } + } |