1 6 7 28 29 package javax.xml.soap; 30 31 import java.io.*; 32 import java.util.Properties ; 33 34 35 class FactoryFinder { 36 37 44 private static Object newInstance(String className, 45 ClassLoader classLoader) 46 throws SOAPException 47 { 48 try { 49 Class spiClass; 50 if (classLoader == null) { 51 spiClass = Class.forName(className); 52 } else { 53 spiClass = classLoader.loadClass(className); 54 } 55 return spiClass.newInstance(); 56 } catch (ClassNotFoundException x) { 57 throw new SOAPException ( 58 "Provider " + className + " not found", x); 59 } catch (Exception x) { 60 throw new SOAPException ( 61 "Provider " + className + " could not be instantiated: " + x, 62 x); 63 } 64 } 65 66 79 static Object find(String factoryId) 80 throws SOAPException 81 { 82 ClassLoader classLoader; 83 try { 84 classLoader = Thread.currentThread().getContextClassLoader(); 85 } catch (Exception x) { 86 throw new SOAPException (x.toString(), x); 87 } 88 89 try { 91 String systemProp = 92 System.getProperty( factoryId ); 93 if( systemProp!=null) { 94 return newInstance(systemProp, classLoader); 95 } 96 } catch (SecurityException se) { 97 } 98 99 try { 101 String javah=System.getProperty( "java.home" ); 102 String configFile = javah + File.separator + 103 "lib" + File.separator + "jaxm.properties"; 104 File f=new File( configFile ); 105 if( f.exists()) { 106 Properties props=new Properties (); 107 props.load( new FileInputStream(f)); 108 String factoryClassName = props.getProperty(factoryId); 109 return newInstance(factoryClassName, classLoader); 110 } 111 } catch(Exception ex ) { 112 } 113 114 String serviceId = "META-INF/services/" + factoryId; 115 try { 117 InputStream is=null; 118 if (classLoader == null) { 119 is=ClassLoader.getSystemResourceAsStream(serviceId); 120 } else { 121 is=classLoader.getResourceAsStream(serviceId); 122 } 123 124 if( is!=null ) { 125 BufferedReader rd = 126 new BufferedReader(new InputStreamReader(is, "UTF-8")); 127 128 String factoryClassName = rd.readLine(); 129 rd.close(); 130 131 if (factoryClassName != null && 132 ! "".equals(factoryClassName)) { 133 return newInstance(factoryClassName, classLoader); 134 } 135 } 136 } catch( Exception ex ) { 137 } 138 139 return null; 140 } 141 142 162 static Object find(String factoryId, String fallbackClassName) 163 throws SOAPException 164 { 165 166 Object obj = find(factoryId); 167 if (obj != null) 168 return obj; 169 170 ClassLoader classLoader; 171 try { 172 classLoader = Thread.currentThread().getContextClassLoader(); 173 } catch (Exception x) { 174 throw new SOAPException (x.toString(), x); 175 } 176 177 if (fallbackClassName == null) { 178 throw new SOAPException ( 179 "Provider for " + factoryId + " cannot be found", null); 180 } 181 182 return newInstance(fallbackClassName, classLoader); 183 } 184 } 185 | Popular Tags |