public abstract class Sequencer extends Object
Each ModeShape repository can be configured with zero or more sequencers. Each sequencer is configured with a set of match conditions that define the acceptable patterns for the paths of changed nodes, as well as a path specification that defines where the derived (or generated) output should be placed. Then when clients change nodes with paths that satisfy the match conditions, the repository will create a new Session and invoke the sequencer, which is then expected to process the changed content and generate the derived information under the supplied parent node. The session will be saved automatically or, if an exception is thrown, discard the changes and close the session.
Modifier and Type | Class and Description |
---|---|
static interface |
Sequencer.Context
The sequencer context represents the complete context of a sequencer invocation.
|
Constructor and Description |
---|
Sequencer() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
execute(Property inputProperty,
Node outputNode,
Sequencer.Context context)
Execute the sequencing operation on the specified property, which has recently been created or changed.
|
protected Set<String> |
getAcceptedMimeTypes()
Utility method to obtain the set of accepted MIME types.
|
protected Logger |
getLogger() |
String |
getName()
Get the name for this sequencer.
|
String[] |
getPathExpressions()
Obtain the path expressions as configured on the sequencer.
|
String |
getRepositoryName()
Get the name of the repository.
|
UUID |
getUniqueId()
Return the unique identifier for this sequencer.
|
boolean |
hasAcceptedMimeTypes()
Determine if this sequencer requires the content to have a specific MIME type
|
void |
initialize(NamespaceRegistry registry,
NodeTypeManager nodeTypeManager)
Initialize the sequencer.
|
boolean |
isAccepted(String mimeType)
Determine if this sequencer has been configured to accept and process content with the supplied MIME type.
|
protected void |
registerDefaultMimeTypes(String... mimeTypes)
Set the MIME types that are accepted by default, if there are any.
|
protected boolean |
registerNamespace(String namespacePrefix,
String namespaceUri,
NamespaceRegistry namespaceRegistry)
Registers a namespace using the given
NamespaceRegistry , if the namespace has not been previously registered. |
protected void |
registerNodeTypes(InputStream cndStream,
NodeTypeManager nodeTypeManager,
boolean allowUpdate)
|
protected void |
registerNodeTypes(String cndFile,
NodeTypeManager nodeTypeManager,
boolean allowUpdate)
Registers node types from a CND file, using the given
NodeTypeManager . |
String |
toString() |
public final UUID getUniqueId()
public final String getName()
public final String getRepositoryName()
public final String[] getPathExpressions()
public void initialize(NamespaceRegistry registry, NodeTypeManager nodeTypeManager) throws RepositoryException, IOException
By default this method does nothing, so it should be overridden by implementations to do a one-time initialization of any
internal components. For example, sequencers can use the supplied registry
and nodeTypeManager
objects to register custom namesapces and node types required by the generated content.
registry
- the namespace registry that can be used to register custom namespaces; never nullnodeTypeManager
- the node type manager that can be used to register custom node types; never nullRepositoryException
- if operations on the NamespaceRegistry
or NodeTypeManager
failIOException
- if any stream based operations fail (like importing cnd files)public abstract boolean execute(Property inputProperty, Node outputNode, Sequencer.Context context) throws Exception
Each sequencer is expected to process the value of the property, extract information from the value, and write a structured representation (in the form of a node or a subgraph of nodes) using the supplied output node. Note that the output node will either be:
Node.setPrimaryType(String)
)The implementation is expected to always clean up all resources that it acquired, even in the case of exceptions.
Note: This method must be threadsafe: ModeShape will likely invoke this method concurrently in separate threads,
and the method should never modify the state or fields of the Sequencer implementation class. All initialization should be
performed in initialize(NamespaceRegistry, NodeTypeManager)
.
inputProperty
- the property that was changed and that should be used as the input; never nulloutputNode
- the node that represents the output for the derived information; never null, and will either be
new
if the output is being placed outside of the selected node, or will not be new when the
output is to be placed on the selected input nodecontext
- the context in which this sequencer is executing, and which may contain additional parameters useful when
generating the output structure; never nullException
- if there was a problem with the sequencer that could not be handled. All exceptions will be logged
automatically as errors by ModeShape.protected boolean registerNamespace(String namespacePrefix, String namespaceUri, NamespaceRegistry namespaceRegistry) throws RepositoryException
NamespaceRegistry
, if the namespace has not been previously registered.namespacePrefix
- a non-null String
namespaceUri
- a non-null String
namespaceRegistry
- a NamespaceRegistry
instance.RepositoryException
- if anything fails during the registration processprotected void registerNodeTypes(String cndFile, NodeTypeManager nodeTypeManager, boolean allowUpdate) throws RepositoryException, IOException
NodeTypeManager
. Any namespaces defined in the CND file will
be automatically registered as well.cndFile
- the relative path to the cnd file, which is loaded using via Class.getResourceAsStream(String)
nodeTypeManager
- the node type manager with which the cnd will be registeredallowUpdate
- a boolean which indicates whether updates on existing node types are allowed or no. See
NodeTypeManager.registerNodeType(javax.jcr.nodetype.NodeTypeDefinition, boolean)
RepositoryException
- if anything failsIOException
- if any stream related operations failprotected void registerNodeTypes(InputStream cndStream, NodeTypeManager nodeTypeManager, boolean allowUpdate) throws RepositoryException, IOException
cndStream
- the input stream containing the CND file; may not be nullnodeTypeManager
- the node type manager with which the node types in the CND file should be registered; may not be
nullallowUpdate
- a boolean which indicates whether updates on existing node types are allowed or no. See
NodeTypeManager.registerNodeType(javax.jcr.nodetype.NodeTypeDefinition, boolean)
RepositoryException
- if anything failsIOException
- if any stream related operations failprotected final Logger getLogger()
protected final void registerDefaultMimeTypes(String... mimeTypes)
initialize(NamespaceRegistry, NodeTypeManager)
method in the subclass.
This method can be called more than once to add additional mime types.
mimeTypes
- the array of MIME types that are accepted by this sequencerisAccepted(String)
protected final Set<String> getAcceptedMimeTypes()
initialize(NamespaceRegistry, NodeTypeManager)
method or the MIME types explicitly set in the
sequencers configuration.public final boolean hasAcceptedMimeTypes()
public final boolean isAccepted(String mimeType)
mimeType
- the MIME typemimeType
is null and
therefore not known), or false otherwisehasAcceptedMimeTypes()
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.