00001
00025 package org.objectweb.jonas.ws;
00026
00027 import java.io.InputStream;
00028 import java.util.Properties;
00029
00035 public class ClientJServiceFactoryFinder {
00036
00040 private static Properties props;
00041
00045 private static final String JONAS_SERVICE_FACTORY = "jonas.service.ws.factory.class";
00046
00050 private ClientJServiceFactoryFinder() {
00051 }
00052
00056 private static String factoryClassName = null;
00057
00063 public static JServiceFactory getJOnASServiceFactory() throws WSServiceException {
00064 JServiceFactory factory = null;
00065 ClassLoader current = Thread.currentThread().getContextClassLoader();
00066
00067 if (props == null) {
00068 props = new Properties();
00069 try {
00070 InputStream is = current.getResourceAsStream("jonas-client.properties");
00071 if (is != null) {
00072 props.load(is);
00073 factoryClassName = props.getProperty(JONAS_SERVICE_FACTORY);
00074 } else {
00075 System.err.println("Cannot load jonas-client.properties from ClassLoader");
00076 }
00077 } catch (Exception e) {
00078 String err = "Error when trying to get jonas property '" + JONAS_SERVICE_FACTORY
00079 + "' from jonas-client.properties";
00080 throw new WSServiceException(err, e);
00081 }
00082 }
00083
00084 if (factoryClassName == null) {
00085 String err = "jonas property '" + JONAS_SERVICE_FACTORY + "' must be set! in jonas-client.properties";
00086 throw new WSServiceException(err);
00087 }
00088
00089
00090 try {
00091 factory = (JServiceFactory) current.loadClass(factoryClassName).newInstance();
00092 } catch (ClassNotFoundException cnfe) {
00093 String err = "ClassNotFound '" + factoryClassName + "' in JOnAS ClassLoader";
00094 throw new WSServiceException(err);
00095 } catch (InstantiationException ie) {
00096 String err = "Instantiation error for new '" + factoryClassName + "'";
00097 throw new WSServiceException(err);
00098 } catch (IllegalAccessException ie) {
00099 String err = "Illegal Access for new '" + factoryClassName + "'";
00100 throw new WSServiceException(err);
00101 }
00102
00103 return factory;
00104
00105 }
00106
00107 }