summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-07-03 16:20:01 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-07-03 16:20:01 +0000
commit1b6c96ea79a1fba132c105299cbddf0e2ebc31a7 (patch)
tree96426fbfeedbcdc3e2c020fbd249ae602af29eef /java/sca
parentf64761fcf0c0fa0d5450ea4074329cd0887cae55 (diff)
Start bringing up the client api to the recent proposals
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@790960 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java38
-rw-r--r--java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java63
-rw-r--r--java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java11
3 files changed, 82 insertions, 30 deletions
diff --git a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
index c054179d8a..907330e93b 100644
--- a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
+++ b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
@@ -9,26 +9,22 @@ import org.oasisopen.sca.NoSuchDomainException;
import org.oasisopen.sca.NoSuchServiceException;
/**
- * Client side interface that can be used to lookup SCA Services within a SCA
- * Domain.
- * <p>
- * The SCAClientFactory is used to obtain an implementation instance of the
- * SCAClient.
+ * Client side helper that can be used to lookup SCA Services within a SCA Domain.
*
* @see SCAClientFactory
- * @author OASIS Open
*/
-public interface SCAClient {
+public class SCAClient {
/**
* Returns a reference proxy that implements the business interface <T> of a
* service in a domain
*
- * @param serviceURI the relative URI of the target service. Takes the form
- * componentName/serviceName. Can also take the extended form
- * componentName/serviceName/bindingName to use a specific
- * binding of the target service
- * @param domainURI the URI of an SCA Domain.
+ * @param uri the URI of the target service. Takes the form domainURI/componentName/serviceName.
+ * The domainURI can be left off and defaults to the implementation specific default domain
+ * The service can also take the extended form
+ * domainURI/componentName/serviceName (or /componentName/serviceName).
+ * Can also take the extended form domainURI/componentName/serviceName/bindingName
+ * (or /componentName/serviceName/bindingName) to use a specific binding of the target service
* @param interfaze The business interface class of the service in the
* domain
* @param <T> The business interface class of the service in the domain
@@ -37,5 +33,21 @@ public interface SCAClient {
* @throws NoSuchServiceException Service requested was not found
* @throws NoSuchDomainException Domain requested was not found
*/
- <T> T getService(Class<T> interfaze, String serviceURI, URI domainURI) throws NoSuchServiceException, NoSuchDomainException;
+ public static <T> T getService(Class<T> interfaze, String uri) throws NoSuchServiceException, NoSuchDomainException {
+ URI domainURI = null;
+ String serviceURI;
+ int i = uri.indexOf('/');
+ if (i == -1) {
+ domainURI = null;
+ serviceURI = uri;
+ } else {
+ serviceURI = uri.substring(i+1);
+ if (i > 0) {
+ domainURI = URI.create(uri.substring(0, i));
+ } else {
+ domainURI = null;
+ }
+ }
+ return SCAClientFactory.newInstance(domainURI).getService(interfaze, serviceURI);
+ }
}
diff --git a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
index e2abcf08e4..e96969c99d 100644
--- a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
+++ b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
@@ -4,8 +4,11 @@
*/
package org.oasisopen.sca.client;
+import java.net.URI;
import java.util.Properties;
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
import org.oasisopen.sca.client.impl.SCAClientFactoryFinder;
/**
@@ -17,8 +20,29 @@ import org.oasisopen.sca.client.impl.SCAClientFactoryFinder;
* @author OASIS Open
*/
public abstract class SCAClientFactory {
+
+ private URI domainURI;
+
+ private SCAClientFactory() {
+ }
+
+ /**
+ * Constructor used by concrete subclasses
+ * @param domainURI - The Domain URI of the Domain accessed via this SCAClientFactory
+ */
+ protected SCAClientFactory(URI domainURI) {
+ this.domainURI = domainURI;
+ }
/**
+ * Gets the Domain URI of the Domain accessed via this SCAClientFactory
+ * @return - the URI for the Domain
+ */
+ protected URI getDomainURI() {
+ return domainURI;
+ }
+
+ /**
* The default implementation of the SCAClientFactory. A Vendor may use
* reflection to inject a default SCAClientFactory instance that will be
* used in the newInstance() methods rather than using the
@@ -32,8 +56,8 @@ public abstract class SCAClientFactory {
*
* @return A new SCAClient
*/
- public static SCAClient newInstance() {
- return newInstance(null, null);
+ public static SCAClientFactory newInstance(URI domainURI) throws NoSuchDomainException {
+ return newInstance(null, null, domainURI);
}
/**
@@ -44,8 +68,8 @@ public abstract class SCAClientFactory {
* instance of the SCAClient
* @return A new SCAClient instance
*/
- public static SCAClient newInstance(Properties properties) {
- return newInstance(properties, null);
+ public static SCAClientFactory newInstance(Properties properties, URI domainURI) {
+ return newInstance(properties, null, domainURI);
}
/**
@@ -56,8 +80,8 @@ public abstract class SCAClientFactory {
* instance of the SCAClient
* @return A new SCAClient instance
*/
- public static SCAClient newInstance(ClassLoader classLoader) {
- return newInstance(null, classLoader);
+ public static SCAClientFactory newInstance(ClassLoader classLoader, URI domainURI) {
+ return newInstance(null, classLoader, domainURI);
}
/**
@@ -70,20 +94,33 @@ public abstract class SCAClientFactory {
* instance of the SCAClient
* @return A new SCAClient instance
*/
- public static SCAClient newInstance(Properties properties, ClassLoader classLoader) {
+ public static SCAClientFactory newInstance(Properties properties, ClassLoader classLoader, URI domainURI) {
final SCAClientFactory factory;
if (defaultFactory == null) {
- factory = SCAClientFactoryFinder.find(properties, classLoader);
+ factory = SCAClientFactoryFinder.find(properties, classLoader, domainURI);
} else {
factory = defaultFactory;
}
- return factory.createSCAClient();
+ return factory;
}
/**
- * This method is invoked to create a new SCAClient instance.
- *
- * @return A new SCAClient instance
+ * Returns a reference proxy that implements the business interface <T>
+ * of a service in the SCA Domain handled by this SCAClientFactory
+ *
+ * @param serviceURI the relative URI of the target service. Takes the
+ * form componentName/serviceName.
+ * Can also take the extended form componentName/serviceName/bindingName
+ * to use a specific binding of the target service
+ *
+ * @param interfaze The business interface class of the service in the
+ * domain
+ * @param <T> The business interface class of the service in the domain
+ *
+ * @return a proxy to the target service, in the specified SCA Domain
+ * that implements the business interface <B>.
+ * @throws NoSuchServiceException Service requested was not found
+ * @throws NoSuchDomainException Domain requested was not found
*/
- protected abstract SCAClient createSCAClient();
+ public abstract <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException, NoSuchDomainException;
}
diff --git a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
index c13e4e9142..5137f8a658 100644
--- a/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
+++ b/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
@@ -9,6 +9,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URI;
import java.net.URL;
import java.util.Properties;
@@ -55,7 +56,7 @@ public class SCAClientFactoryFinder {
* @throws SCARuntimeException Failed to create SCAClientFactory
* implementation.
*/
- public static SCAClientFactory find(Properties properties, ClassLoader classLoader) {
+ public static SCAClientFactory find(Properties properties, ClassLoader classLoader, URI domainURI) {
if (classLoader == null) {
classLoader = getThreadContextClassLoader();
if (classLoader == null) {
@@ -64,7 +65,7 @@ public class SCAClientFactoryFinder {
}
final String factoryImplClassName = discoverProviderFactoryImplClass(properties, classLoader);
final Class<? extends SCAClientFactory> factoryImplClass = loadProviderFactoryClass(factoryImplClassName, classLoader);
- final SCAClientFactory factory = instantiateSCAClientFactoryClass(factoryImplClass);
+ final SCAClientFactory factory = instantiateSCAClientFactoryClass(factoryImplClass, domainURI);
return factory;
}
@@ -207,16 +208,18 @@ public class SCAClientFactoryFinder {
*
* @param factoryImplClass The SCAClientFactory implementation class to
* instantiate.
+ * @param domainURI
* @return An instance of the SCAClientFactory implementation class
* @throws SCARuntimeException Failed to instantiate the specified specified
* SCAClientFactory implementation class
*/
- private static SCAClientFactory instantiateSCAClientFactoryClass(Class<? extends SCAClientFactory> factoryImplClass) throws SCARuntimeException {
+ private static SCAClientFactory instantiateSCAClientFactoryClass(Class<? extends SCAClientFactory> factoryImplClass, URI domainURI) throws SCARuntimeException {
try {
- final SCAClientFactory provider = factoryImplClass.newInstance();
+ final SCAClientFactory provider = factoryImplClass.getConstructor(URI.class).newInstance(domainURI);
return provider;
} catch (Throwable ex) {
+ ex.printStackTrace();
throw new SCARuntimeException("Failed to instantiate SCAClientFactory implementation class " + factoryImplClass, ex);
}
}