ModeShape has had sequencers almost since the very beginning of the project. When you upload files or add other content to a repository, ModeShape sequencers can automatically process that content to extract useful information and represent it as additional content in the repository.
For example, let’s say that you are going to store (among other things) an XSD file in your repository. Sure, ModeShape stores the actual content as well as metadata about the XSD, such as the name, the MIME type, date it was uploaded, date it was saved, and any other properties your application wants to store. But what about the stuff inside the file? You know, the element declarations, attribute declarations, namespaces, complex types, simple types, etc.?
ModeShape sequencers can get at that stuff. ModeShape comes with quite a few sequencers, including one that can parse the XSD file content and build nodes for each of the element definitions, attribute definitions, complex types, simple types, groups, and all the other concepts. We call this derived content, and having that in your repository is very useful. Imagine being able to find all schemas that contain an element declaration that matches some criteria!
All your application has to do was upload the file — the rest is automatic.
What about cases when you don’t want it to be automatic? For example, you might want to upload and sequence the file all before saving it. Or, you might want some files to be sequenced, and others not to be. Until now, doing this required some pretty complicated workarounds.
However, next month’s ModeShape 3.6 will allow you to configure sequencers that should only be able to be invoked explicitly. We call these “manual sequencers” (in contrast to the “automatic sequencers” we’ve always had), and they are exactly the same as the good ol’ automatic sequencers except for one thing: they don’t have path expressions.
If you recall, a path expression is a pattern that tells ModeShape which content should be sequenced by a particular sequencer. ModeShape watches the changes to the repository, and any time it sees a new or changed node at a path that matches a sequencer’s path expression, ModeShape will automatically run that sequencer on that new/changed node. Every automatic sequencer need at least one valid path expression. But when a sequencer is to be invoked manually, there’s no need to configure a path expression!
So configuring manual sequencer is easy enough, but how do you invoke a sequencer? Very easily.
Consider this scenario: we’ve used a session to upload a file at “
/files/schemas/Customers.xsd“, and this node has a primary type of “
nt:file“. (This means the file’s content is stored in the “
jcr:data” property the “
jcr:content” child node.) The session has not yet saved any of this information, so it is still in the session’s transient state. The repository has a manual sequencer named “XSD Sequencer”, so all we want to do is manually invoke it on our newly-uploaded file and have the generated content put directly under the “
/files/schemas/Customers.xsd” node, adjacent to the “
jcr:content” node. The code is simple:
// Find the file content ...
Node fileNode = session.getNode("/files/schemas/Customers.xsd");
Property content = fileNode.getProperty("jcr:content/jcr:data");
// Pick where we want the new content to be placed ...
Node output = fileNode; // could be anywhere!
// Invoke the specific sequencer ...
boolean success = session.sequence("XSD Sequencer", content, output);
sequence(...) method returns “true” if the sequencer generated output, or “false” if the sequencer couldn’t use the input and instead did nothing. Remember that when
sequence(...) does return, any generated output is only in the session’s transient state and “
session.save()” must be called to persist this state.
For more detail about how to configure and use manual sequencers in ModeShape 3.6 or later, please see our documentation. Then, watch this space for news about the 3.6 release.
Filed under: uncategorized