Skip to content

User Documentation

jpav edited this page Sep 17, 2014 · 8 revisions

What is Modelspace?

Modelspace 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).

How to use Modelspace

After downloading Modelspace, you start by simply creating an instance of a Modelspace:

import org.modelspace.Modelspace;
...
Modelspace modelspace = new Modelspace();

Then configure the Modelspace with whatever metamodels your application needs to support. This is done by telling the Modelspace 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. Modelspace 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:

MetamodelManager metamodelManager = modelspace.metamodelManager();
List< String > groupUrls = metamodelManager.sequencerGroups( MetamodelManager.MAVEN_SEQUENCER_REPOSITORY );
List< String > archiveUrls = metamodelManager.sequencerArchives( <aGroupUrl> );
metamodelManager.installSequencers( <anArchiveUrl> ); // Like that hideously long URL in the previous code snippet

A Metamodel will be created for each sequencer installed. Use this method to retrieve all available metamodels:

List< Metamodel > metamodels = metamodelManager.metamodels();

Next, import a file into the Modelspace's embedded repository:

String filePath = modelspace.importFile( new File( "Books.xsd" ) );

Finally, create a model from your imported file using an available metamodel. These will be created:

modelspace.createModel( filePath, <metamodel> );

More than one metamodel 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 metamodel is used to create a model from an imported file.