summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/sca-client-impl
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-01-31 16:36:01 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-01-31 16:36:01 +0000
commitb891ba6824e932c01e6103446dc87346b780c02d (patch)
tree80eb90f5096ce5241ca4a5d245da060727d06c15 /sca-java-2.x/trunk/modules/sca-client-impl
parent8434e69c00ea11444c85479af5534cd052df3cd7 (diff)
Update to make plugable whether or not the client should use bindings other than SCA binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1238685 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-client-impl')
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java54
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java28
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java28
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java3
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java25
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java12
6 files changed, 127 insertions, 23 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
new file mode 100644
index 0000000000..d4ac2e486b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
@@ -0,0 +1,54 @@
+/*
+ * 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.client.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.runtime.DomainRegistry;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public class DefaultEndpointFinder implements EndpointFinder {
+
+ protected boolean onlySCABinding;
+
+ @Override
+ public Endpoint findEndpoint(DomainRegistry domainRegistry, String serviceName) throws NoSuchServiceException {
+ List<Endpoint> eps = domainRegistry.findEndpoint(serviceName);
+ if (eps == null || eps.size() < 1) {
+ throw new NoSuchServiceException(serviceName);
+ }
+
+ // If there is an Endpoint using the SCA binding use that
+ for (Endpoint ep : eps) {
+ if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
+ return ep;
+ }
+ }
+
+ if (onlySCABinding) {
+ throw new NoSuchServiceException(serviceName + " not found using binding.sca");
+ }
+
+ // Otherwise just choose the first one
+ return eps.get(0);
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
new file mode 100644
index 0000000000..881cb86230
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
@@ -0,0 +1,28 @@
+/*
+ * 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.client.impl;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.runtime.DomainRegistry;
+import org.oasisopen.sca.NoSuchServiceException;
+
+public interface EndpointFinder {
+ public Endpoint findEndpoint(DomainRegistry domainRegistry, String serviceName) throws NoSuchServiceException;
+}
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
new file mode 100644
index 0000000000..5f818c4799
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
@@ -0,0 +1,28 @@
+/*
+ * 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.client.impl;
+
+public class OnlySCABindingEndpointFinder extends DefaultEndpointFinder {
+
+ public OnlySCABindingEndpointFinder() {
+ this.onlySCABinding = true;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
index 5806101560..004433ad73 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
@@ -132,7 +132,8 @@ public class RemoteServiceInvocationHandler implements InvocationHandler {
CompositeContext compositeContext = new CompositeContext(extensionsRegistry, domainRegistry, null, domainURI, null, null);
- Endpoint endpoint = RuntimeUtils.findEndpoint(domainRegistry, serviceName);
+ EndpointFinder endpointFinder = RuntimeUtils.getEndpointFinder(extensionsRegistry);
+ Endpoint endpoint = endpointFinder.findEndpoint(domainRegistry, serviceName);
if (serviceInterface == null) {
try {
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
index 0a9f7cdebd..bb84d93b11 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
@@ -19,24 +19,20 @@
package org.apache.tuscany.sca.client.impl;
-import java.util.List;
import java.util.Properties;
-import org.apache.tuscany.sca.assembly.Endpoint;
-import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
-import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
import org.apache.tuscany.sca.runtime.DomainRegistry;
+import org.apache.tuscany.sca.runtime.DomainRegistryFactory;
import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
import org.apache.tuscany.sca.runtime.RuntimeProperties;
import org.apache.tuscany.sca.work.WorkScheduler;
import org.oasisopen.sca.NoSuchDomainException;
-import org.oasisopen.sca.NoSuchServiceException;
public class RuntimeUtils {
@@ -87,20 +83,11 @@ public class RuntimeUtils {
}
}
- public static Endpoint findEndpoint(DomainRegistry domainRegistry, String serviceName) throws NoSuchServiceException {
- List<Endpoint> eps = domainRegistry.findEndpoint(serviceName);
- if (eps == null || eps.size() < 1) {
- throw new NoSuchServiceException(serviceName);
+ public static EndpointFinder getEndpointFinder(ExtensionPointRegistry registry) {
+ EndpointFinder endpointFinder = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointFinder.class);
+ if (endpointFinder == null) {
+ endpointFinder = new DefaultEndpointFinder();
}
-
- // If there is an Endpoint using the SCA binding use that
- for (Endpoint ep : eps) {
- if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
- return ep;
- }
- }
-
- // Otherwise just choose the first one
- return eps.get(0);
+ return endpointFinder;
}
}
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
index 8671a0e42d..5354fd9e74 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
@@ -28,6 +28,7 @@ import java.security.PrivilegedAction;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistryLocator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.runtime.DomainRegistry;
import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -41,6 +42,8 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
protected ExtensionPointRegistry extensionPointRegistry;
protected DomainRegistry domainRegistry;
protected boolean remoteClient;
+ protected boolean onlySCABinding;
+ private EndpointFinder endpointFinder;
public static URI default_domainURI = URI.create("default");
@@ -55,8 +58,10 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
public SCAClientFactoryImpl(URI domainURI) throws NoSuchDomainException {
super(domainURI == null ? default_domainURI : domainURI);
findLocalRuntime();
- }
-
+
+ endpointFinder = RuntimeUtils.getEndpointFinder(extensionPointRegistry);
+ }
+
protected void findLocalRuntime() throws NoSuchDomainException {
String domainURI = getDomainURI().toString();
for (ExtensionPointRegistry xpr : ExtensionPointRegistryLocator.getExtensionPointRegistries()) {
@@ -88,7 +93,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
// The service is a component in a local runtime
if (!remoteClient) {
- Endpoint ep = RuntimeUtils.findEndpoint(domainRegistry, serviceURI);
+ Endpoint ep = endpointFinder.findEndpoint(domainRegistry, serviceURI);
if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) {
return ((RuntimeComponent)ep.getComponent()).getServiceReference(serviceInterface, serviceName).getService();
}
@@ -121,4 +126,5 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
return (T)Proxy.newProxyInstance(cl, new Class[]{serviceInterface}, handler);
}
+
}