1 25 package org.objectweb.jonas.ws; 26 27 import java.io.InputStream ; 28 import java.util.Properties ; 29 30 35 public class ClientJServiceFactoryFinder { 36 37 40 private static Properties props; 41 42 45 private static final String JONAS_SERVICE_FACTORY = "jonas.service.ws.factory.class"; 46 47 50 private ClientJServiceFactoryFinder() { 51 } 52 53 56 private static String factoryClassName = null; 57 58 63 public static JServiceFactory getJOnASServiceFactory() throws WSServiceException { 64 JServiceFactory factory = null; 65 ClassLoader current = Thread.currentThread().getContextClassLoader(); 66 67 if (props == null) { 68 props = new Properties (); 69 try { 70 InputStream is = current.getResourceAsStream("jonas-client.properties"); 71 if (is != null) { 72 props.load(is); 73 factoryClassName = props.getProperty(JONAS_SERVICE_FACTORY); 74 } else { 75 System.err.println("Cannot load jonas-client.properties from ClassLoader"); 76 } 77 } catch (Exception e) { 78 String err = "Error when trying to get jonas property '" + JONAS_SERVICE_FACTORY 79 + "' from jonas-client.properties"; 80 throw new WSServiceException(err, e); 81 } 82 } 83 84 if (factoryClassName == null) { 85 String err = "jonas property '" + JONAS_SERVICE_FACTORY + "' must be set! in jonas-client.properties"; 86 throw new WSServiceException(err); 87 } 88 89 try { 91 factory = (JServiceFactory) current.loadClass(factoryClassName).newInstance(); 92 } catch (ClassNotFoundException cnfe) { 93 String err = "ClassNotFound '" + factoryClassName + "' in JOnAS ClassLoader"; 94 throw new WSServiceException(err); 95 } catch (InstantiationException ie) { 96 String err = "Instantiation error for new '" + factoryClassName + "'"; 97 throw new WSServiceException(err); 98 } catch (IllegalAccessException ie) { 99 String err = "Illegal Access for new '" + factoryClassName + "'"; 100 throw new WSServiceException(err); 101 } 102 103 return factory; 104 105 } 106 107 } | Popular Tags |