Package org.dspace.utils.servicemanager
Class ProviderHolder<T>
- java.lang.Object
-
- org.dspace.utils.servicemanager.ProviderHolder<T>
-
public final class ProviderHolder<T> extends Object
A holder which is designed to make it easy to hold onto a reference to a class which is outside of our ClassLoader and not cause it to not be able to reload happily. The reference to the object that is held onto here needs to not be the only one in the system or this object will be garbage collected before it probably should be. That is generally outside the purview of the service manager system though.- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Constructor Summary
Constructors Constructor Description ProviderHolder()
Default constructor.ProviderHolder(T provider)
Create the holder with a provider already in it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
T
getProvider()
Gets the provider out of this holder.T
getProviderOrFail()
Gets the provider out of this holder if it still exists.int
hashCode()
void
setProvider(T provider)
Stores a provider in this holder in a ClassLoader safe way.String
toString()
-
-
-
Constructor Detail
-
ProviderHolder
public ProviderHolder()
Default constructor.
-
ProviderHolder
public ProviderHolder(T provider)
Create the holder with a provider already in it.- Parameters:
provider
- the provider to place in the holder to start
-
-
Method Detail
-
getProvider
public T getProvider()
Gets the provider out of this holder. Use thegetProviderOrFail()
method if you want a method that never returns null.- Returns:
- the provider if it is still available OR null if none is set or no longer available
-
getProviderOrFail
public T getProviderOrFail()
Gets the provider out of this holder if it still exists. Will not return null (unlike thegetProvider()
method).- Returns:
- the provider if it is available
- Throws:
ProviderNotFoundException
- if there is none available
-
setProvider
public void setProvider(T provider)
Stores a provider in this holder in a ClassLoader safe way.- Parameters:
provider
- the provider to store. If this is null then the current provider is cleared.
-
-