bibliothek.gui.dock.util
Class ResourceRequest<T>

java.lang.Object
  extended by bibliothek.gui.dock.util.ResourceRequest<T>
Type Parameters:
T - the kind of resource this ResourceRequest provides
Direct Known Subclasses:
DisplayerRequest, DockTitleRequest

public abstract class ResourceRequest<T>
extends Object

A ResourceRequest describes an algorithm for finding or creating a resource by calling a set of resource providers or factories in a specific order.

Author:
Benjamin Sigg

Constructor Summary
ResourceRequest()
           
 
Method Summary
 void answer(T resource)
          Informs this request that resource should be user.
protected abstract  void answer(T previousResource, T newResource)
          Called when the requested resource changed.
protected abstract  void executeRequestList()
          Asks all sources for a new resource, needs to stop as soon as one source called answer(Object) (this can be queried with isAnswered()).
 T getAnswer()
          Gets the last answer made to this request.
 boolean isAnswered()
          Tells whether answer(Object) was called since the last request().
protected  void request()
          Asks for a new resource and may trigger answer(Object, Object).
 void requestNull()
          Asks this request to simulate a call to request() which is answered with null
protected abstract  void validate(T resource)
          Called by answer(Object), this method ensure that resource is a valid answer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceRequest

public ResourceRequest()
Method Detail

answer

protected abstract void answer(T previousResource,
                               T newResource)
Called when the requested resource changed.

Parameters:
previousResource - the old resource object, may be null
newResource - the new resource object, may be null

request

protected void request()
Asks for a new resource and may trigger answer(Object, Object). This method is made protected, subclasses can expose it, or write another method requiering additional parameters, that calls this method.


isAnswered

public boolean isAnswered()
Tells whether answer(Object) was called since the last request().

Returns:
true if there is an answer

executeRequestList

protected abstract void executeRequestList()
Asks all sources for a new resource, needs to stop as soon as one source called answer(Object) (this can be queried with isAnswered()).


requestNull

public void requestNull()
Asks this request to simulate a call to request() which is answered with null


answer

public void answer(T resource)
Informs this request that resource should be user. This method can be called more than once to use different resources. Subclasses may put strict demands on what objects are valid resource objects. This method is not intended to be called in a generic way, callers must be aware of the restrictions a subclass requires. An answer must fulfill some rules:

Parameters:
resource - the new resource or null
Throws:
IllegalArgumentException - if the resource does not met the specifications a subclass requires
IllegalStateException - if request() is not currently executing

validate

protected abstract void validate(T resource)
Called by answer(Object), this method ensure that resource is a valid answer. The method throws an IllegalArgumentException if not.

Parameters:
resource - the resource to check
Throws:
IllegalArgumentException - if resource is not a valid resource

getAnswer

public T getAnswer()
Gets the last answer made to this request.

Returns:
the last answer, may be null