org.openide.util.lookup
Class AbstractLookup

java.lang.Object
  extended by org.openide.util.Lookup
      extended by org.openide.util.lookup.AbstractLookup
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MetaInfServicesLookup

public class AbstractLookup
extends Lookup
implements java.io.Serializable

Implementation of the lookup from OpenAPIs that is based on the introduction of Item. This class should provide the default way of how to store (Class, Object) pairs in the lookups. It offers protected methods for subclasses to register the pairs.

Serializable since 3.27.

Since:
1.9
Author:
Jaroslav Tulach
See Also:
Serialized Form

Nested Class Summary
static class AbstractLookup.Content
          A class that can be used by the creator of the AbstractLookup to control its content.
(package private) static class AbstractLookup.Info
          Just a holder for index & modified values.
(package private) static class AbstractLookup.ISE
          Signals that a lookup is being modified from a lookup query.
static class AbstractLookup.Pair<T>
          Extension to the default lookup item that offers additional information for the data structures use in AbstractLookup
(package private) static class AbstractLookup.R<T>
          Result based on one instance returned.
(package private) static class AbstractLookup.ReferenceIterator
          Supporting class to iterate over linked list of ReferenceToResult Use:
(package private) static class AbstractLookup.ReferenceToResult<T>
          Reference to a result R
(package private) static interface AbstractLookup.Storage<Transaction>
          Storage to keep the internal structure of Pairs and to answer different queries.
 
Nested classes/interfaces inherited from class org.openide.util.Lookup
Lookup.Item<T>, Lookup.Provider, Lookup.Result<T>, Lookup.Template<T>
 
Field Summary
(package private) static long serialVersionUID
           
 
Fields inherited from class org.openide.util.Lookup
EMPTY
 
Constructor Summary
protected AbstractLookup()
          Default constructor for subclasses that do not need to provide a content
  AbstractLookup(AbstractLookup.Content content)
          Constructor to create this lookup and associate it with given Content.
(package private) AbstractLookup(AbstractLookup.Content content, AbstractLookup.Storage<?> storage)
          Constructor for testing purposes that allows specification of storage as mechanism as well.
(package private) AbstractLookup(AbstractLookup.Content content, java.lang.Integer trashhold)
          Constructor for testing purposes that allows specification of storage as mechanism as well.
 
Method Summary
protected  void addPair(AbstractLookup.Pair<?> pair)
          The method to add instance to the lookup with.
protected  void beforeLookup(Lookup.Template<?> template)
          Notifies subclasses that a query is about to be processed.
(package private)
<T> boolean
cleanUpResult(Lookup.Template<T> template)
          Method to be called when a result is cleared to signal that the list of all result should be checked for clearing.
(package private)  java.util.LinkedHashSet<AbstractLookup.Pair<?>> getPairsAsLHS()
          Getter for set of pairs.
protected  void initialize()
          Method for subclasses to initialize them selves.
<T> T
lookup(java.lang.Class<T> clazz)
          Look up an object matching a given interface.
<T> Lookup.Result<T>
lookup(Lookup.Template<T> template)
          The general lookup method.
<T> Lookup.Item<T>
lookupItem(Lookup.Template<T> template)
          Look up the first item matching a given template.
(package private) static boolean matches(Lookup.Template<?> t, AbstractLookup.Pair<?> item, boolean deepCheck)
          A method that defines matching between Item and Template.
(package private) static java.lang.Object modifyListenerList(boolean add, LookupListener l, java.lang.Object ref)
          Generic support for listeners, so it can be used in other results as well.
(package private)  void notifyCollectedListeners(java.util.Set<AbstractLookup.R> listeners)
          Notifies all collected listeners.
(package private) static void notifyListeners(java.lang.Object[] listeners, LookupEvent ev, java.util.Collection<java.lang.Object> evAndListeners)
          Call resultChanged on all listeners.
protected  void removePair(AbstractLookup.Pair<?> pair)
          Remove instance.
protected  void setPairs(java.util.Collection<? extends AbstractLookup.Pair> collection)
          Changes all pairs in the lookup to new values.
(package private)
<Transaction>
java.util.HashSet<AbstractLookup.R>
setPairsAndCollectListeners(java.util.Collection<? extends AbstractLookup.Pair> collection)
          Collects listeners without notification.
 java.lang.String toString()
           
 
Methods inherited from class org.openide.util.Lookup
getDefault, lookupAll, lookupResult
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

AbstractLookup

public AbstractLookup(AbstractLookup.Content content)
Constructor to create this lookup and associate it with given Content. The content than allows the creator to invoke protected methods which are not accessible for any other user of the lookup.

