org.codehaus.plexus.component
Class ComponentIndex<V>

java.lang.Object
  extended by org.codehaus.plexus.component.ComponentIndex<V>

public class ComponentIndex<V>
extends java.lang.Object


Constructor Summary
ComponentIndex()
          Creates a component index that indexes by all super types and interfaces of supplied type.
ComponentIndex(boolean indexByAllTypes)
          Creates a component index.
 
Method Summary
 void add(java.lang.ClassLoader classLoader, java.lang.Class<?> type, java.lang.String roleHint, V value)
          Associate a value with the specified class loader, type and roleHint.
 java.util.Collection<V> clear()
          Removes all values from this index.
 V get(java.lang.Class<?> type, java.lang.String roleHint)
          Gets the value associated with the specified type and roleHint.
 V get(java.lang.Class<?> type, java.lang.String roleHint, java.lang.ClassLoader classLoader)
          Gets the value associated with the specified type and roleHint.
 java.util.Collection<V> getAll()
           
 java.util.List<V> getAll(java.lang.Class<?> type)
          Gets all values associated with the specified type.
 java.util.List<V> getAll(java.lang.Class<?> type, java.lang.ClassLoader classLoader)
          Gets all values associated with the specified type.
 java.util.Map<java.lang.String,V> getAllAsMap(java.lang.Class<?> type)
          Gets a map of all values associated with the specified type indexed by roleHint.
 java.util.Map<java.lang.String,V> getAllAsMap(java.lang.Class<?> type, java.lang.ClassLoader classLoader)
          Gets a map of all values associated with the specified type indexed by roleHint.
 boolean isIndexByAllTypes()
          Are values are indexed by all super types and interfaces of supplied type?
 void remove(V value)
          Removes the specified value from the index.
 java.util.List<V> removeAll(java.lang.ClassLoader classLoader)
          Removes all values associated with the specified class loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentIndex

public ComponentIndex()
Creates a component index that indexes by all super types and interfaces of supplied type.


ComponentIndex

public ComponentIndex(boolean indexByAllTypes)
Creates a component index.

Parameters:
indexByAllTypes - if true, values are indexed by all super types and interfaces of supplied type; otherwise values are only indexed by supplied type
Method Detail

isIndexByAllTypes

public boolean isIndexByAllTypes()
Are values are indexed by all super types and interfaces of supplied type?

Returns:
true, values are indexed by all super types and interfaces of supplied type; otherwise false and values are only indexed by supplied type

get

public V get(java.lang.Class<?> type,
             java.lang.String roleHint)
Gets the value associated with the specified type and roleHint. Values are searched for in classloader order starting from the thread context class loader or type class loader if thread context class loader is not set.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
roleHint - the roleHint associated with the value, or null for the default roleHint
Returns:
the value associated with the type and roleHint, or null

get

public V get(java.lang.Class<?> type,
             java.lang.String roleHint,
             java.lang.ClassLoader classLoader)
Gets the value associated with the specified type and roleHint. Values are searched for in classloader order starting from the specified class loader, or thread context class loader or type class loader if specified class loader is null.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
roleHint - the roleHint associated with the value, or null for the default roleHint
classLoader - the class loader to search from
Returns:
the value associated with the type and roleHint, or null

getAll

public java.util.Collection<V> getAll()

getAll

public java.util.List<V> getAll(java.lang.Class<?> type)
Gets all values associated with the specified type. Values are searched for in classloader order starting from the thread context class loader or type class loader if thread context class loader is not set. The values are sorted in class loader search order then by registration order.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
Returns:
all values associated with the type; never null

getAll

public java.util.List<V> getAll(java.lang.Class<?> type,
                                java.lang.ClassLoader classLoader)
Gets all values associated with the specified type. Values are searched for in classloader order starting from the specified class loader, or thread context class loader or type class loader if specified class loader is null. The values are sorted in class loader search order then by registration order.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
classLoader - the class loader to search from
Returns:
all values associated with the type; never null

getAllAsMap

public java.util.Map<java.lang.String,V> getAllAsMap(java.lang.Class<?> type)
Gets a map of all values associated with the specified type indexed by roleHint. Values are searched for in classloader order starting from the thread context class loader or type class loader if thread context class loader is not set.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
Returns:
all of the value associated with the type; never null

getAllAsMap

public java.util.Map<java.lang.String,V> getAllAsMap(java.lang.Class<?> type,
                                                     java.lang.ClassLoader classLoader)
Gets a map of all values associated with the specified type indexed by roleHint. Values are searched for in classloader order starting from the specified class loader, or thread context class loader or type class loader if specified class loader is null.

Parameters:
type - the type (or super type if enabled) associated with the value; not null
classLoader - the class loader to search from
Returns:
all of the value associated with the type; never null

add

public void add(java.lang.ClassLoader classLoader,
                java.lang.Class<?> type,
                java.lang.String roleHint,
                V value)
Associate a value with the specified class loader, type and roleHint. The value is also associated with all superclasses and interfaces of the specified type unless index by all types is disabled.


remove

public void remove(V value)
Removes the specified value from the index. This is operation requires a linear search of the whole index, and is therefor very expensive.

Parameters:
value - the value to remove

removeAll

public java.util.List<V> removeAll(java.lang.ClassLoader classLoader)
Removes all values associated with the specified class loader. This operation is very fast.


clear

public java.util.Collection<V> clear()
Removes all values from this index.



Copyright © 2001-2009 Codehaus. All Rights Reserved.