Methods Summary |
---|
static java.lang.Object | find(java.lang.String factoryPropertyName, java.lang.String defaultFactoryClassName)Instantiates a factory object given the factory's property name and the
default class name.
try {
String factoryClassName = System.getProperty(factoryPropertyName);
if (factoryClassName != null) {
return newInstance(factoryClassName);
}
} catch (SecurityException securityexception) {}
try {
String propertiesFileName = System.getProperty("java.home")
+ File.separator + "lib"
+ File.separator + "jaxm.properties";
File file = new File(propertiesFileName);
if (file.exists()) {
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInput);
fileInput.close();
String factoryClassName = properties.getProperty(factoryPropertyName);
return newInstance(factoryClassName);
}
} catch (Exception exception1) {}
String factoryResource = "META-INF/services/" + factoryPropertyName;
try {
InputStream inputstream = getResource(factoryResource);
if (inputstream != null) {
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "UTF-8"));
String factoryClassName = bufferedreader.readLine();
bufferedreader.close();
if ((factoryClassName != null) && !"".equals(factoryClassName)) {
return newInstance(factoryClassName);
}
}
} catch (Exception exception2) {}
if (defaultFactoryClassName == null) {
throw new SOAPException("Provider for " + factoryPropertyName + " cannot be found", null);
} else {
return newInstance(defaultFactoryClassName);
}
|
private static java.io.InputStream | getResource(java.lang.String factoryResource)Returns an input stream for the specified resource.
This method will firstly try
ClassLoader.getSystemResourceAsStream() then
the class loader of the current thread with
getResourceAsStream() and finally attempt
getResourceAsStream() on
FactoryFinder.class.getClassLoader() .
ClassLoader classloader = null;
try {
classloader = Thread.currentThread().getContextClassLoader();
} catch (SecurityException securityexception) {}
InputStream inputstream;
if (classloader == null) {
inputstream = ClassLoader.getSystemResourceAsStream(factoryResource);
} else {
inputstream = classloader.getResourceAsStream(factoryResource);
}
if (inputstream == null) {
inputstream = FactoryFinder.class.getClassLoader().getResourceAsStream(factoryResource);
}
return inputstream;
|
private static java.lang.Object | newInstance(java.lang.String factoryClassName)instantiates an object go the given classname.
ClassLoader classloader = null;
try {
classloader = Thread.currentThread().getContextClassLoader();
} catch (Exception exception) {
throw new SOAPException(exception.toString(), exception);
}
try {
Class factory = null;
if (classloader == null) {
factory = Class.forName(factoryClassName);
} else {
try {
factory = classloader.loadClass(factoryClassName);
} catch (ClassNotFoundException cnfe) {}
}
if (factory == null) {
classloader = FactoryFinder.class.getClassLoader();
factory = classloader.loadClass(factoryClassName);
}
return factory.newInstance();
} catch (ClassNotFoundException classnotfoundexception) {
throw new SOAPException("Provider " + factoryClassName + " not found", classnotfoundexception);
} catch (Exception exception) {
throw new SOAPException("Provider " + factoryClassName + " could not be instantiated: " + exception, exception);
}
|