As described in Defining custom node types, the JCR 2.0 specification defines the Compact Node Definition (CND) format to easily and compactly specify node type definitions, but uses this format only within the specification. Instead, the only standard API for registering custom node types is via the standard programmatic API.
ModeShape fully supports this standard API, but it also defines a non-standard API for reading node type definitions from either CND files or the older Jackrabbit XML format. This non-standard API is described in this section.
ModeShape defines in its public API a org.modeshape.jcr.nodetype.NodeTypeManager interface that extends the standard javax.jcr.nodetype.NodeTypeManager interface:
Simply cast the NodeTypeManager instance obtained from the Workspace.getNodeTypeManager() method:
Alternatively, you can cast the result of the Session.getWorkspace() method to org.modeshape.jcr.api.Workspace, which overrides the getNodeTypeManager() method to return org.modeshape.jcr.api.nodetype.NodeTypeManager:
In addition to using the ModeShape API as described above, it is possible to configure a repository to import, at startup, one or more CND files using the following format:
where the node-types attribute accepts an array of strings, representing paths to CND files, accessible at runtime.
|If CND files are configured to be imported at repository startup, they will overwrite each time any pre-existing node types with the same name that have been registered previously.|
ModeShape also supports the older non-standard Jackrabbit format for defining node types, and only to make it easier for people to switch from Jackrabbit to ModeShape. The Jackrabbit 2.x no longer uses this format, and Jackrabbit 1.x only used this XML format for built-in node types and discouraged users from modifying it. However, some users of Jackrabbit 1.x still added their custom node types to this file.
|Use the standard CND format wherever possible, and use this non-standard XML format only if you're trying to switch from Jackrabbit to ModeShape (with as little work as possible). Once you're convinced to use ModeShape, then convert your XML files to CND files.|
The DTD for the non-standard XML files can be found here.