de.smartics.util.util
Class GenericServiceFactory<T>

java.lang.Object
  extended by de.smartics.util.util.GenericServiceFactory<T>
Type Parameters:
T - the type of the created instance.
All Implemented Interfaces:
Serializable

public final class GenericServiceFactory<T>
     
     
extends Object
implements Serializable

A factory to create instances of a given type via META-INF/services.

See Also:
Serialized Form

Constructor Summary
GenericServiceFactory(Class<T> type)
          Convenience constructor for lenient creation.
GenericServiceFactory(Class<T> type, boolean lenient)
          Default constructor.
 
Method Summary
 T create()
          Creates an instance of the type provided with the constructor using the configuration of the service in META-INF/services in the mode passed to the constructor.
 T create(boolean lenient)
          Creates an instance of the type provided with the constructor using the configuration of the service in META-INF/services.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericServiceFactory

public GenericServiceFactory(Class<T> type)
                      throws NullPointerException
Convenience constructor for lenient creation.

Parameters:
type - the type of instances to be created.
Throws:
NullPointerException - if type is null.

GenericServiceFactory

public GenericServiceFactory(Class<T> type,
                             boolean lenient)
                      throws NullPointerException
Default constructor.

Parameters:
type - the type of instances to be created.
lenient - the default mode to create instances.
Throws:
NullPointerException - if type is null.
Method Detail

create

public T create()
         throws IllegalStateException
Creates an instance of the type provided with the constructor using the configuration of the service in META-INF/services in the mode passed to the constructor.

Returns:
instance of the configured type.
Throws:
IllegalStateException - if no instance has been loaded successfully.

create

public T create(boolean lenient)
         throws IllegalStateException
Creates an instance of the type provided with the constructor using the configuration of the service in META-INF/services.

Parameters:
lenient - if more than one instance has been found or loading a redundant instance encountered problems, a value of true will only issue a warning, while false will throw an IllegalStateException.
Returns:
instance of the configured type.
Throws:
IllegalStateException - if no instance has been loaded successfully.


Copyright © 2011–2013 smartics. All rights reserved.