Top Description Fields Constructors Methods
javax.ws.rs.ext

pack-priv final Class FactoryFinder

extends Object
Class Inheritance
Imports
java.io.File, .FileInputStream, .IOException, java.security.AccessController, .PrivilegedAction, java.util.Iterator, .Properties, .ServiceConfigurationError, .ServiceLoader, java.util.logging.Level, .Logger

Factory finder utility class.
Authors
Paul Sandoz, Marc Hadley, Marek Potociar
Since
1.0

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <
type of the service to be found.
T
>
Object

Returns:

the instance of the specified service; may not be null.
find
(final String
the name of the factory to find, which is a system property.
factoryId
,
final String
the implementation class name, which is to be used only if nothing else. is found; null to indicate that there is no fallback class name.
fallbackClassName
,
Class<T>
service to be found.
service
)

Finds the implementation Class for the given factory name, or if that fails, finds the Class for the given fallback class name and create its instance.

private static ClassLoader
private static Object

Returns:

instance of the specified class.
newInstance
(final String
name of the class to be instantiated.
className
,
final ClassLoader
class loader to be used.
classLoader
)

Creates an instance of the specified class using the specified ClassLoader object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

FactoryFinderback to summary
private FactoryFinder()

Method Detail

findback to summary
pack-priv static <T> Object find(final String factoryId, final String fallbackClassName, Class<T> service) throws ClassNotFoundException

Finds the implementation Class for the given factory name, or if that fails, finds the Class for the given fallback class name and create its instance. The arguments supplied MUST be used in order. If using the first argument is successful, the second one will not be used.

This method is package private so that this code can be shared.

Parameters
<T>
type of the service to be found.
factoryId:String

the name of the factory to find, which is a system property.

fallbackClassName:String

the implementation class name, which is to be used only if nothing else. is found; null to indicate that there is no fallback class name.

service:Class<T>

service to be found.

Returns:Object

the instance of the specified service; may not be null.

Exceptions
ClassNotFoundException:
if the given class could not be found or could not be instantiated.
getContextClassLoaderback to summary
private static ClassLoader getContextClassLoader()
newInstanceback to summary
private static Object newInstance(final String className, final ClassLoader classLoader) throws ClassNotFoundException

Creates an instance of the specified class using the specified ClassLoader object.

Parameters
className:String

name of the class to be instantiated.

classLoader:ClassLoader

class loader to be used.

Returns:Object

instance of the specified class.

Exceptions
ClassNotFoundException:
if the given class could not be found or could not be instantiated.