Author: antelder
Date: Tue Jan 31 16:36:01 2012
New Revision: 1238685
URL: http://svn.apache.org/viewvc?rev=1238685&view=rev
Log:
Update to make plugable whether or not the client should use bindings other
than SCA binding
Added:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
Modified:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
Added:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java?rev=1238685&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java
Tue Jan 31 16:36:01 2012
@@ -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);
+ }
+}
Added:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java?rev=1238685&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/EndpointFinder.java
Tue Jan 31 16:36:01 2012
@@ -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;
+}
Added:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java?rev=1238685&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/OnlySCABindingEndpointFinder.java
Tue Jan 31 16:36:01 2012
@@ -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;
+ }
+
+}
Modified:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java?rev=1238685&r1=1238684&r2=1238685&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java
Tue Jan 31 16:36:01 2012
@@ -132,7 +132,8 @@ public class RemoteServiceInvocationHand
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 {
Modified:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java?rev=1238685&r1=1238684&r2=1238685&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
Tue Jan 31 16:36:01 2012
@@ -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;
}
}
Modified:
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java?rev=1238685&r1=1238684&r2=1238685&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java
Tue Jan 31 16:36:01 2012
@@ -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 extend
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 extend
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 extend
// 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 extend
return (T)Proxy.newProxyInstance(cl, new Class[]{serviceInterface},
handler);
}
+
}