[jbossws-commits] JBossWS SVN: r14263 - api/trunk/src/main/java/org/jboss/wsf/spi/util.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Fri May 6 03:30:58 EDT 2011
Author: richard.opalka at jboss.com
Date: 2011-05-06 03:30:57 -0400 (Fri, 06 May 2011)
New Revision: 14263
Modified:
api/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
Log:
Refactoring ServiceLoader
- it's utility class not intended for inheritance - disabling abstractness
- fixing many compiler warnings
- updating methods signature and removing unused parameters
- removing useless comments
Modified: api/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
===================================================================
--- api/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java 2011-05-05 14:14:20 UTC (rev 14262)
+++ api/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java 2011-05-06 07:30:57 UTC (rev 14263)
@@ -42,7 +42,7 @@
* @author alessio.soldano at jboss.com
* @since 14-Dec-2006
*/
-public abstract class ServiceLoader
+public final class ServiceLoader
{
/**
* A synchronized weak hash map that keeps factory names retrieved using Service API (META-INF/services/*) for each classloader.
@@ -51,6 +51,14 @@
private static Map<ClassLoader, Map<String, String>> serviceMap = Collections.synchronizedMap(new WeakHashMap<ClassLoader, Map<String, String>>());
/**
+ * Constructor.
+ */
+ private ServiceLoader()
+ {
+ // forbidden instantiation
+ }
+
+ /**
* This method uses the algorithm below using the JAXWS Provider as an example.
*
* 1. If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider exists, then
@@ -72,10 +80,10 @@
*/
public static Object loadService(String propertyName, String defaultFactory, ClassLoader cl)
{
- Object factory = loadFromServices(propertyName, null, cl);
+ Object factory = loadFromServices(propertyName, cl);
if (factory == null)
{
- factory = loadFromPropertiesFile(propertyName, null, cl);
+ factory = loadFromPropertiesFile(propertyName, cl);
}
if (factory == null)
{
@@ -113,7 +121,7 @@
/** Use the Services API (as detailed in the JAR specification), if available, to determine the classname.
*/
- private static Object loadFromServices(String propertyName, String defaultFactory, ClassLoader loader)
+ private static Object loadFromServices(String propertyName, ClassLoader loader)
{
Object factory = null;
String factoryName = null;
@@ -126,7 +134,7 @@
factoryName = getServiceNameUsingCache(loader, filename);
if (factoryName != null)
{
- Class factoryClass = SecurityActions.loadClass(loader, factoryName);
+ Class<?> factoryClass = SecurityActions.loadClass(loader, factoryName);
factory = factoryClass.newInstance();
}
}
@@ -135,12 +143,6 @@
throw new IllegalStateException("Failed to load " + propertyName + ": " + factoryName, t);
}
- // Use the default factory implementation class.
- if (factory == null && defaultFactory != null)
- {
- factory = loadDefault(defaultFactory, loader);
- }
-
return factory;
}
@@ -177,14 +179,13 @@
{
Object factory = null;
- PrivilegedAction action = new PropertyAccessAction(propertyName);
- String factoryName = (String)AccessController.doPrivileged(action);
+ PrivilegedAction<String> action = new PropertyAccessAction(propertyName);
+ String factoryName = AccessController.doPrivileged(action);
if (factoryName != null)
{
try
{
- //if(log.isDebugEnabled()) log.debug("Load from system property: " + factoryName);
- Class factoryClass = SecurityActions.loadClass(loader, factoryName);
+ Class<?> factoryClass = SecurityActions.loadClass(loader, factoryName);
factory = factoryClass.newInstance();
}
catch (Throwable t)
@@ -207,26 +208,25 @@
* This configuration file is in standard java.util.Properties format and contains the
* fully qualified name of the implementation class with the key being the system property defined above.
*/
- private static Object loadFromPropertiesFile(String propertyName, String defaultFactory, ClassLoader loader)
+ private static Object loadFromPropertiesFile(String propertyName, ClassLoader loader)
{
Object factory = null;
String factoryName = null;
// Use the properties file "lib/jaxm.properties" in the JRE directory.
// This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above.
- PrivilegedAction action = new PropertyAccessAction("java.home");
- String javaHome = (String)AccessController.doPrivileged(action);
+ PrivilegedAction<String> propertyReadAction = new PropertyAccessAction("java.home");
+ String javaHome = AccessController.doPrivileged(propertyReadAction);
File jaxmFile = new File(javaHome + "/lib/jaxws.properties");
if ((Boolean)AccessController.doPrivileged(new PropertyFileExistAction(jaxmFile)))
{
try
{
- action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
- Properties jaxmProperties = (Properties)AccessController.doPrivileged(action);
+ PropertyFileAccessAction propertyFileAccessAction = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
+ Properties jaxmProperties = AccessController.doPrivileged(propertyFileAccessAction);
factoryName = jaxmProperties.getProperty(propertyName);
if (factoryName != null)
{
- //if(log.isDebugEnabled()) log.debug("Load from " + jaxmFile + ": " + factoryName);
Class<?> factoryClass = SecurityActions.loadClass(loader, factoryName);
factory = factoryClass.newInstance();
}
@@ -237,12 +237,6 @@
}
}
- // Use the default factory implementation class.
- if (factory == null && defaultFactory != null)
- {
- factory = loadDefault(defaultFactory, loader);
- }
-
return factory;
}
@@ -255,8 +249,7 @@
{
try
{
- //if(log.isDebugEnabled()) log.debug("Load from default: " + factoryName);
- Class factoryClass = SecurityActions.loadClass(loader, defaultFactory);
+ Class<?> factoryClass = SecurityActions.loadClass(loader, defaultFactory);
factory = factoryClass.newInstance();
}
catch (Throwable t)
@@ -268,7 +261,7 @@
return factory;
}
- private static class PropertyAccessAction implements PrivilegedAction
+ private static class PropertyAccessAction implements PrivilegedAction<String>
{
private String name;
@@ -277,13 +270,13 @@
this.name = name;
}
- public Object run()
+ public String run()
{
return System.getProperty(name);
}
}
- private static class PropertyFileAccessAction implements PrivilegedAction
+ private static class PropertyFileAccessAction implements PrivilegedAction<Properties>
{
private String filename;
@@ -292,7 +285,7 @@
this.filename = filename;
}
- public Object run()
+ public Properties run()
{
InputStream inStream = null;
try
@@ -310,14 +303,17 @@
{
try
{
- inStream.close();
+ if (inStream != null)
+ {
+ inStream.close();
+ }
}
- catch (Exception e) {} //ignore
+ catch (Exception ignore) {}
}
}
}
- private static class PropertyFileExistAction implements PrivilegedAction
+ private static class PropertyFileExistAction implements PrivilegedAction<Boolean>
{
private File file;
@@ -326,7 +322,7 @@
this.file = file;
}
- public Object run()
+ public Boolean run()
{
return file.exists();
}
More information about the jbossws-commits
mailing list