net.sf.taverna.raven.spi
Class SpiRegistry

java.lang.Object
  extended by net.sf.taverna.raven.spi.SpiRegistry
All Implemented Interfaces:
java.lang.Iterable<java.lang.Class>, ArtifactFilterListener

public class SpiRegistry
extends java.lang.Object
implements java.lang.Iterable<java.lang.Class>, ArtifactFilterListener

A typed registry of implementations of a particular Service Provider Interface (SPI). Discovery of these implementations is done using a similar mechanism to that employed by the Apache project commons-discovery that is to say a search for resources within known jar archives for META-INF/services/

Author:
Tom Oinn

Constructor Summary
SpiRegistry(Repository r, java.lang.String classname, java.lang.ClassLoader parentLoader)
          Create a new SpiRegistry based on a particular repository and searching for the specified SPI classname.
 
Method Summary
 void addFilter(ArtifactFilter af)
          Add a new ArtifactFilter
 void addNewArtifact(Artifact a)
           
 void addRegistryListener(RegistryListener l)
          Add a new registry listener to be notified of any updates to this SpiRegistry
 void clearFilters()
          Clear all ArtifactFilter objects
 void filterChanged(ArtifactFilter filter)
           
 void finalize()
           
 java.util.List<java.lang.Class> getClasses()
          Get the Class objects for all implementations of this SPI currently known
 java.lang.String getClassName()
          The class name for the registry to search over
 java.util.Iterator<java.lang.Class> iterator()
           
 void removeRegistryListener(RegistryListener l)
          Remove a listener from this SpiRegistry
 void setFilters(java.util.List<ArtifactFilter> newFilters)
          Set the filter list
 void updateRegistry()
          Apply all filters to the set of new artifacts in turn, then for each Artifact which passes all the filters see if it contains a service entry for the SPI we're meant to be looking after.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpiRegistry

public SpiRegistry(Repository r,
                   java.lang.String classname,
                   java.lang.ClassLoader parentLoader)
Create a new SpiRegistry based on a particular repository and searching for the specified SPI classname. Note that no scan for implementations is done at this point to allow interested parties to register SpiListener instances first.

Parameters:
r - the Repository which will be used to locate implementations of the SPI
classname - of the SPI to search for
parentLoader - a ClassLoader to use as the parent for any entries loaded here, or null for no parent (most likely behaviour is to leave as null)
Method Detail

addFilter

public void addFilter(ArtifactFilter af)
Add a new ArtifactFilter


addNewArtifact

public void addNewArtifact(Artifact a)

addRegistryListener

public void addRegistryListener(RegistryListener l)
Add a new registry listener to be notified of any updates to this SpiRegistry

Parameters:
l -

clearFilters

public void clearFilters()
Clear all ArtifactFilter objects


filterChanged

public void filterChanged(ArtifactFilter filter)
Specified by:
filterChanged in interface ArtifactFilterListener

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

getClasses

public java.util.List<java.lang.Class> getClasses()
Get the Class objects for all implementations of this SPI currently known


getClassName

public java.lang.String getClassName()
The class name for the registry to search over


iterator

public java.util.Iterator<java.lang.Class> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.Class>

removeRegistryListener

public void removeRegistryListener(RegistryListener l)
Remove a listener from this SpiRegistry

Parameters:
l -

setFilters

public void setFilters(java.util.List<ArtifactFilter> newFilters)
Set the filter list


updateRegistry

public void updateRegistry()
Apply all filters to the set of new artifacts in turn, then for each Artifact which passes all the filters see if it contains a service entry for the SPI we're meant to be looking after. If it does then parse the entry and extract the list of implementation classnames. Class objects corresponding to these are then added to the set of current known implementations.