|
org.openide.util 6.8.31 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openide.util.lookup.Lookups
public class Lookups
Static factory methods for creating common lookup implementations.
Method Summary | |
---|---|
static Lookup |
exclude(Lookup lookup,
Class[] classes)
Creates a lookup that wraps another one and filters out instances of specified classes. |
static Lookup |
fixed(Object[] objectsToLookup)
Creates a lookup that contains an array of objects specified via the parameter. |
static Lookup |
fixed(Object[] keys,
InstanceContent.Convertor convertor)
Creates a lookup that contains an array of objects specified via the parameter. |
static Lookup.Item |
lookupItem(Object instance,
String id)
Creates Lookup.Item representing the instance passed in. |
static Lookup |
metaInfServices(ClassLoader classLoader)
Returns a lookup that implements the JDK1.3 JAR services mechanism and delegates to META-INF/services/name.of.class files. |
static Lookup |
proxy(Lookup.Provider provider)
Creates a lookup that delegates to another one but that one can change from time to time. |
static Lookup |
singleton(Object objectToLookup)
Creates a singleton lookup. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Lookup singleton(Object objectToLookup)
NullPointerException
- if the supplied argument is nullpublic static Lookup fixed(Object[] objectsToLookup)
NullPointerException
- if the supplied argument is nullpublic static Lookup fixed(Object[] keys, InstanceContent.Convertor convertor)
NullPointerException
- if the any of the arguments is nullpublic static Lookup proxy(Lookup.Provider provider)
lookup
or lookupItem
method whether the
provider still returns the same lookup. If not, it updates state of
all Lookup.Result
s that it created (and that still exists).
The user of this method has to implement its provider's getLookup
method (must be thread safe and fast, will be called often and from any thread)
pass it to this method and use the returned lookup. Whenever the user
changes the return value from the getLookup
method and wants
to notify listeners on the lookup about that it should trigger the event
firing, for example by calling lookup.lookup (Object.class)
that forces check of the return value of getLookup
.
provider
- the provider that returns a lookup to delegate to
public static Lookup metaInfServices(ClassLoader classLoader)
Note: It is not dynamic - so if you need to change the classloader or JARs,
wrap it in a ProxyLookup
and change the delegate when necessary.
Existing instances will be kept if the implementation classes are unchanged,
so there is "stability" in doing this provided some parent loaders are the same
as the previous ones.
public static Lookup exclude(Lookup lookup, Class[] classes)
l = Lookups.exclude (lookup, new Class[] { ActionMap.class });Then anybody who asks for
l.lookup (ActionMap.class)
or
subclass will get null
. Even if the original lookup contains the
value.
To create empty lookup (well, just an example, otherwise use Lookup.EMPTY
) one could use:
Lookup.exclude (anyLookup, new Class[] { Object.class });as any instance in any lookup is of type Object and thus would be excluded.
The complete behaviour can be described as classes
being
a barrier. For an object not to be excluded, there has to be an inheritance
path between the queried class and the actual class of the instance,
that is not blocked by any of the excluded classes:
interface A {} interface B {} class C implements A, B {} Object c = new C(); Lookup l1 = Lookups.singleton(c); Lookup l2 = Lookups.exclude(l1, new Class[] {A.class}); assertNull("A is directly excluded", l2.lookup(A.class)); assertEquals("Returns C as A.class is not between B and C", c, l2.lookup(B.class));For more info check the excluding lookup tests and the discussion in issue 53058.
lookup
- the original lookup that should be filteredclasses
- array of classes those instances should be excludedpublic static Lookup.Item lookupItem(Object instance, String id)
Lookup.Item
representing the instance passed in.
instance
- the object for which Lookup.Item should be cretedid
- unique identification of the object, for details see Lookup.Item.getId()
,
can be null
|
org.openide.util 6.8.31 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |