net.sf.taverna.raven.spi
Class Profile

java.lang.Object
  extended by net.sf.taverna.raven.spi.AbstractArtifactFilter
      extended by net.sf.taverna.raven.spi.Profile
All Implemented Interfaces:
ArtifactFilter

public class Profile
extends AbstractArtifactFilter

A Profile in this context is a set of Artifacts that are known to work in conjunction with one another. With Raven's ability to deploy components at runtime and update in a very fine grained manner the issue of support can become tangled, the potential variety of coexisting (and therefore possibly interacting) software components may cause incompatibilities that are only apparent at runtime. For this reason some organisations such as OMII-UK may with to provide a 'blessed' combination of component versions which have had some level of integration testing within their host environment.

The profile is held and distributed in the form of an XML file with the following structure:

  <profile>
    <artifact groupId="..." artifactId="..." version="..."/>
    ...
  </profile>
 
Note that as this is only used by the SPI mechanism there is no need to include dependencies of these artifacts, the only entries required are those which directly contain SPI implementations

Author:
Tom Oinn, Stian Soiland-Reyes

Constructor Summary
Profile(boolean strict)
           
Profile(java.io.InputStream is, boolean strict)
          Create a Profile and initialize it from the specified InputStream of XML (see class description)
 
Method Summary
 void addArtifact(Artifact artifact)
          Allow an artifact to be added to the profile at runtime
 void addArtifactsForPlugins(java.io.InputStream pluginsDefinitionStream)
          Adds artifacts contains in the profile definition for a Plugin.
 void addSystemArtifact(Artifact artifact)
           
 Artifact discoverArtifact(java.lang.String groupId, java.lang.String artifactId)
          Select the highest version Artifact defined in the registry that fits the artifactId and groupId.
 Artifact discoverArtifact(java.lang.String groupId, java.lang.String artifactId, Repository repository)
          Select the highest version Artifact defined in the registry that fits the artifactId and groupId.
 java.util.Set<Artifact> filter(java.util.Set<Artifact> intersecting)
          Return the intersection of the set of Artifacts in this Profile and that presented to this method if strict is true, otherwise return the intersection plus all artifacts in the set which have no match within the profile when only groupId and artifactId are taken into account.
 java.util.Set<Artifact> getArtifacts()
          Get the artifacts that forms part of this profile.
 java.lang.String getName()
          Return the name of the profile, or null if no name is defined
 java.util.Set<Artifact> getSystemArtifacts()
          Get the subset of getArtifacts() that is marked as being system artifacts by this profile.
 java.lang.String getVersion()
          Return the version string of the Profile, or 'NO VERSION' if a version is not defined
 void removeArtifact(Artifact artifact)
          Allow an artifact to be removed from the profile at runtime
 void removeSystemArtifact(Artifact artifact)
           
 void write(java.io.OutputStream outputStream)
          Generate the XML representation of this profile, write to given output stream.
 
Methods inherited from class net.sf.taverna.raven.spi.AbstractArtifactFilter
addArtifactFilterListener, removeArtifactFilterListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Profile

public Profile(boolean strict)

Profile

public Profile(java.io.InputStream is,
               boolean strict)
        throws InvalidProfileException
Create a Profile and initialize it from the specified InputStream of XML (see class description)

If the strict setting is set to true then the filter operation is a straight set intersection of the set to be filtered and the set of artifacts within this profile. If false then the behaviour is slightly more complex - an artifact is allowed through the filter if either all three fields (groupId, artifactId and version) match or there are no matches on the groupId and artifactId pair. This effectively allows through components which are unknown to the profile and can be used to compose the union of multiple profiles by adding each one to the filter chain in turn.

Parameters:
is - InputStream to read XML from
strict - only allows exact matches to the profile through if true, if false then artifacts which don't exist in the profile in any version will be allowed through.
Throws:
InvalidProfileException - if there is any problem reading or parsing the profile XML.
Method Detail

addArtifact

public void addArtifact(Artifact artifact)
Allow an artifact to be added to the profile at runtime

Parameters:
artifact -

addArtifactsForPlugins

public void addArtifactsForPlugins(java.io.InputStream pluginsDefinitionStream)
Adds artifacts contains in the profile definition for a Plugin. These need to be added early in the startup process so that system artifacts get added to the correct classloader. It also prevents a long delay between the splash screen and the workbench appearing when first initialising default plugins.

Parameters:
pluginsDefinitionStream -

addSystemArtifact

public void addSystemArtifact(Artifact artifact)

discoverArtifact

public Artifact discoverArtifact(java.lang.String groupId,
                                 java.lang.String artifactId)
Select the highest version Artifact defined in the registry that fits the artifactId and groupId. Useful for allowing artifacts to be defined without version with the profile dictating the version to be used.

Versions are compared as described in VersionComparator.

Parameters:
groupId -
artifactId -
Returns:
the Artifact or null if not found
See Also:
VersionComparator

discoverArtifact

public Artifact discoverArtifact(java.lang.String groupId,
                                 java.lang.String artifactId,
                                 Repository repository)
Select the highest version Artifact defined in the registry that fits the artifactId and groupId. Useful for allowing artifacts to be defined without version with the profile dictating the version to be used.

Versions are compared as described in VersionComparator.

Parameters:
groupId -
artifactId -
repository - Repository to use for finding nested dependencies
Returns:
the Artifact or null if not found
See Also:
VersionComparator

filter

public java.util.Set<Artifact> filter(java.util.Set<Artifact> intersecting)
Return the intersection of the set of Artifacts in this Profile and that presented to this method if strict is true, otherwise return the intersection plus all artifacts in the set which have no match within the profile when only groupId and artifactId are taken into account.

Parameters:
intersecting - List of Artifacts to filter
Returns:
filtered list of Artifact objects

getArtifacts

public java.util.Set<Artifact> getArtifacts()
Get the artifacts that forms part of this profile.

Returns:
a copy of the internal Set of Artifact.

getName

public java.lang.String getName()
Return the name of the profile, or null if no name is defined


getSystemArtifacts

public java.util.Set<Artifact> getSystemArtifacts()
Get the subset of getArtifacts() that is marked as being system artifacts by this profile. A system artifact is supposed to be added by PreLauncher.addURLToClassPath(java.net.URL) and thereby available even to artifacts that don't declare it as a dependency. This is mainly useful for global XML parsers and similar implementations that are discovered by non-Raven SPIs.

Returns:
a copy of the internal Set of system Artifacts

getVersion

public java.lang.String getVersion()
Return the version string of the Profile, or 'NO VERSION' if a version is not defined


removeArtifact

public void removeArtifact(Artifact artifact)
Allow an artifact to be removed from the profile at runtime

Parameters:
artifact -

removeSystemArtifact

public void removeSystemArtifact(Artifact artifact)

write

public void write(java.io.OutputStream outputStream)
           throws javax.xml.parsers.ParserConfigurationException,
                  javax.xml.transform.TransformerFactoryConfigurationError,
                  javax.xml.transform.TransformerException
Generate the XML representation of this profile, write to given output stream.

Parameters:
outputStream - Stream to output profile as XML.
Throws:
javax.xml.parsers.ParserConfigurationException - If a DocumentBuilder could not be created
javax.xml.transform.TransformerFactoryConfigurationError - If a Transformer could not be created
javax.xml.transform.TransformerException - If the XML document could not be transformed