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
static interface ModeShapeConfiguration.ChooseClass<ComponentClassType,ReturnType>
          The interface used to configure the class used for a component.
static class ModeShapeConfiguration.ConfigurationDefinition
          Representation of the current configuration content.
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.
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.
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.
 
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.
 ModeShapeConfiguration.ConfigurationDefinition getConfigurationDefinition()
          Get the immutable representation of the information defining where the configuration content can be found.
 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.
 Set<ModeShapeConfiguration.MimeTypeDetectorDefinition<? extends ModeShapeConfiguration>> mimeTypeDetectors()
          Get the list of MIME type detector definitions.
 ModeShapeConfiguration.RepositorySourceDefinition<? extends ModeShapeConfiguration> repositorySource(String name)
          Obtain or create a definition for the RepositorySource with the supplied name or identifier.
 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.
 Set<ModeShapeConfiguration.SequencerDefinition<? extends ModeShapeConfiguration>> sequencers()
          Get the list of sequencer definitions.
 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
equals, 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

getConfigurationDefinition

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

Returns:
the configuration definition

getProblems

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

Returns:
the problems

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

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

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()


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