org.modeshape.repository
Class ModeShapeConfiguration

java.lang.Object
  extended by org.modeshape.repository.ModeShapeConfiguration
Direct Known Subclasses:
JcrConfiguration

@NotThreadSafe
public class ModeShapeConfiguration
extends Object

A configuration builder for a ModeShapeEngine. This class is an internal domain-specific language (DSL), and is designed to be used in a traditional way or in a method-chained manner:

 configuration.repositorySource("Source1").setClass(InMemoryRepositorySource.class).setDescription("description");
 configuration.mimeTypeDetector("detector").setClass(ExtensionBasedMimeTypeDetector.class).setDescription("default detector");
 configuration.sequencer("MicrosoftDocs")
              .setClass("org.modeshape.sequencer.msoffice.MSOfficeMetadataSequencer")
              .setDescription("Our primary sequencer for all .doc files")
              .sequencingFrom("/public//(*.(doc|xml|ppt)[*]/jcr:content[@jcr:data]")
              .andOutputtingTo("/documents/$1");
 configuration.save();
 


Nested Class Summary
protected static class ModeShapeConfiguration.BaseReturnable<ReturnType>
           
static interface ModeShapeConfiguration.ChooseClass<ComponentClassType,ReturnType>
          The interface used to configure the class used for a component.
protected static class ModeShapeConfiguration.ClusterBuilder<ReturnType>
           
static interface ModeShapeConfiguration.ClusterDefinition<ReturnType>
          Interface used to set up and define the cluster configuration.
static class ModeShapeConfiguration.ConfigurationDefinition
          Representation of the current configuration content.
protected static class ModeShapeConfiguration.GraphComponentBuilder<ReturnType,ThisType,ComponentType>
          Base class for ModeShapeConfiguration.Returnable types that work on a node in the graph.
protected static class ModeShapeConfiguration.GraphReturnable<ReturnType,ThisType>
          Base class for ModeShapeConfiguration.Returnable types that work on a node in the graph.
static interface ModeShapeConfiguration.HasName
          Interface for a component that has a name.
static interface ModeShapeConfiguration.LoadedFrom<ReturnType>
          Interface for specifying from where the component's class is to be loaded.
protected static class ModeShapeConfiguration.MimeTypeDetectorBuilder<ReturnType>
           
static interface ModeShapeConfiguration.MimeTypeDetectorDefinition<ReturnType>
          Interface used to set up and define a MIME type detector instance.
static interface ModeShapeConfiguration.PathExpressionOutput<ReturnType>
          Interface used to specify the output path expression for a sequencer configuration.
static interface ModeShapeConfiguration.Removable<ReturnType>
          Interface that defines the ability to remove the configuration component.
static interface ModeShapeConfiguration.RepositorySourceDefinition<ReturnType>
          Interface used to set up and define a RepositorySource instance.
static interface ModeShapeConfiguration.Returnable<ReturnType>
          Interface that defines the ability to obtain the configuration component.
protected static class ModeShapeConfiguration.SequencerBuilder<ReturnType>
           
static interface ModeShapeConfiguration.SequencerDefinition<ReturnType>
          Interface used to set up and define a sequencer instance.
static interface ModeShapeConfiguration.SetDescription<ReturnType>
          The interface used to set a description on a component.
static interface ModeShapeConfiguration.SetProperties<ReturnType>
          Interface for configuring the JavaBean-style properties of an object.
protected static class ModeShapeConfiguration.SourceBuilder<ReturnType>
           
 
Field Summary
static String DEFAULT_CONFIGURATION_SOURCE_NAME
           
static String DEFAULT_PATH
           
static String DEFAULT_WORKSPACE_NAME
           
 
Constructor Summary
ModeShapeConfiguration()
          Create a new configuration, using a default-constructed ExecutionContext.
ModeShapeConfiguration(ExecutionContext context)
          Create a new configuration using the supplied ExecutionContext.
 
Method Summary
 ModeShapeConfiguration and()
          Convenience method to make the code that sets up this configuration easier to read.
 ModeShapeEngine build()
          Construct an engine that reflects the current state of this configuration.
protected  Graph.Batch changes()
           
protected
<ReturnType extends ModeShapeConfiguration>
ModeShapeConfiguration.ClusterDefinition<ReturnType>
clusterDefinition(ReturnType returnObject)
          Utility method to construct a definition object for the clustering with the supplied name and return type.
 ModeShapeConfiguration.ClusterDefinition<? extends ModeShapeConfiguration> clustering()
          Obtain the definition for this engine's clustering.
