diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-20 11:02:48 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-20 11:02:48 +0000 |
commit | d93f0ae0212dc48000fbe6145b07e497d7062a6c (patch) | |
tree | 5a11619af0dafa88ac533383df4b607290d2da4c /sca-java-2.x/trunk/modules | |
parent | c4ba5b60d5b730e44405dc7e9b795d8b789cd825 (diff) |
Update the client api classes to be the very latest from the oasis svn
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@901126 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
4 files changed, 409 insertions, 305 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java index e96969c99d..cb9fb1b34b 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java @@ -1,6 +1,6 @@ -/* - * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. - * OASIS trademark, IPR and other policies apply. +/* + * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. + * OASIS trademark, IPR and other policies apply. */ package org.oasisopen.sca.client; @@ -9,28 +9,49 @@ import java.util.Properties; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; -import org.oasisopen.sca.client.impl.SCAClientFactoryFinder; +import org.oasisopen.sca.client.SCAClientFactoryFinder; +import org.oasisopen.sca.client.impl.SCAClientFactoryFinderImpl; /** - * The SCAClientFactory can be used by non-SCA managed code to lookup services - * that exist in a SCADomain. + * The SCAClientFactory can be used by non-SCA managed code to + * lookup services that exist in a SCADomain. + * + * @see SCAClientFactoryFinderImpl * - * @see SCAClientFactoryFinder - * @see SCAClient * @author OASIS Open */ + public abstract class SCAClientFactory { - + + /** + * The SCAClientFactoryFinder. + * Provides a means by which a provider of an SCAClientFactory + * implementation can inject a factory finder implementation into + * the abstract SCAClientFactory class - once this is done, future + * invocations of the SCAClientFactory use the injected factory + * finder to locate and return an instance of a subclass of + * SCAClientFactory. + */ + protected static SCAClientFactoryFinder factoryFinder; + /** + * The Domain URI of the SCA Domain which is accessed by this + * SCAClientFactory + */ private URI domainURI; + /** + * Prevent concrete subclasses from using the no-arg constructor + */ private SCAClientFactory() { } /** * Constructor used by concrete subclasses - * @param domainURI - The Domain URI of the Domain accessed via this SCAClientFactory + * @param domainURI - The Domain URI of the Domain accessed via this + * SCAClientFactory */ - protected SCAClientFactory(URI domainURI) { + protected SCAClientFactory(URI domainURI) + throws NoSuchDomainException { this.domainURI = domainURI; } @@ -41,69 +62,73 @@ public abstract class SCAClientFactory { 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 - * SCAClientFactoryFinder. - */ - protected static SCAClientFactory defaultFactory; - - /** - * Creates a new instance of the SCAClient that can be used to lookup SCA - * Services. + * Creates a new instance of the SCAClientFactory that can be + * used to lookup SCA Services. * - * @return A new SCAClient + * @param domainURI URI of the target domain for the SCAClientFactory + * @return A new SCAClientFactory */ - public static SCAClientFactory newInstance(URI domainURI) throws NoSuchDomainException { + public static SCAClientFactory newInstance( URI domainURI ) + throws NoSuchDomainException { return newInstance(null, null, domainURI); } - + /** - * Creates a new instance of the SCAClient that can be used to lookup SCA - * Services. - * - * @param properties Properties that may be used when creating a new - * instance of the SCAClient - * @return A new SCAClient instance + * Creates a new instance of the SCAClientFactory that can be + * used to lookup SCA Services. + * + * @param properties Properties that may be used when + * creating a new instance of the SCAClientFactory + * @param domainURI URI of the target domain for the SCAClientFactory + * @return A new SCAClientFactory instance */ - public static SCAClientFactory newInstance(Properties properties, URI domainURI) { + public static SCAClientFactory newInstance(Properties properties, + URI domainURI) + throws NoSuchDomainException { return newInstance(properties, null, domainURI); } /** - * Creates a new instance of the SCAClient that can be used to lookup SCA - * Services. - * - * @param classLoader ClassLoader that may be used when creating a new - * instance of the SCAClient - * @return A new SCAClient instance + * Creates a new instance of the SCAClientFactory that can be + * used to lookup SCA Services. + * + * @param classLoader ClassLoader that may be used when + * creating a new instance of the SCAClientFactory + * @param domainURI URI of the target domain for the SCAClientFactory + * @return A new SCAClientFactory instance */ - public static SCAClientFactory newInstance(ClassLoader classLoader, URI domainURI) { + public static SCAClientFactory newInstance(ClassLoader classLoader, + URI domainURI) + throws NoSuchDomainException { return newInstance(null, classLoader, domainURI); } /** - * Creates a new instance of the SCAClient that can be used to lookup SCA - * Services. - * - * @param properties Properties that may be used when creating a new - * instance of the SCAClient - * @param classLoader ClassLoader that may be used when creating a new - * instance of the SCAClient - * @return A new SCAClient instance + * Creates a new instance of the SCAClientFactory that can be + * used to lookup SCA Services. + * + * @param properties Properties that may be used when + * creating a new instance of the SCAClientFactory + * @param classLoader ClassLoader that may be used when + * creating a new instance of the SCAClientFactory + * @param domainURI URI of the target domain for the SCAClientFactory + * @return A new SCAClientFactory instance */ - public static SCAClientFactory newInstance(Properties properties, ClassLoader classLoader, URI domainURI) { - final SCAClientFactory factory; - if (defaultFactory == null) { - factory = SCAClientFactoryFinder.find(properties, classLoader, domainURI); - } else { - factory = defaultFactory; - } + public static SCAClientFactory newInstance(Properties properties, + ClassLoader classLoader, + URI domainURI) + throws NoSuchDomainException { + final SCAClientFactoryFinder finder = + factoryFinder != null ? factoryFinder : + new SCAClientFactoryFinderImpl(); + final SCAClientFactory factory + = finder.find(properties, classLoader, domainURI); return factory; } - + /** * Returns a reference proxy that implements the business interface <T> * of a service in the SCA Domain handled by this SCAClientFactory @@ -112,15 +137,16 @@ public abstract class SCAClientFactory { * 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 + * + * @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 + * @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 */ - public abstract <T> T getService(Class<T> interfaze, String serviceURI) throws NoSuchServiceException, NoSuchDomainException; + public abstract <T> T getService(Class<T> interfaze, String serviceURI) + throws NoSuchServiceException, NoSuchDomainException; } diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java new file mode 100644 index 0000000000..d9cd780424 --- /dev/null +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java @@ -0,0 +1,35 @@ +/*
+ * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+
+package org.oasisopen.sca.client;
+
+import java.net.URI;
+import java.util.Properties;
+
+import org.oasisopen.sca.NoSuchDomainException;
+
+/* A Service Provider Interface representing a SCAClientFactory finder.
+ * SCA provides a default reference implementation of this interface.
+ * SCA runtime vendors can create alternative implementations of this
+ * interface that use different class loading or lookup mechanisms.
+ */
+public interface SCAClientFactoryFinder {
+
+ /**
+ * Method for finding the SCAClientFactory for a given Domain URI using
+ * a specified set of properties and a a specified ClassLoader
+ * @param properties - properties to use - may be null
+ * @param classLoader - ClassLoader to use - may be null
+ * @param domainURI - the Domain URI - must be a valid SCA Domain URI
+ * @return - the SCAClientFactory or null if the factory could not be
+ * @throws - NoSuchDomainException if the domainURI does not reference
+ * a valid SCA Domain
+ * found
+ */
+ SCAClientFactory find(Properties properties,
+ ClassLoader classLoader,
+ URI domainURI )
+ throws NoSuchDomainException ;
+}
diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java deleted file mode 100644 index 4bbb769142..0000000000 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinder.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. - * OASIS trademark, IPR and other policies apply. - */ -package org.oasisopen.sca.client.impl; - -import java.io.BufferedReader; -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; - -import org.oasisopen.sca.SCARuntimeException; -import org.oasisopen.sca.client.SCAClientFactory; - -/** - * This is a default class that returns an SCAClientFactory implementation - - * this class can be replaced by a vendor implementation. - * - * @see SCAClientFactory - * @author OASIS Open - */ -public class SCAClientFactoryFinder { - - /** - * The name of the System Property used to determine the SPI implementation - * to use for the SCAClientFactory. - */ - private static final String SCA_CLIENT_FACTORY_PROVIDER_KEY = SCAClientFactory.class.getName(); - - /** - * The name of the file loaded from the ClassPath to determine the SPI - * implementation to use for the SCAClientFactory. - */ - private static final String SCA_CLIENT_FACTORY_PROVIDER_META_INF_SERVICE = "META-INF/services/" + SCA_CLIENT_FACTORY_PROVIDER_KEY; - - /** - * Private Constructor. - */ - private SCAClientFactoryFinder() { - } - - /** - * Creates an instance of the SCAClientFactory implementation. This - * discovers the SCAClientFactory implementation and instantiates the - * provider's implementation. - * - * @param properties Properties that may be used when creating a new - * instance of the SCAClient - * @param classLoader ClassLoader that may be used when creating a new - * instance of the SCAClient - * @return new instance of the SCAClientFactory - * @throws SCARuntimeException Failed to create SCAClientFactory - * implementation. - */ - public static SCAClientFactory find(Properties properties, ClassLoader classLoader, URI domainURI) { - // TODO - TUSCANY-3424 - swap the order here temporarily to help with the - // fixes to the client factory lookup processing - // will revert when TUSCANY-3424 is done - if (classLoader == null) { - // classLoader = getThreadContextClassLoader(); - classLoader = SCAClientFactoryFinder.class.getClassLoader(); - if (classLoader == null) { - //classLoader = SCAClientFactoryFinder.class.getClassLoader(); - classLoader = getThreadContextClassLoader(); - } - } - final String factoryImplClassName = discoverProviderFactoryImplClass(properties, classLoader); - final Class<? extends SCAClientFactory> factoryImplClass = loadProviderFactoryClass(factoryImplClassName, classLoader); - final SCAClientFactory factory = instantiateSCAClientFactoryClass(factoryImplClass, domainURI); - return factory; - } - - /** - * Gets the Context ClassLoader for the current Thread. - * - * @return The Context ClassLoader for the current Thread. - */ - private static ClassLoader getThreadContextClassLoader() { - final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader(); - return threadClassLoader; - } - - /** - * Attempts to discover the class name for the SCAClientFactory - * implementation from the specified Properties, the System Properties or - * the specified ClassLoader. - * - * @return The class name of the SCAClientFactory implementation - * @throw SCARuntimeException Failed to find implementation for - * SCAClientFactory. - */ - private static String discoverProviderFactoryImplClass(Properties properties, ClassLoader classLoader) throws SCARuntimeException { - String providerClassName = checkPropertiesForSPIClassName(properties); - if (providerClassName != null) { - return providerClassName; - } - - providerClassName = checkPropertiesForSPIClassName(System.getProperties()); - if (providerClassName != null) { - return providerClassName; - } - - return checkMETAINFServicesForClassName(classLoader); - } - - /** - * Attempts to find the class name for the SCAClientFactory implementation - * from the specified Properties. - * - * @return The class name for the SCAClientFactory implementation or - * <code>null</code> if not found. - */ - private static String checkPropertiesForSPIClassName(Properties properties) { - if (properties == null) { - return null; - } - - final String providerClassName = properties.getProperty(SCA_CLIENT_FACTORY_PROVIDER_KEY); - if (providerClassName != null && providerClassName.length() > 0) { - return providerClassName; - } - - return null; - } - - /** - * Attempts to find the class name for the SCAClientFactory implementation - * from the META-INF/services directory - * - * @return The class name for the SCAClientFactory implementation or - * <code>null</code> if not found. - */ - private static String checkMETAINFServicesForClassName(ClassLoader cl) { - final URL url = cl.getResource(SCA_CLIENT_FACTORY_PROVIDER_META_INF_SERVICE); - if (url == null) { - return null; - } - - InputStream in = null; - try { - in = url.openStream(); - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); - - String line; - while ((line = readNextLine(reader)) != null) { - if (!line.startsWith("#") && line.length() > 0) { - return line; - } - } - return null; - } finally { - closeStream(reader); - } - } catch (IOException ex) { - throw new SCARuntimeException("Failed to discover SCAClientFactory provider", ex); - } finally { - closeStream(in); - } - } - - /** - * Reads the next line from the reader and returns the trimmed version of - * that line - * - * @param reader The reader from which to read the next line - * @return The trimmed next line or <code>null</code> if the end of the - * stream has been reached - * @throws IOException I/O error occurred while reading from Reader - */ - private static String readNextLine(BufferedReader reader) throws IOException { - - String line = reader.readLine(); - if (line != null) { - line = line.trim(); - } - return line; - } - - /** - * Loads the specified SCAClientFactory implementation class. - * - * @param factoryImplClassName The name of the SCAClientFactory - * Implementation class to load - * @return The specified SCAClientFactory Implementation class - * @throws SCARuntimeException Failed to load the SCAClientFactory - * implementation class - */ - private static Class<? extends SCAClientFactory> loadProviderFactoryClass(String factoryImplClassName, ClassLoader classLoader) - throws SCARuntimeException { - - try { - final Class<?> providerClass = classLoader.loadClass(factoryImplClassName); - final Class<? extends SCAClientFactory> providerFactoryClass = providerClass.asSubclass(SCAClientFactory.class); - return providerFactoryClass; - } catch (ClassNotFoundException ex) { - throw new SCARuntimeException("Failed to load SCAClientFactory implementation class " + factoryImplClassName, ex); - } catch (ClassCastException ex) { - throw new SCARuntimeException("Loaded SCAClientFactory implementation class " + factoryImplClassName - + " is not a subclass of " - + SCAClientFactory.class.getName(), ex); - } - } - - /** - * Instantiate an instance of the specified SCAClientFactory implementation - * class. - * - * @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, URI domainURI) throws SCARuntimeException { - - try { - 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); - } - } - - /** - * Utility method for closing Closeable Object. - * - * @param closeable The Object to close. - */ - private static void closeStream(Closeable closeable) { - if (closeable != null) { - try { - closeable.close(); - } catch (IOException ex) { - throw new SCARuntimeException("Failed to close stream", ex); - } - } - } -} diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java new file mode 100644 index 0000000000..9c5eea601b --- /dev/null +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java @@ -0,0 +1,289 @@ +/*
+ * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+package org.oasisopen.sca.client.impl;
+
+import org.oasisopen.sca.client.SCAClientFactoryFinder;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.net.URL;
+import java.util.Properties;
+
+import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.oasisopen.sca.client.SCAClientFactory;
+
+/**
+ * This is a default implementation of an SCAClientFactoryFinder which is
+ * used to find an implementation of the SCAClientFactory interface.
+ *
+ * @see SCAClientFactoryFinder
+ * @see SCAClientFactory
+ *
+ * @author OASIS Open
+ */
+public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder {
+
+ /**
+ * The name of the System Property used to determine the SPI
+ * implementation to use for the SCAClientFactory.
+ */
+ private static final String SCA_CLIENT_FACTORY_PROVIDER_KEY =
+ SCAClientFactory.class.getName();
+
+ /**
+ * The name of the file loaded from the ClassPath to determine
+ * the SPI implementation to use for the SCAClientFactory.
+ */
+ private static final String SCA_CLIENT_FACTORY_PROVIDER_META_INF_SERVICE
+ = "META-INF/services/" + SCA_CLIENT_FACTORY_PROVIDER_KEY;
+
+ /**
+ * Public Constructor
+ */
+ public SCAClientFactoryFinderImpl() {
+ }
+
+ /**
+ * Creates an instance of the SCAClientFactorySPI implementation.
+ * This discovers the SCAClientFactorySPI Implementation and instantiates
+ * the provider's implementation.
+ *
+ * @param properties Properties that may be used when creating a new
+ * instance of the SCAClient
+ * @param classLoader ClassLoader that may be used when creating a new
+ * instance of the SCAClient
+ * @return new instance of the SCAClientFactory
+ * @throws ServiceRuntimeException Failed to create SCAClientFactory
+ * Implementation.
+ */
+ public SCAClientFactory find(Properties properties,
+ ClassLoader classLoader,
+ URI domainURI )
+ throws NoSuchDomainException, ServiceRuntimeException {
+ if (classLoader == null) {
+ classLoader = getThreadContextClassLoader ();
+ }
+ final String factoryImplClassName =
+ discoverProviderFactoryImplClass(properties, classLoader);
+ final Class<? extends SCAClientFactory> factoryImplClass
+ = loadProviderFactoryClass(factoryImplClassName,
+ classLoader);
+ final SCAClientFactory factory =
+ instantiateSCAClientFactoryClass(factoryImplClass,
+ domainURI );
+ return factory;
+ }
+
+ /**
+ * Gets the Context ClassLoader for the current Thread.
+ *
+ * @return The Context ClassLoader for the current Thread.
+ */
+ private static ClassLoader getThreadContextClassLoader () {
+ final ClassLoader threadClassLoader =
+ Thread.currentThread().getContextClassLoader();
+ return threadClassLoader;
+ }
+
+ /**
+ * Attempts to discover the class name for the SCAClientFactorySPI
+ * implementation from the specified Properties, the System Properties
+ * or the specified ClassLoader.
+ *
+ * @return The class name of the SCAClientFactorySPI implementation
+ * @throw ServiceRuntimeException Failed to find implementation for
+ * SCAClientFactorySPI.
+ */
+ private static String
+ discoverProviderFactoryImplClass(Properties properties,
+ ClassLoader classLoader)
+ throws ServiceRuntimeException {
+ String providerClassName =
+ checkPropertiesForSPIClassName(properties);
+ if (providerClassName != null) {
+ return providerClassName;
+ }
+
+ providerClassName =
+ checkPropertiesForSPIClassName(System.getProperties());
+ if (providerClassName != null) {
+ return providerClassName;
+ }
+
+ providerClassName = checkMETAINFServicesForSIPClassName(classLoader);
+ if (providerClassName == null) {
+ throw new ServiceRuntimeException(
+ "Failed to find implementation for SCAClientFactory");
+ }
+
+ return providerClassName;
+ }
+
+ /**
+ * Attempts to find the class name for the SCAClientFactorySPI
+ * implementation from the specified Properties.
+ *
+ * @return The class name for the SCAClientFactorySPI implementation
+ * or <code>null</code> if not found.
+ */
+ private static String
+ checkPropertiesForSPIClassName(Properties properties) {
+ if (properties == null) {
+ return null;
+ }
+
+ final String providerClassName =
+ properties.getProperty(SCA_CLIENT_FACTORY_PROVIDER_KEY);
+ if (providerClassName != null && providerClassName.length() > 0) {
+ return providerClassName;
+ }
+
+ return null;
+ }
+
+ /**
+ * Attempts to find the class name for the SCAClientFactorySPI
+ * implementation from the META-INF/services directory
+ *
+ * @return The class name for the SCAClientFactorySPI implementation or
+ * <code>null</code> if not found.
+ */
+ private static String checkMETAINFServicesForSIPClassName(ClassLoader cl)
+ {
+ final URL url =
+ cl.getResource(SCA_CLIENT_FACTORY_PROVIDER_META_INF_SERVICE);
+ if (url == null) {
+ return null;
+ }
+
+ InputStream in = null;
+ try {
+ in = url.openStream();
+ BufferedReader reader = null;
+ try {
+ reader =
+ new BufferedReader(new InputStreamReader(in, "UTF-8"));
+
+ String line;
+ while ((line = readNextLine(reader)) != null) {
+ if (!line.startsWith("#") && line.length() > 0) {
+ return line;
+ }
+ }
+
+ return null;
+ } finally {
+ closeStream(reader);
+ }
+ } catch (IOException ex) {
+ throw new ServiceRuntimeException(
+ "Failed to discover SCAClientFactory provider", ex);
+ } finally {
+ closeStream(in);
+ }
+ }
+
+ /**
+ * Reads the next line from the reader and returns the trimmed version
+ * of that line
+ *
+ * @param reader The reader from which to read the next line
+ * @return The trimmed next line or <code>null</code> if the end of the
+ * stream has been reached
+ * @throws IOException I/O error occurred while reading from Reader
+ */
+ private static String readNextLine(BufferedReader reader)
+ throws IOException {
+
+ String line = reader.readLine();
+ if (line != null) {
+ line = line.trim();
+ }
+ return line;
+ }
+
+ /**
+ * Loads the specified SCAClientFactory Implementation class.
+ *
+ * @param factoryImplClassName The name of the SCAClientFactory
+ * Implementation class to load
+ * @return The specified SCAClientFactory Implementation class
+ * @throws ServiceRuntimeException Failed to load the SCAClientFactory
+ * Implementation class
+ */
+ private static Class<? extends SCAClientFactory>
+ loadProviderFactoryClass(String factoryImplClassName,
+ ClassLoader classLoader)
+ throws ServiceRuntimeException {
+
+ try {
+ final Class<?> providerClass =
+ classLoader.loadClass(factoryImplClassName);
+ final Class<? extends SCAClientFactory> providerFactoryClass =
+ providerClass.asSubclass(SCAClientFactory.class);
+ return providerFactoryClass;
+ } catch (ClassNotFoundException ex) {
+ throw new ServiceRuntimeException(
+ "Failed to load SCAClientFactory implementation class "
+ + factoryImplClassName, ex);
+ } catch (ClassCastException ex) {
+ throw new ServiceRuntimeException(
+ "Loaded SCAClientFactory implementation class "
+ + factoryImplClassName
+ + " is not a subclass of "
+ + SCAClientFactory.class.getName() , ex);
+ }
+ }
+
+ /**
+ * Instantiate an instance of the specified SCAClientFactorySPI
+ * Implementation class.
+ *
+ * @param factoryImplClass The SCAClientFactorySPI Implementation
+ * class to instantiate.
+ * @return An instance of the SCAClientFactorySPI Implementation class
+ * @throws ServiceRuntimeException Failed to instantiate the specified
+ * specified SCAClientFactorySPI Implementation class
+ */
+ private static SCAClientFactory instantiateSCAClientFactoryClass(
+ Class<? extends SCAClientFactory> factoryImplClass,
+ URI domainURI)
+ throws NoSuchDomainException, ServiceRuntimeException {
+
+ try {
+ Constructor<? extends SCAClientFactory> URIConstructor =
+ factoryImplClass.getConstructor(domainURI.getClass());
+ SCAClientFactory provider =
+ URIConstructor.newInstance( domainURI );
+ return provider;
+ } catch (Throwable ex) {
+ throw new ServiceRuntimeException(
+ "Failed to instantiate SCAClientFactory implementation class "
+ + factoryImplClass, ex);
+ }
+ }
+
+ /**
+ * Utility method for closing Closeable Object.
+ *
+ * @param closeable The Object to close.
+ */
+ private static void closeStream(Closeable closeable) {
+ if (closeable != null) {
+ try{
+ closeable.close();
+ } catch (IOException ex) {
+ throw new ServiceRuntimeException("Failed to close stream",
+ ex);
+ }
+ }
+ }
+}
|