Author: antelder
Date: Fri Jul  3 16:20:01 2009
New Revision: 790960

URL: http://svn.apache.org/viewvc?rev=790960&view=rev
Log:
Start bringing up the client api to the recent proposals

Modified:
    
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
    
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
    
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java

Modified: 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java?rev=790960&r1=790959&r2=790960&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
 (original)
+++ 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClient.java
 Fri Jul  3 16:20:01 2009
@@ -9,26 +9,22 @@
 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 @@
      * @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);       
+    }
 }

Modified: 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java?rev=790960&r1=790959&r2=790960&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
 (original)
+++ 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java
 Fri Jul  3 16:20:01 2009
@@ -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 @@
  * @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 @@
      * 
      * @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 @@
      *                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 @@
      *                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 @@
      *                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;
 }

Modified: 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java?rev=790960&r1=790959&r2=790960&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
 (original)
+++ 
tuscany/java/sca/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java
 Fri Jul  3 16:20:01 2009
@@ -9,6 +9,7 @@
 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 @@
      * @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 @@
         }
         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 @@
      * 
      * @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);
         }
     }


Reply via email to