protected  Graph configurationGraph()
           
 ModeShapeConfiguration.ConfigurationDefinition getConfigurationDefinition()
          Get the immutable representation of the information defining where the configuration content can be found.
protected  ExecutionContext getExecutionContext()
           
protected  ExecutionContext getExecutionContextForEngine()
          Utility method used by build() to get the ExecutionContext instance for the engine.
protected  Set<String> getNamesOfComponentsUnder(Name parentName)
           
 Problems getProblems()
          Get the problems (if any) that are associated with this configuration.
 boolean hasChanges()
          Determine if there are any unsaved changes to this configuration that must be saved before they take effect.
 ModeShapeConfiguration loadFrom(File configurationFile)
          Load the configuration from a file.
 ModeShapeConfiguration loadFrom(File configurationFile, String path)
          Load the configuration from a file.
 ModeShapeConfiguration loadFrom(InputStream configurationFileInputStream)
          Load the configuration from a file at the supplied URL.
 ModeShapeConfiguration loadFrom(InputStream configurationFileInputStream, String path)
          Load the configuration from a file at the supplied URL.
 ModeShapeConfiguration loadFrom(RepositorySource source)
          Load the configuration from the repository content using the supplied repository source.
 ModeShapeConfiguration loadFrom(RepositorySource source, String workspaceName)
          Load the configuration from the repository content using the workspace in the supplied repository source.
 ModeShapeConfiguration loadFrom(RepositorySource source, String workspaceName, String pathInWorkspace)
          Load the configuration from the repository content at the supplied path in the workspace in the supplied repository source.
 ModeShapeConfiguration loadFrom(String pathToConfigurationFile)
          Load the configuration from a file at the given path.
 ModeShapeConfiguration loadFrom(String pathToConfigurationFile, String path)
          Load the configuration from a file at the given path.
 ModeShapeConfiguration loadFrom(URL urlToConfigurationFile)
          Load the configuration from a file at the supplied URL.
 ModeShapeConfiguration loadFrom(URL urlToConfigurationFile, String path)
          Load the configuration from a file at the supplied URL.
 ModeShapeConfiguration.MimeTypeDetectorDefinition<? extends ModeShapeConfiguration> mimeTypeDetector(String name)
          Obtain or create a definition for the MIME type detector with the supplied name or identifier.
protected
<ReturnType extends ModeShapeConfiguration>
ModeShapeConfiguration.MimeTypeDetectorDefinition<ReturnType>
mimeTypeDetectorDefinition(ReturnType returnObject, String name)
          Utility method to construct a definition object for the detector with the supplied name and return type.
 Set<ModeShapeConfiguration.MimeTypeDetectorDefinition<? extends ModeShapeConfiguration>> mimeTypeDetectors()
          Get the list of MIME type detector definitions.
protected  Name name(String name)
           
protected  Path path()
           
protected  Path path(String path)
           
 ModeShapeConfiguration.RepositorySourceDefinition<? extends ModeShapeConfiguration> repositorySource(String name)
          Obtain or create a definition for the RepositorySource with the supplied name or identifier.
protected
<ReturnType extends ModeShapeConfiguration>
ModeShapeConfiguration.RepositorySourceDefinition<ReturnType>
repositorySourceDefinition(ReturnType returnObject, String name)
          Utility method to construct a definition object for the repository source with the supplied name and return type.
 Set<ModeShapeConfiguration.RepositorySourceDefinition<? extends ModeShapeConfiguration>> repositorySources()
          Get the list of repository source definitions.
 ModeShapeConfiguration save()
          Persist any unsaved changes that have been made to this configuration.
 ModeShapeConfiguration.SequencerDefinition<? extends ModeShapeConfiguration> sequencer(String name)
          Obtain or create a definition for the sequencer with the supplied name or identifier.
