Jump to: navigation, search

JCR Management

Revision as of 11:02, 14 September 2008 by Sandro.boehme.gmx.de (Talk | contribs)

JCR Mangement (JCRM)

JCR Management will provide tooling and a JCR (http://en.wikipedia.org/wiki/Content_repository_API_for_Java) persistence framework for EMF with pluggable JCR implementations.

The Contributions


  • Johan Gielstra:
  • My employer inovex GmbH (http://www.inovex.de) contributes 2 person days to work on this project within working hours.
  • Ed Merks:
    • helps as a mentor for questions regarding the Eclipse foundation.
    • implemented a new feature request for EMF that I had (dynamic feature delegation)
    • answers a lot of my questions in the newsgroup


  • My employer inovex GmbH (http://www.inovex.de) contributes 5 person days to work on this project within working hours.
  • Ed Merks:
    • helps as a mentor for questions regarding the Eclipse foundation.
    • answers a lot of my questions in the newsgroup
  • The ATL team contributed an initial meta model and transformation that will speed up ATL integration.
  • Nick Boldt created the initial JCR Management (CVS, website, ...) setup at eclipse.org

The Status

JCRM is not production ready at the moment. The current code base consists of prototypes that serve as a basis for concrete discussions about requirements and solutions. The prototypes are tested exclusively with the example library EMF model.

The Architecture

JCRM is based on a mapping between EMF and JCR. One part is responsible to map EMF type elements to JCR node type elements and the other part maps EMF objects to JCR nodes. The main advantage of that architecture is, that many EMF frameworks can now work on JCR node types and nodes. The following JCRM tool prototypes are just examples how this mapping can be used. More ideas JCR tools or Eclipse projects are certainly welcome. They will be logged in the ideas section of this wiki. The most interesting ideas will be provided to the community for priorization and for validation the use cases. After that the JCRM team (at the moment it's just me - Sandro) will work on it.

Mapping of type elements

There is a seperate page that explains how to map EMF type elements to JCR node type elements.

The Tooling

EMF Class Editor

The class editor is based on the EMF Ecore model. This model is generated from the node types in the repository.


Jackrabbit XML Nodetype Editor

This editor saves the content in the XML format that can be used for Jackrabbit node type registration. It completely supports drag 'n drop, copy & paste and undo/redo. The editor is basically the sample model editor of EMF enhanced with the JCRM type mapping semantics. You can use it to create a new XML file for the node type registration in Jackrabbit and you can also read the node types from the repository save it and manipulate it with this editor.


Jackrabbit CND Editor

This text editor validates the content against the Jackrabbit CND format. It also contains minimal code completion. For this editor the XText framework of oAW is used. The JCRM type mapping framework makes it possible to use the JCR node type structure in the grammar for the XText editor. This way the CND file can get generated from the node types in the repository on the fly. At the moment only a small subset of the XText features are used in this editor.


Domain Model Editor

The domain model editor is a sample tool that is generated from EMF. It usually has a XML backend. Just the backend configuration changes it to be an editor of JCR nodes.

Every change in the model immediately changes the underlaying repository. E.g. if you add a "Book" object in that editor node.addNode("NewNode","Book") is called. As soon as you save the editor session.save() is called.



The API uses the classes generated by EMF and the JCRM type mapping. At runtime you can see the JCRM object mapping at work. You can find more detailed descriptions in the comments.

  public static void main(String[] args) {
  	// Create an EMF resource set to hold the resources.
  	ResourceSet resourceSet = new ResourceSetImpl();
  	// Register the appropriate EMF resource factory to handle the file 
        // extension "mydomainmodel"
  	("mydomainmodel", new demo.MyResourceFactory());
  	// Register the EMF package to ensure it is available during loading.
  	try {
                // Create an EMF resource using the registered "mydomainmodel" extension
  		Resource resource = resourceSet.createResource(URI.createURI("http:///My.mydomainmodel"));
                // Create a domain object. The constructor is initially generated by EMF to be protected
                // but you can make it public if you want.
  		Library library = MyDomainModelFactory.eINSTANCE.createLibrary();
                // In contrast to the JCR specification EMF generally allows to have many root nodes
                // hence the content of the resource is designed to be a list in EMF even though the 
                // JCRM Framework needs only one element in the content.
                // JCRM puts the root object containing the corresponding root node of the repository
                // in the content of the resource where it can get retrieved. "root" is the type
                // of the rootObject that corresponds to the node type of the root node.
  		root rootObject = (root) resource.getContents().get(0);
                // As soon as an object is added to it's containing object it also get it's
                // node injected. In this case the library object is added to the "residual
                // definition" feature of the rootObject. That calls addNode() on the
                // node that is contained within the rootObject. The resulting node
                // is then injected in the library object.
                // Every domain object contains it's corresponding node and every modification 
                // is delegated to the node. In this case setName...("MyLibraryNameByAPI") actually
                // calls nodeOfTheObject.setProperty("name","MyLibraryNameByAPI")
                // This way the objects don't need to have own copies of the property content.
                // At the moment there is not something like a detached mode where you can
                // modify properties without the object having an injected node.
  		Book aBook = MyDomainModelFactory.eINSTANCE.createBook();
  		Writer aWriter = MyDomainModelFactory.eINSTANCE.createGuideBookWriter();
                // that calls session.save() and persists the changes made above.
  		resource.save(System.out, null);
  	catch (IOException exception) {


  1. See Bugzilla for an overview of the ToDo's https://bugs.eclipse.org/bugs/buglist.cgi?short_desc_type=allwordssubstr&short_desc=&product=EMFT&component=JCR+Management&long_desc_type=allwordssubstr&long_desc=&order=Importance

Next Milestone

Create a first downloadable presentation of the project to show the potential of Eclipse modeling to the Jackrabbit community.


  • Using Cedrics Compare editor inside the JCR Manager


  • simplicity
  • transparency
  • no dependency on JCR implementations


  1. What's the relationship between JCR Management and Jackrabbit JCR-OCM?

One part of JCR Management has the same goal as JCR-OCM - exposing node data and operations to domain models - but JCRM uses an MDSD approach based on Eclipse Modeling Framework (EMF). This makes it depending less on reflection and using more generated classes instead. It will delegate as many calls on JCR node data as possible to minimize copying node data to domain model objects. Additionally JCR Management also has many other goals. But find out the details of JCR-OCM and check out the source code and the documentation.

Try it out


  • Jackrabbit:

JCRM expects the currently latest Jackrabbit version remotely at "//localhost:1099/jackrabbit.repository". Please make sure it's available there.

  • Eclipse:

JCRM is tested with the Eclipse modeling package (http://www.eclipse.org/downloads/packages/) together with oAW (http://www.eclipse.org/downloads/download.php?file=/technology/gmt/oaw/43/openarchitectureware-sdk-4.3-release.zip)

  • JCRM:

- Check out all modules from org.eclipse.emf/org.eclipse.emf.jcrm/plugins as plugins using this repository connection:

   Server: dev.eclipse.org
   Repository Path: /cvsroot/modeling
   User: anonymous
   Password: (leave blank)
   Connection Type: pserver
   Checkout As: Empty EMF Project

- In the "org.eclipse.emf.jcrm.conversion" plugin in the source folder you find the general build.xml file. It is used to build all projects.

  1. Right-Click it and choose "Run As/Ant Build..."
  2. In the "JRE" tab choose "Run in the same JRE as the workspace"
  3. Press "Run"

If there are no errors anymore you successfully checked out JCRM.

Running JCRM

  1. In the main menu choose "Run/Run Configurations"
  2. Create a new Run Configuration for "Eclipse Application"
  3. Give it a name like "Start JCRM" if you want
  4. In the "Arguments" tab enter "-Xmx512m" in the "VM arguments" field
  5. Press "Run" to start a new Eclipse instance
  6. You can also start your Jackrabbit server now

This puts all plugin projects that have been checked out (and maybe modified) into the new Eclipse instance.

Creating a demo domain model

  1. In the new Eclipse instance create a new JCR Management project using the "New Project..." wizard. You can give it a name like "Demo" if you want.
  2. Paste the example library EMF model as library.ecore into the generated "model" folder. I tested JCRM basically with this model but the current features should also work with other models.
  3. In the "workflow" folder open the "workflow.properties" file and change the "projectFolderName" to the one you have choosen in the New Project-wizard.

Registering the domain model and create the tooling

Now the fun part starts as the tooling can be generated.

  1. Right-Click at "workflow/registerModelToRepository.oaw" choose "Run As/oAW Workflow" to register your Ecore model to the Jackrabbit repository.
    1. "src-gen/library.jrxmlntmodel" is the xml file that has been used to register the domain model as Jackrabbit XML.
    2. "src-gen/library.nodetype" is a native JCRM model that serves as a basis for transformations into other models.
  2. Right-Click at "workflow/loadModelFromRepository.oaw" choose "Run As/oAW Workflow" to create a new EMF model from the native JCR node types and your own node types that are currently registered to your repository. This basically puts your domain model in the context of the node types of your repository.
    1. "src-gen/loadedLibrary.ecore" is the Ecore model that contains the domain model, the native JCR node types in Ecore format and the annotations that map the Ecore elements to node types elements.
    2. "src-gen/loadedlibraryNodeTypes.nodetype" is a native JCRM model that serves as a basis for transformations into other models.
    3. "src-gen/loadedLibrary.jrcnd" is a generated file that contains all node types in the Jackrabbit CND format.
    4. Right-Click at "loadedLibrary.ecore/Initialize ecore_diagram Diagram file"
    5. Press "Finish" and you will see how the EClasses (node types) relate to each other in the Diagram

Configure JCRM for the use as API and as domain model editor

  1. Copy the loadedLibrary from the src-gen folder to the model folder to avoid that it is overwritten by subsequent calls on loadModelFromRepository.oaw
  2. To make JCRM aware of changes in the model instance, all domain model classes need to extend from JCRM's JCRMNode class instead of Object or EMF's EObject. As now basically all domain model classes inherit from the "Base" class (nt:base) we only need to make the Base class inherit from JCRMNode. To do this you can do the following steps:
    1. Open the mode/loadedLibrary.ecore file
    2. Right-Click at the root node of the tree and choose "Load Resource..."
    3. Choose "Browse Registered Packages..."
    4. Select "http://www.eclipse.org/jcrm/0.8.0/dmodel, finish the dialog and save the model. This references the domain model (dmodel) base of JCRM for the object-node mapping.
    5. Open the properties editor for the "base" EClass
    6. Assign the JCRMNode EClass as the ESuper Type for "base"
  3. Right-Click at loadedLibrary.ecore and create a new "Eclipse Modeling Framework/EMF model" (loadedLibrary.genmodel) based on the Ecore model.
    1. Click throuch to the 4th page and press "Load".
    2. At the "Package Selection" page check "myDomainModel" as "Root packages" and "Domainmodel" as "Referenced generator models". Then you can finish the dialog.
  4. Open the properties editor for the root element of the genmodel and change the "Model/Feature Delegation Field" to "Reflective". That delegates all calls on the model to the JCRM framework. Later an other value instead of "Reflective" will be used which will provide more flexibility.
  5. Right-Click at the root element of the genmodel and select "Generate All". That generates the model classes, initial source code for a test class and the tree based editor for the model.
  6. Add org.eclipse.emf.jcrm.userdependencies to the list of the plug-in dependencies in the META-INF/MANIFEST.MF file. Make sure the "reexport" option is selected.
  7. Add the "org.eclipse.emf.ecore.extension_parser" extension to the list of extensions in the plugin.xml file (it's the same editor as the manifest.mf file.
  8. Use "mydomainmodel" in the type field. That declarates that every resource that ends with *.mydomainmodel will handled by the JCR backend we declare in the class field
  9. Click at the link in the "class*:" label. This opens the "New Class" wizard.
  10. You can use the /Demo/src-resource folder as source folder, "demo" as package and "MyResourceFactory" as class name.
  11. Choose "JRRMIResourceFactoryImpl" as supertype for that class and finish the dialog.
  12. In the resulting Java class use the Eclipse quick tip to import the "JRRMIResourceFactoryImpl" class and to add the unimplemented method.
  13. Instead of "null" return "myDomainModel.MyDomainModelPackage.eINSTANCE"
  14. Navigate to the "Runtime" tab of the manifest.mf editor and add the demo package to make the resource available to the depending plugins. Now the JCRM class-node type mapping, the object-node mapping and the backend (resource) configuration are finished.

Starting a test case using the API

  1. To test the JCRM API you can replace the Demo.tests/src/myDomainModel.tests.MyDomainModelExample.main() method with the one from http://wiki.eclipse.org/JCR_Management#The_API . If you run it as an application within Eclipse you need to add "-Xmx512m" to the VM arguments in the "Arguments" tab of the run configuration. This should add some nodes and give you a quick example of the JCRM runtime API.

Starting the domain model editor

  1. In the main menu of your current (2nd) Eclipse instance choose "Run/Run Configurations"
  2. Create a new Run Configuration for "Eclipse Application"
  3. Give it a name like "Start Editor" if you want
  5. Press "Run" to start a new Eclipse instance open a new simple project like that:
  6. In the new Eclipse instance (the 3rd):
    1. Click at "File/New/Project...".
    2. Choose "General/Project".
    3. Give it a name like "Editor".
  7. Now you can create the domain model editor by using the new file wizard:
    1. Right click at your project and choose "New/Other...".
    2. Choose "Example EMF Model Creation Wizards/MyDomainModel".
    3. Give it an arbitrary name.
    4. Choose an arbitrary Model Object in the following page and finish the dialog.
    5. Now the editor opens and you can edit your Jackrabbit backed model.
    6. The properties editor can be opened by right clicking on a model element and choosing "Show Properties View".