|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectca.infoway.messagebuilder.service.ServiceFactory<T>
T
- - the interface type of the servicepublic abstract class ServiceFactory<T>
A common Java practice for allowing configurable implementations of a service
interface is to look for a file in the META-INF directory of a jar. An example of
this problem is XML parsing. There's an abstract factory type called
javax.xml.parsers.DocumentBuilderFactory
, and the expectation is that
some component will provide a concrete implementation of this type.
The Java way of handling that is to look for a file in the META-INF directory called /META-INF/javax.xml.parsers.DocumentBuilderFactory
The file is a simple text file that contains the fully-qualified name of an implementing class, and Java can decide to pick one (or many) of those implementations.
This class implements behaviour like that -- it looks for a set of resources on the classpath, named after a specific type, and finds the corresponding classes.
Constructor Summary | |
---|---|
ServiceFactory(Class<T> c)
Standard constructor. |
Method Summary | |
---|---|
protected abstract T |
chooseImplementationOfService(List<T> services)
Choose an implementation of a service, based on several options. |
T |
create()
Create an instance of the service. |
protected abstract T |
createTrivialService()
Create a trivial service if no other option exists. |
protected List<T> |
getServices(Enumeration<URL> resources)
Find all implementations of the message definition service. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServiceFactory(Class<T> c)
Standard constructor.
c
- - the type of service that the factory findsMethod Detail |
---|
public T create()
Create an instance of the service.
protected abstract T chooseImplementationOfService(List<T> services)
Choose an implementation of a service, based on several options.
protected abstract T createTrivialService()
Create a trivial service if no other option exists.
protected List<T> getServices(Enumeration<URL> resources) throws IOException
Find all implementations of the message definition service.
resources
- - an enumeration of all the URLs to service files
IOException
- - if any resource cannot be accessed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |