|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.schlichtherle.key.AbstractKeyProvider
public abstract class AbstractKeyProvider
This abstract class implements the base functionality required to be a
"friendly" KeyProvider
.
Each instance of this class maintains a single key, which can be of any
run time type (it is just required to be an Object
).
A clone of this key is returned on each call to getCreateKey()
and getOpenKey()
.
Cloning is used for all array classes and all classes which properly
implement the Cloneable
interface.
The class remains abstract because there is no meaningful template
implementation of the invalidOpenKeyImpl()
method.
Other than the key, this class is stateless.
Hence, instances may be shared among multiple protected resources,
causing them to use the same key.
However, this feature may be restricted by subclasses such as
PromptingKeyProvider
for example.
This class is thread safe.
KeyProvider
Field Summary |
---|
Fields inherited from interface de.schlichtherle.key.KeyProvider |
---|
MIN_KEY_RETRY_DELAY |
Constructor Summary | |
---|---|
AbstractKeyProvider()
|
Method Summary | |
---|---|
protected KeyProvider |
addToKeyManager(String resourceID)
Maps this instance as the key provider for the given resource identifier in the KeyManager . |
protected Object |
cloneKey()
Deprecated. You should not use or override this method. This method will vanish in the next major version release. |
Object |
getCreateKey()
Forwards the call to getCreateKeyImpl() . |
protected Object |
getCreateKeyImpl()
Returns the key which should be used to create a new protected resource or entirely replace the contents of an already existing protected resource. |
Object |
getKey()
Deprecated. You should not use this method from this class. It will be moved to a subclass in the next major version release. |
Object |
getOpenKey()
Forwards the call to getOpenKeyImpl() and enforces a three
seconds suspension penalty if invalidOpenKey() was called by
the same thread before. |
protected Object |
getOpenKeyImpl()
Returns the key which should be used to open an existing protected resource in order to access its contents. |
void |
invalidOpenKey()
This method logs the current time for the current thread, which is later used by getOpenKey() to enforce the suspension penalty
and then calls invalidOpenKeyImpl() . |
protected abstract void |
invalidOpenKeyImpl()
Sublasses must implement this method. |
protected KeyProvider |
removeFromKeyManager(String resourceID)
Remove this instance as the key provider for the given resource identifier from the map in the KeyManager . |
void |
reset()
This hook may be overridden to reset this key provider instance. |
protected void |
resetKey()
Deprecated. You should not use or override this method. This method will vanish in the next major version release. |
void |
setKey(Object key)
Deprecated. You should not use this method from this class. It will be moved to a subclass in the next major version release. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractKeyProvider()
Method Detail |
---|
public Object getKey()
getOpenKey()
or getCreateKey()
.
It is intended to be used by subclasses and user interface classes only.
public void setKey(Object key)
public Object getCreateKey() throws UnknownKeyException
getCreateKeyImpl()
.
getCreateKey
in interface KeyProvider
getCreateKeyImpl
.
In case of an array, a shallow copy of the array is returned.
UnknownKeyException
- If getCreateKeyImpl
throws
this or the returned key is null
.
RuntimeException
- If cloning the key results in a runtime
exception.KeyProvider.getCreateKey()
protected Object getCreateKeyImpl() throws UnknownKeyException
key
to use or null
.
UnknownKeyException
- If the required key is unknown.
At the subclasses discretion, this may mean that prompting for
the key has been disabled or cancelled by the user.KeyProvider.getCreateKey()
public final Object getOpenKey() throws UnknownKeyException
getOpenKeyImpl()
and enforces a three
seconds suspension penalty if invalidOpenKey()
was called by
the same thread before.
Because this method is final, this qualifies the implementation in
this class as a "friendly" KeyProvider
implementation,
even when subclassed.
getOpenKey
in interface KeyProvider
getOpenKeyImpl
.
In case of an array, a shallow copy of the array is returned.
UnknownKeyException
- If getOpenKeyImpl
throws
this or the returned key is null
.
RuntimeException
- If cloning the key results in a runtime
exception.KeyProvider.getOpenKey()
protected Object getOpenKeyImpl() throws UnknownKeyException
key
to use or null
.
UnknownKeyException
- If the required key is unknown.
At the subclasses discretion, this may mean that prompting for
the key has been disabled or cancelled by the user.KeyProvider.getCreateKey()
public final void invalidOpenKey()
getOpenKey()
to enforce the suspension penalty
and then calls invalidOpenKeyImpl()
.
Because this method is final, this implementation qualifies as a
"friendly" KeyProvider
implementation, even when subclassed.
invalidOpenKey
in interface KeyProvider
KeyProvider.invalidOpenKey()
protected abstract void invalidOpenKeyImpl()
KeyProvider.invalidOpenKey()
public void reset()
protected Object cloneKey()
null
.
If the key is an array, a shallow copy of the array is
returned.
When overriding this method, please consider that the key
may be null
.
RuntimeException
- If cloning the key results in a runtime
exception.protected void resetKey()
null
.
If the key is an array, the array is filled with zero values
before setting the reference to null
.
When overwriting this method, please consider that the key
may be null
.
protected KeyProvider addToKeyManager(String resourceID) throws NullPointerException, IllegalStateException
KeyManager
.
The key manager will use this method whenever it adds a key provider
which is actually an instance of this class.
This allows subclasses to add additional behaviour or constraints
whenever an instance is mapped in the KeyManager
.
resourceID
- The resource identifier to map this instance for.
null
if no key provider was mapped.
NullPointerException
- If resourceID
is
null
.
IllegalStateException
- If mapping this instance is prohibited
by a constraint in a subclass.
Please refer to the respective subclass documentation for
more information about its constraint(s).protected KeyProvider removeFromKeyManager(String resourceID) throws NullPointerException, IllegalStateException
KeyManager
.
The key manager will use this method whenever it adds a key provider
which is actually an instance of this class.
This allows subclasses to add additional behaviour or constraints
whenever an instance is unmapped in the KeyManager
.
resourceID
- The resource identifier to unmap this instance from.
NullPointerException
- If resourceID
is
null
.
IllegalStateException
- If unmapping this instance is prohibited
by a constraint in a subclass.
Please refer to the respective subclass documentation for
more information about its constraint(s).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |