-
Notifications
You must be signed in to change notification settings - Fork 5
User Documentation
ModeShape Modeler is an API that allows applications to manage files, and particularly models, in an embedded ModeShape workspace. The projects temporarily reside here until we find an appropriate home (like in the ModeShape project).
After downloading ModeShape Modeler, you start by simply creating an instance of a Modeler:
import org.modeshape.modeler.Modeler;
...
Modeler modeler = new Modeler();
Then configure the Modeler with whatever model types your application needs to support. This is done by telling the Modeler to download and install sequencers from an existing ModeShape sequencer archive residing in a registered Maven repository:
installSequencers( "http://repo1.maven.org/maven2/org/modeshape/modeshape-sequencer-zip/3.5.0.Final/modeshape-sequencer-zip-3.5.0.Final.jar" );
Don't worry about that hideously long URL. ModeShape Modeler comes pre-registered with two Maven repositories, the Maven Central repository and the JBoss Nexus repository, and the API provides methods for navigating a Maven repository and retrieving the URLs of available sequencers:
ModelTypeManager modelTypeManager = modeler.modelTypeManager();
List< String > groupUrls = modelTypeManager.sequencerGroups( ModelTypeManager.MAVEN_SEQUENCER_REPOSITORY );
List< String > archiveUrls = modelTypeManager.sequencerArchives( <aGroupUrl> );
modelTypeManager.installSequencers( <anArchiveUrl> ); // Like that hideously long URL in the previous code snippet
A ModelType will be created for each sequencer installed. Use this method to retrieve all available model types:
List< ModelType > modelTypes = modelTypeManager.modelTypes();
Next, import a file into the Modeler's embedded repository:
String filePath = modeler.importFile( new File( "Books.xsd" ) );
Finally, create a model from your imported file using an available model type. These will be created:
modeler.createModel( filePath, <aModelType> );
More than one model type may be applicable to a file's content. For instance, both an XML and XSD model could be created for an XSD file. An exception will be thrown if an inapplicable model type is used to create a model from an imported file.