public final class ServiceLoader
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
ServiceLoader.PropertyAccessAction |
private static class |
ServiceLoader.PropertyFileAccessAction |
private static class |
ServiceLoader.PropertyFileExistAction |
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.String>> |
serviceMap
A synchronized weak hash map that keeps factory names retrieved using Service API (META-INF/services/*) for each classloader.
|
| Modifier | Constructor and Description |
|---|---|
private |
ServiceLoader()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private static java.lang.String |
getServiceNameUsingCache(java.lang.ClassLoader loader,
java.lang.String filename) |
private static java.lang.Object |
loadDefault(java.lang.String defaultFactory,
java.lang.ClassLoader loader) |
private static java.lang.Object |
loadFromPropertiesFile(java.lang.String propertyName,
java.lang.ClassLoader loader)
Use the properties file "${java.home}/lib/jaxws.properties" in the JRE directory.
|
private static java.lang.Object |
loadFromServices(java.lang.String propertyName,
java.lang.ClassLoader loader)
Use the Services API (as detailed in the JAR specification), if available, to determine the classname.
|
private static java.lang.Object |
loadFromSystemProperty(java.lang.String propertyName,
java.lang.String defaultFactory,
java.lang.ClassLoader loader)
Use the system property
|
static java.lang.Object |
loadService(java.lang.String propertyName,
java.lang.String defaultFactory)
This method uses the algorithm below using the JAXWS Provider as an example.
|
static java.lang.Object |
loadService(java.lang.String propertyName,
java.lang.String defaultFactory,
java.lang.ClassLoader cl)
This method uses the algorithm below using the JAXWS Provider as an example.
|
private static java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.String>> serviceMap
public static java.lang.Object loadService(java.lang.String propertyName,
java.lang.String defaultFactory,
java.lang.ClassLoader cl)
1. If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider exists, then
its first line, if present, is used as the UTF-8 encoded name of the implementation class.
2. If the ${java.home}/lib/jaxws.properties file exists and it is readable by the
java.util.Properties.load(InputStream) method and it contains an entry whose key is
javax.xml.ws.spi.Provider, then the value of that entry is used as the name of the implementation class.
3. If a system property with the name javax.xml.ws.spi.Provider is defined, then its value is used
as the name of the implementation class.
4. Finally, a default implementation class name is used.
propertyName - The property name for the service to resolvedefaultFactory - Default factory class name to be used when not able to resolve anythingcl - The classLoader to be used for loading resolved servicepublic static java.lang.Object loadService(java.lang.String propertyName,
java.lang.String defaultFactory)
1. If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider exists, then
its first line, if present, is used as the UTF-8 encoded name of the implementation class.
2. If the ${java.home}/lib/jaxws.properties file exists and it is readable by the
java.util.Properties.load(InputStream) method and it contains an entry whose key is
javax.xml.ws.spi.Provider, then the value of that entry is used as the name of the implementation class.
3. If a system property with the name javax.xml.ws.spi.Provider is defined, then its value is used
as the name of the implementation class.
4. Finally, a default implementation class name is used.
This is equivalent to calling loadService(String propertyName, String defaultFactory, ClassLoader cl)
passing in the Thread.currentThread().getContextClassLoader().propertyName - The property name for the service to resolvedefaultFactory - Default factory class name to be used when not able to resolve anythingprivate static java.lang.Object loadFromServices(java.lang.String propertyName,
java.lang.ClassLoader loader)
private static java.lang.String getServiceNameUsingCache(java.lang.ClassLoader loader,
java.lang.String filename)
throws java.io.IOException
java.io.IOExceptionprivate static java.lang.Object loadFromSystemProperty(java.lang.String propertyName,
java.lang.String defaultFactory,
java.lang.ClassLoader loader)
private static java.lang.Object loadFromPropertiesFile(java.lang.String propertyName,
java.lang.ClassLoader loader)
private static java.lang.Object loadDefault(java.lang.String defaultFactory,
java.lang.ClassLoader loader)