protected
<ReturnType extends ModeShapeConfiguration>
ModeShapeConfiguration.SequencerDefinition<ReturnType>
sequencerDefinition(ReturnType returnObject, String name)
          Utility method to construct a definition object for the sequencer with the supplied name and return type.
 Set<ModeShapeConfiguration.SequencerDefinition<? extends ModeShapeConfiguration>> sequencers()
          Get the list of sequencer definitions.
 void storeTo(ContentHandler handler)
          Traverse the saved configuration graph treating it as an XML document and calling the corresponding SAX event on the provided ContentHandler.
 void storeTo(File file)
          Store the saved configuration to the given file.
 void storeTo(OutputStream os)
          Store the saved configuration to the stream.
 void storeTo(String file)
          Store the saved configuration to the file with the given name.
 ModeShapeConfiguration withClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
          Specify the ClassLoaderFactory that should be used to load the classes for the various components.
 ModeShapeConfiguration withName(String name)
          Set the name of this configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WORKSPACE_NAME

public static final String DEFAULT_WORKSPACE_NAME
See Also:
Constant Field Values

DEFAULT_PATH

public static final String DEFAULT_PATH
See Also:
Constant Field Values

DEFAULT_CONFIGURATION_SOURCE_NAME

public static final String DEFAULT_CONFIGURATION_SOURCE_NAME
See Also:
Constant Field Values
Constructor Detail

ModeShapeConfiguration

public ModeShapeConfiguration()
Create a new configuration, using a default-constructed ExecutionContext.


ModeShapeConfiguration

public ModeShapeConfiguration(ExecutionContext context)
Create a new configuration using the supplied ExecutionContext.

Parameters:
context - the execution context
Throws:
IllegalArgumentException - if the path is null or empty
Method Detail

withName

public ModeShapeConfiguration withName(String name)
Set the name of this configuration.

Parameters:
name - the configuration name; may be null if the default name should be used
Returns:
this configuration

loadFrom

public ModeShapeConfiguration loadFrom(String pathToConfigurationFile)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the given path.

Parameters:
pathToConfigurationFile - the path the file containing the configuration information
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied location
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the path is null or empty

loadFrom

public ModeShapeConfiguration loadFrom(String pathToConfigurationFile,
                                       String path)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the given path.

Parameters:
pathToConfigurationFile - the path the file containing the configuration information
path - path within the content to the parent containing the configuration information, or null if the default path should be used
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied location
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the path is null or empty

loadFrom

public ModeShapeConfiguration loadFrom(File configurationFile)
                                throws IOException,
                                       SAXException
Load the configuration from a file.

Parameters:
configurationFile - the file containing the configuration information
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the supplied file
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the file reference is null

loadFrom

public ModeShapeConfiguration loadFrom(File configurationFile,
                                       String path)
                                throws IOException,
                                       SAXException
Load the configuration from a file.

Parameters:
configurationFile - the file containing the configuration information
path - path within the content to the parent containing the configuration information, or null if the default path should be used
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the supplied file
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the file reference is null

loadFrom

public ModeShapeConfiguration loadFrom(URL urlToConfigurationFile)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the supplied URL.

Parameters:
urlToConfigurationFile - the URL of the file containing the configuration information
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied URL
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the URL is null

loadFrom

public ModeShapeConfiguration loadFrom(URL urlToConfigurationFile,
                                       String path)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the supplied URL.

Parameters:
urlToConfigurationFile - the URL of the file containing the configuration information
path - path within the content to the parent containing the configuration information, or null if the default path should be used
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied URL
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the URL is null

loadFrom

public ModeShapeConfiguration loadFrom(InputStream configurationFileInputStream)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the supplied URL.

Parameters:
configurationFileInputStream - the stream with the configuration information
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied URL
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the stream is null

loadFrom

public ModeShapeConfiguration loadFrom(InputStream configurationFileInputStream,
                                       String path)
                                throws IOException,
                                       SAXException
Load the configuration from a file at the supplied URL.

Parameters:
configurationFileInputStream - the stream with the configuration information
path - path within the content to the parent containing the configuration information, or null if the default path should be used
Returns:
this configuration object, for convenience and method chaining
Throws:
IOException - if there is an error or problem reading the file at the supplied URL
SAXException - if the file is not a valid XML format
IllegalArgumentException - if the stream is null

loadFrom

public ModeShapeConfiguration loadFrom(RepositorySource source)
Load the configuration from the repository content using the supplied repository source. This method assumes that the supplied source has already been configured and is ready to create connections. Also, the default workspace of the source will be used, and the configuration content may be found directly under the root node.

Parameters:
source - the source that defines the repository with the configuration content
Returns:
this configuration object, for convenience and method chaining
Throws:
IllegalArgumentException - if the source is null

loadFrom

public ModeShapeConfiguration loadFrom(RepositorySource source,
                                       String workspaceName)
Load the configuration from the repository content using the workspace in the supplied repository source. This method assumes that the supplied source has already been configured and is ready to create connections. Also, the configuration content may be found directly under the root node.

Parameters:
source - the source that defines the repository with the configuration content
workspaceName - the name of the workspace with the configuration content, or null if the source's default workspace should be used
Returns:
this configuration object, for convenience and method chaining
Throws:
IllegalArgumentException - if the source is null

loadFrom

public ModeShapeConfiguration loadFrom(RepositorySource source,
                                       String workspaceName,
                                       String pathInWorkspace)
Load the configuration from the repository content at the supplied path in the workspace in the supplied repository source. This method assumes that the supplied source has already been configured and is ready to create connections.

Parameters:
source - the source that defines the repository with the configuration content
workspaceName - the name of the workspace with the configuration content, or null if the source's default workspace should be used
pathInWorkspace - the path to the parent node under which the configuration content may be found, or null if the content may be found under the root node
Returns:
this configuration object, for convenience and method chaining
Throws:
IllegalArgumentException - if the source is null

storeTo

public void storeTo(String file)
             throws SAXException,
                    IOException
Store the saved configuration to the file with the given name. Changes made without calling save() will not be written to the file.

Parameters:
file - the name of the file to which the configuration should be stored
Throws:
SAXException - if there is an error saving the configuration
IOException - if the file cannot be created or if there is an error writing the configuration to the file.

storeTo

public void storeTo(File file)
             throws SAXException,
                    IOException
Store the saved configuration to the given file. Changes made without calling save() will not be written to the file.

Parameters:
file - the name of the file to which the configuration should be stored
Throws:
SAXException - if there is an error saving the configuration
IOException - if the file cannot be created or if there is an error writing the configuration to the file.

storeTo

public void storeTo(OutputStream os)
             throws SAXException
Store the saved configuration to the stream. Changes made without calling save() will not be written to the stream.

Parameters:
os - the name of the file to which the configuration should be stored
Throws:
SAXException - if there is an error saving the configuration

storeTo

public void storeTo(ContentHandler handler)
             throws SAXException
Traverse the saved configuration graph treating it as an XML document and calling the corresponding SAX event on the provided ContentHandler. Changes made without calling save() will not be written to the stream.

Parameters:
handler - the content handler that will receive the SAX events
Throws:
SAXException - if there is an error saving the configuration

getConfigurationDefinition

public ModeShapeConfiguration.ConfigurationDefinition getConfigurationDefinition()
Get the immutable representation of the information defining where the configuration content can be found.

Returns:
the configuration definition

getExecutionContext

protected ExecutionContext getExecutionContext()

path

protected Path path()

path

protected Path path(String path)

name

protected Name name(String name)

getProblems

public Problems getProblems()
Get the problems (if any) that are associated with this configuration.

Returns:
the problems

configurationGraph

protected Graph configurationGraph()

changes

protected Graph.Batch changes()

hasChanges

public boolean hasChanges()
Determine if there are any unsaved changes to this configuration that must be saved before they take effect.

Returns:
true if a save() is required, or false no changes have been made to the configuration since the last save()

save

public ModeShapeConfiguration save()
Persist any unsaved changes that have been made to this configuration. This method has no effect if there are currently no unsaved changes.

Returns:
this configuration, for method chaining purposes

withClassLoaderFactory

public ModeShapeConfiguration withClassLoaderFactory(ClassLoaderFactory classLoaderFactory)
Specify the ClassLoaderFactory that should be used to load the classes for the various components. Most of the definitions can specify the classpath that should be used, and that classpath is passed to the supplied ClassLoaderFactory instance to obtain a ClassLoader for the class.

If not called, this configuration will use the class loader that loaded this configuration's class.

Parameters:
classLoaderFactory - the class loader factory implementation, or null if the classes should be loaded using the class loader of this object
Returns:
this configuration, for method chaining purposes

getNamesOfComponentsUnder

protected Set<String> getNamesOfComponentsUnder(Name parentName)

mimeTypeDetectors

public Set<ModeShapeConfiguration.MimeTypeDetectorDefinition<? extends ModeShapeConfiguration>> mimeTypeDetectors()
Get the list of MIME type detector definitions.

Returns:
the unmodifiable set of definitions; never null but possibly empty if there are no definitions

repositorySources

public Set<ModeShapeConfiguration.RepositorySourceDefinition<? extends ModeShapeConfiguration>> repositorySources()
Get the list of repository source definitions.

Returns:
the unmodifiable set of definitions; never null but possibly empty if there are no definitions

sequencers

public Set<ModeShapeConfiguration.SequencerDefinition<? extends ModeShapeConfiguration>> sequencers()
Get the list of sequencer definitions.

Returns:
the unmodifiable set of definitions; never null but possibly empty if there are no definitions

mimeTypeDetector

public ModeShapeConfiguration.MimeTypeDetectorDefinition<? extends ModeShapeConfiguration> mimeTypeDetector(String name)
Obtain or create a definition for the MIME type detector with the supplied name or identifier. A new definition will be created if there currently is no MIME type detector defined with the supplied name.

Parameters:
name - the name or identifier of the detector
Returns:
the details of the MIME type detector definition; never null

repositorySource

public ModeShapeConfiguration.RepositorySourceDefinition<? extends ModeShapeConfiguration> repositorySource(String name)
Obtain or create a definition for the RepositorySource with the supplied name or identifier. A new definition will be created if there currently is no repository source defined with the supplied name.

Parameters:
name - the name or identifier of the repository source
Returns:
the details of the repository source definition; never null

sequencer

public ModeShapeConfiguration.SequencerDefinition<? extends ModeShapeConfiguration> sequencer(String name)
Obtain or create a definition for the sequencer with the supplied name or identifier. A new definition will be created if there currently is no sequencer defined with the supplied name.

Parameters:
name - the name or identifier of the sequencer
Returns:
the details of the sequencer definition; never null

clustering

public ModeShapeConfiguration.ClusterDefinition<? extends ModeShapeConfiguration> clustering()
Obtain the definition for this engine's clustering. If no clustering definition exists, one will be created.

Returns:
the clustering definition; never null

and

public ModeShapeConfiguration and()
Convenience method to make the code that sets up this configuration easier to read. This method simply returns this object.

Returns:
this configuration component; never null

build

public ModeShapeEngine build()
Construct an engine that reflects the current state of this configuration. This method always creates a new instance.

Returns:
the resulting engine; never null
See Also:
getExecutionContextForEngine()

getExecutionContextForEngine

protected ExecutionContext getExecutionContextForEngine()
Utility method used by build() to get the ExecutionContext instance for the engine. This method gives subclasses the ability to override this behavior.

Currently, this method wraps the configuration's execution context to provide backward-compability with JBoss DNA namespaces. See MODE-647 for details.

Returns:
the execution context to be used for the engine
See Also:
build()

mimeTypeDetectorDefinition

protected <ReturnType extends ModeShapeConfiguration> ModeShapeConfiguration.MimeTypeDetectorDefinition<ReturnType> mimeTypeDetectorDefinition(ReturnType returnObject,
                                                                                                                                               String name)
Utility method to construct a definition object for the detector with the supplied name and return type.

Type Parameters:
ReturnType - the type of the return object
Parameters:
returnObject - the return object
name - the name of the detector
Returns:
the definition for the detector

repositorySourceDefinition

protected <ReturnType extends ModeShapeConfiguration> ModeShapeConfiguration.RepositorySourceDefinition<ReturnType> repositorySourceDefinition(ReturnType returnObject,
                                                                                                                                               String name)
Utility method to construct a definition object for the repository source with the supplied name and return type.

Type Parameters:
ReturnType - the type of the return object
Parameters:
returnObject - the return object
name - the name of the repository source
Returns:
the definition for the repository source

sequencerDefinition

protected <ReturnType extends ModeShapeConfiguration> ModeShapeConfiguration.SequencerDefinition<ReturnType> sequencerDefinition(ReturnType returnObject,
                                                                                                                                 String name)
Utility method to construct a definition object for the sequencer with the supplied name and return type.

Type Parameters:
ReturnType - the type of the return object
Parameters:
returnObject - the return object
name - the name of the sequencer
Returns:
the definition for the sequencer

clusterDefinition

protected <ReturnType extends ModeShapeConfiguration> ModeShapeConfiguration.ClusterDefinition<ReturnType> clusterDefinition(ReturnType returnObject)
Utility method to construct a definition object for the clustering with the supplied name and return type.

Type Parameters:
ReturnType - the type of the return object
Parameters:
returnObject - the return object
Returns:
the definition for the clustering; never null


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.