Parameters:
content - the content to assciate with
Since:
1.25

AbstractLookup

AbstractLookup(AbstractLookup.Content content,
               AbstractLookup.Storage<?> storage)
Constructor for testing purposes that allows specification of storage as mechanism as well.


AbstractLookup

AbstractLookup(AbstractLookup.Content content,
               java.lang.Integer trashhold)
Constructor for testing purposes that allows specification of storage as mechanism as well.

Parameters:
trashhold - number of Pair to "remain small"

AbstractLookup

protected AbstractLookup()
Default constructor for subclasses that do not need to provide a content

Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

initialize

protected void initialize()
Method for subclasses to initialize them selves.


beforeLookup

protected void beforeLookup(Lookup.Template<?> template)
Notifies subclasses that a query is about to be processed.

Parameters:
template - the template

addPair

protected final void addPair(AbstractLookup.Pair<?> pair)
The method to add instance to the lookup with.

Parameters:
pair - class/instance pair

removePair

protected final void removePair(AbstractLookup.Pair<?> pair)
Remove instance.

Parameters:
pair - class/instance pair

setPairs

protected final void setPairs(java.util.Collection<? extends AbstractLookup.Pair> collection)
Changes all pairs in the lookup to new values.

Parameters:
collection - the collection of (Pair) objects

getPairsAsLHS

final java.util.LinkedHashSet<AbstractLookup.Pair<?>> getPairsAsLHS()
Getter for set of pairs. Package private contract with MetaInfServicesLookup.

Returns:
a LinkedHashSet that can be modified

setPairsAndCollectListeners

final <Transaction> java.util.HashSet<AbstractLookup.R> setPairsAndCollectListeners(java.util.Collection<? extends AbstractLookup.Pair> collection)
Collects listeners without notification. Needed in MetaInfServicesLookup right now, but maybe will become an API later.


notifyCollectedListeners

final void notifyCollectedListeners(java.util.Set<AbstractLookup.R> listeners)
Notifies all collected listeners. Needed by MetaInfServicesLookup, maybe it will be an API later.


lookup

public final <T> T lookup(java.lang.Class<T> clazz)
Description copied from class: Lookup
Look up an object matching a given interface. This is the simplest method to use. If more than one object matches, the first will be returned. The template class may be a class or interface; the instance is guaranteed to be assignable to it.

Specified by:
lookup in class Lookup
Parameters:
clazz - class of the object we are searching for
Returns:
an object implementing the given class or null if no such implementation is found

lookupItem

public final <T> Lookup.Item<T> lookupItem(Lookup.Template<T> template)
Description copied from class: Lookup
Look up the first item matching a given template. Includes not only the instance but other associated information.

Overrides:
lookupItem in class Lookup
Parameters:
template - the template to check
Returns:
a matching item or null

lookup

public final <T> Lookup.Result<T> lookup(Lookup.Template<T> template)
Description copied from class: Lookup
The general lookup method. Callers can get list of all instances and classes that match the given template, request more info about them in form of Lookup.Item and attach a listener to this be notified about changes. The general interface does not specify whether subsequent calls with the same template produce new instance of the Lookup.Result or return shared instance. The prefered behaviour however is to return shared one.

Specified by:
lookup in class Lookup
Parameters:
template - a template describing the services to look for
Returns:
an object containing the results

notifyListeners

static void notifyListeners(java.lang.Object[] listeners,
                            LookupEvent ev,
                            java.util.Collection<java.lang.Object> evAndListeners)
Call resultChanged on all listeners.

Parameters:
listeners - array of listeners in the format used by javax.swing.EventListenerList. It means that there are Class objects on even positions and the listeners on odd positions
ev - the event to fire

matches

static boolean matches(Lookup.Template<?> t,
                       AbstractLookup.Pair<?> item,
                       boolean deepCheck)
A method that defines matching between Item and Template.

Parameters:
t - template providing the criteria
item - the item to match
deepCheck - true if type of the pair should be tested, false if it is already has been tested
Returns:
true if item matches the template requirements, false if not

cleanUpResult

<T> boolean cleanUpResult(Lookup.Template<T> template)
Method to be called when a result is cleared to signal that the list of all result should be checked for clearing.

Parameters:
template - the template the result was for
Returns:
true if the hash map with all items has been cleared

modifyListenerList

static java.lang.Object modifyListenerList(boolean add,
                                           LookupListener l,
                                           java.lang.Object ref)
Generic support for listeners, so it can be used in other results as well.

Parameters:
add - true to add it, false to modify
l - listener to modify
ref - the value of the reference to listener or listener list
Returns:
new value to the reference to listener or list