dk.netarkivet.common.utils
Class SettingsFactory<T>

java.lang.Object
  extended by dk.netarkivet.common.utils.SettingsFactory<T>
Direct Known Subclasses:
ActiveBitPreservationFactory, AdminFactory, ArcRepositoryClientFactory, DBSpecifics, DBSpecifics, FreeSpaceProviderFactory, HarvestReportFactory, HeritrixControllerFactory, HeritrixLauncherFactory, IndexClientFactory, MonitorRegistryClientFactory, NotificationsFactory, RemoteFileFactory, UrlCanonicalizerFactory

public class SettingsFactory<T>
extends java.lang.Object

Generic class for creating class instances from class names given in settings.


Constructor Summary
SettingsFactory()
           
 
Method Summary
static
<T> T
getInstance(java.lang.String settingsField, java.lang.Object... args)
          Creates a new class of the class given in the settings field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SettingsFactory

public SettingsFactory()
Method Detail

getInstance

public static <T> T getInstance(java.lang.String settingsField,
                                java.lang.Object... args)
Creates a new class of the class given in the settings field. If the loaded class has a getInstance() method that matches the given arguments, that will be called to create the class, otherwise a matching constructor will be called, if it exists. This sequence allows for creating singletons. Due to limitations of the Java Reflection API, the parameters of the getInstance method declared on the loaded class must match the given arguments exactly, without subclassing, interface implementation or unboxing. In particular, since any primitive types are automatically boxed when passed to this method, getInstance() methods with primitive type formal parameters will not be found.

Parameters:
settingsField - A field in the Settings class.
args - The arguments that will be passed to the getInstance method or the constructor. These will also be used to determine which getInstance method or constructor to find.
Returns:
A new instance created by calling getInstance() or by invoking a constructor.
Throws:
ArgumentNotValid - if settingsField is null or the invoked method or constructor threw an exception.
IOFailure - if there are unrecoverable errors reflecting upon the class.
PermissionDenied - if the class or methods cannot be accessed.