summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-06-05 05:17:47 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-06-05 05:17:47 +0000
commitf052ca9d9dc273dc0f625c9a6ec6eb38d6bc0f3a (patch)
treec316c1a4a098d965f91aef6422aebb862a88a0f7 /sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen
parent8fde4cc2b0f89400b21744d67d91db49f1df8318 (diff)
Setting svn:eol-style for java and xml files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@951651 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen')
-rw-r--r--sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/ResponseDispatch.java92
-rw-r--r--sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncFault.java54
-rw-r--r--sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncInvocation.java58
-rw-r--r--sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java70
-rw-r--r--sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java578
5 files changed, 426 insertions, 426 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/ResponseDispatch.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/ResponseDispatch.java
index fe7f779f5e..1192b16778 100644
--- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/ResponseDispatch.java
+++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/ResponseDispatch.java
@@ -1,46 +1,46 @@
-/*
- * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
- * OASIS trademark, IPR and other policies apply.
- */
-package org.oasisopen.sca;
-
-import java.util.Map;
-
-/**
- *
- * The following defines the ResponseDispatch interface, used to return a response
- * message asynchronously from a service implementation method.
- *
- * @param <T> the type of the Response message returned by the service implementation method
- */
-public interface ResponseDispatch<T> {
-
- /**
- * Sends the response message from an asynchronous service method.
- * This method can only be invoked once for a given ResponseDispatch object and cannot be invoked
- * if sendFault has previously been invoked for the same ResponseDispatch object.
- * @param res an instance of the response message returned by the service operation
- * @exception InvalidStateException if this method is called more than once for the same service
- * operation.
- */
- void sendResponse(T res);
-
- /**
- * Sends an exception as a fault from an asynchronous service method.
- * This method can only be invoked once for a given ResponseDispatch object and cannot be invoked
- * if sendResponse has previously been invoked for the same ResponseDispatch object.
- * @param e an instance of an exception returned by the service operation
- * @exception InvalidStateException if this method is called more than once for the same service
- * operation.
- */
- void sendFault(Throwable e);
-
- /**
- * Obtains the context object for the ResponseDispatch method
- * @return a Map which is is the context object for the ResponseDispatch object.
- * The invoker can update the context object with appropriate context information, prior to invoking
- * either the sendResponse method or the sendFault method
- */
- Map<String, Object> getContext();
-}
-
+/*
+ * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+package org.oasisopen.sca;
+
+import java.util.Map;
+
+/**
+ *
+ * The following defines the ResponseDispatch interface, used to return a response
+ * message asynchronously from a service implementation method.
+ *
+ * @param <T> the type of the Response message returned by the service implementation method
+ */
+public interface ResponseDispatch<T> {
+
+ /**
+ * Sends the response message from an asynchronous service method.
+ * This method can only be invoked once for a given ResponseDispatch object and cannot be invoked
+ * if sendFault has previously been invoked for the same ResponseDispatch object.
+ * @param res an instance of the response message returned by the service operation
+ * @exception InvalidStateException if this method is called more than once for the same service
+ * operation.
+ */
+ void sendResponse(T res);
+
+ /**
+ * Sends an exception as a fault from an asynchronous service method.
+ * This method can only be invoked once for a given ResponseDispatch object and cannot be invoked
+ * if sendResponse has previously been invoked for the same ResponseDispatch object.
+ * @param e an instance of an exception returned by the service operation
+ * @exception InvalidStateException if this method is called more than once for the same service
+ * operation.
+ */
+ void sendFault(Throwable e);
+
+ /**
+ * Obtains the context object for the ResponseDispatch method
+ * @return a Map which is is the context object for the ResponseDispatch object.
+ * The invoker can update the context object with appropriate context information, prior to invoking
+ * either the sendResponse method or the sendFault method
+ */
+ Map<String, Object> getContext();
+}
+
diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncFault.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncFault.java
index 6f36f97bff..278e8ead57 100644
--- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncFault.java
+++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncFault.java
@@ -1,27 +1,27 @@
-/*
- * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
- * OASIS trademark, IPR and other policies apply.
- */
-package org.oasisopen.sca.annotation;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * The @AsyncFault annotation is used to indicate the faults/exceptions which are returned by
- * the asynchronous service method which it annotates.
- *
- */
-@Inherited
-@Target({METHOD})
-@Retention(RUNTIME)
-public @interface AsyncFault {
-
- Class<?>[] value() default {};
-
-}
-
+/*
+ * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+package org.oasisopen.sca.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * The @AsyncFault annotation is used to indicate the faults/exceptions which are returned by
+ * the asynchronous service method which it annotates.
+ *
+ */
+@Inherited
+@Target({METHOD})
+@Retention(RUNTIME)
+public @interface AsyncFault {
+
+ Class<?>[] value() default {};
+
+}
+
diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncInvocation.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncInvocation.java
index 43233e9747..c6a4147afd 100644
--- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncInvocation.java
+++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/AsyncInvocation.java
@@ -1,29 +1,29 @@
-/*
- * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
- * OASIS trademark, IPR and other policies apply.
- */
-package org.oasisopen.sca.annotation;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static org.oasisopen.sca.Constants.SCA_PREFIX;
-
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * The @AsyncInvocation annotation is used to indicate that the operations of a Java interface
- * uses the long-running request-response pattern as described in the SCA Assembly specification.
- *
- */
-@Inherited
-@Target({TYPE, METHOD})
-@Retention(RUNTIME)
-@Intent(AsyncInvocation.ASYNCINVOCATION)
-public @interface AsyncInvocation {
- String ASYNCINVOCATION = SCA_PREFIX + "asyncInvocation";
-
- boolean value() default true;
-}
+/*
+ * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ */
+package org.oasisopen.sca.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.oasisopen.sca.Constants.SCA_PREFIX;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * The @AsyncInvocation annotation is used to indicate that the operations of a Java interface
+ * uses the long-running request-response pattern as described in the SCA Assembly specification.
+ *
+ */
+@Inherited
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+@Intent(AsyncInvocation.ASYNCINVOCATION)
+public @interface AsyncInvocation {
+ String ASYNCINVOCATION = SCA_PREFIX + "asyncInvocation";
+
+ boolean value() default true;
+}
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
index 795fe30714..54a73fc023 100644
--- 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
@@ -1,35 +1,35 @@
-/*
- * Copyright(C) OASIS(R) 2005,2010. 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 ;
-}
+/*
+ * Copyright(C) OASIS(R) 2005,2010. 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/SCAClientFactoryFinderImpl.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java
index 4aa312f6b5..0f5eae7603 100644
--- 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
@@ -1,289 +1,289 @@
-/*
- * Copyright(C) OASIS(R) 2005,2010. 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 = checkMETAINFServicesForSPIClassName(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 checkMETAINFServicesForSPIClassName(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);
- }
- }
- }
-}
+/*
+ * Copyright(C) OASIS(R) 2005,2010. 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 = checkMETAINFServicesForSPIClassName(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 checkMETAINFServicesForSPIClassName(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);
+ }
+ }
+ }
+}