|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.neo4j.helpers.Service
public abstract class Service
A utility for locating services. This implements the same functionality as
the Java 6 ServiceLoader interface, in fact it uses the
ServiceLoader
if available, but backports the functionality to
previous Java versions and adds some error handling to ignore misconfigured
service implementations.
Additionally this class can be used as a base class for implementing services
that are differentiated by a String key. An example implementation might be:
public abstract class StringConverter extends org.neo4j.commons.Service
{
protected StringConverter(String id)
{
super( id );
}
public abstract String convert( String input );
public static StringConverter load( String id )
{
return org.neo4j.commons.Service.load( StringConverter.class, id );
}
}
With for example these implementations:
public final class UppercaseConverter extends StringConverter
{
public UppercaseConverter()
{
super( "uppercase" );
}
public String convert( String input )
{
return input.toUpperCase();
}
}
public final class ReverseConverter extends StringConverter
{
public ReverseConverter()
{
super( "reverse" );
}
public String convert( String input )
{
char[] chars = input.toCharArray();
for ( int i = 0; i < chars.length/2; i++ )
{
char intermediate = chars[i];
chars[i] = chars[chars.length-1-i];
chars[chars.length-1-i] = chars[i];
}
return new String( chars );
}
}
This would then be used as:
String atad = StringConverter.load( "reverse" ).convert( "data" );
Nested Class Summary | |
---|---|
static class |
Service.CaseInsensitiveService
A base class for services, similar to Service , that compares keys
using case insensitive comparison instead of exact comparison. |
static interface |
Service.Implementation
Designates that a class implements the specified service and should be added to the services listings file (META-INF/services/[service-name]). |
Constructor Summary | |
---|---|
protected |
Service(String key,
String... altKeys)
Create a new instance of a service implementation identified with the specified key(s). |
Method Summary | ||
---|---|---|
static
|
load(Class<T> type)
Load all implementations of a Service. |
|
static
|
load(Class<T> type,
String key)
Load the Service implementation with the specified key. |
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Service(String key, String... altKeys)
key
- the main key for identifying this service implementationaltKeys
- alternative spellings of the identifier of this service
implementationMethod Detail |
---|
public static <T> Iterable<T> load(Class<T> type)
T
- the type of the Servicetype
- the type of the Service to load
public static <T extends Service> T load(Class<T> type, String key)
T
- the type of the Servicetype
- the type of the Service to loadkey
- the key that identifies the desired implementation
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |