eXo Platform 3.5

## Chapter 12. Node Types and Namespaces

## Introduction

Support of node types and namespaces is required by the JSR-170 specification. Beyond the methods required by the specification, eXo JCR has its own API extension for the Node type registration as well as the ability to declaratively define node types in the Repository at the start-up time.

## Node Types definition

Node type registration extension is declared in org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager interface

Your custom service can register some neccessary predefined node types at the start-up time. The node definition should be placed in a special XML file (see DTD below) and declared in the service's configuration file thanks to eXo component plugin mechanism, described as follows:

    <external-component-plugins>

      <target-component>org.exoplatform.services.jcr.RepositoryService</target-component>

          <component-plugin>

            <name>add.nodeType</name>

            <set-method>addPlugin</set-method>

            <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>

            <init-params>

              <values-param>

                <name>autoCreatedInNewRepository</name>

                <description>Node types configuration file</description>

                <value>jar:/conf/test/nodetypes-tck.xml</value>

                <value>jar:/conf/test/nodetypes-impl.xml</value>

              </values-param>

        <values-param>

                <name>repo1</name>

                <description>Node types configuration file for repository with name repo1</description>

                <value>jar:/conf/test/nodetypes-test.xml</value>

              </values-param>

        <values-param>

                <name>repo2</name>

                <description>Node types configuration file for repository with name repo2</description>

                <value>jar:/conf/test/nodetypes-test2.xml</value>

              </values-param>

            </init-params>

          </component-plugin>

There are two types of registration. The first type is the registration of node types in all created repositories, it is configured in values-param with the name autoCreatedInNewRepository. The second type is registration of node types in specified repository and it is configured in values-param with the name of repository.

Node type definition file format:

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE nodeTypes [

       <!ELEMENT nodeTypes (nodeType)*>

          <!ELEMENT nodeType (supertypes?|propertyDefinitions?|childNodeDefinitions?)>

          <!ATTLIST nodeType

             name CDATA #REQUIRED

             isMixin (true|false) #REQUIRED

             hasOrderableChildNodes (true|false)

             primaryItemName CDATA

          >

          <!ELEMENT supertypes (supertype*)>

          <!ELEMENT supertype (CDATA)>

          <!ELEMENT propertyDefinitions (propertyDefinition*)>

          <!ELEMENT propertyDefinition (valueConstraints?|defaultValues?)>

          <!ATTLIST propertyDefinition

             name CDATA #REQUIRED

             requiredType (String|Date|Path|Name|Reference|Binary|Double|Long|Boolean|undefined) #REQUIRED

             autoCreated (true|false) #REQUIRED

             mandatory (true|false) #REQUIRED

             onParentVersion (COPY|VERSION|INITIALIZE|COMPUTE|IGNORE|ABORT) #REQUIRED

             protected (true|false) #REQUIRED

             multiple  (true|false) #REQUIRED

          >

        <!-- For example if you need to set ValueConstraints [],

          you have to add an empty element <valueConstraints/>.

          The same order is for other properties like defaultValues, requiredPrimaryTypes etc.

          -->

          <!ELEMENT valueConstraints (valueConstraint*)>

          <!ELEMENT valueConstraint (CDATA)>

          <!ELEMENT defaultValues (defaultValue*)>

          <!ELEMENT defaultValue (CDATA)>

          <!ELEMENT childNodeDefinitions (childNodeDefinition*)>

          <!ELEMENT childNodeDefinition (requiredPrimaryTypes)>

          <!ATTLIST childNodeDefinition

             name CDATA #REQUIRED

             defaultPrimaryType  CDATA #REQUIRED

             autoCreated (true|false) #REQUIRED

             mandatory (true|false) #REQUIRED

             onParentVersion (COPY|VERSION|INITIALIZE|COMPUTE|IGNORE|ABORT) #REQUIRED

             protected (true|false) #REQUIRED

             sameNameSiblings (true|false) #REQUIRED

          >

          <!ELEMENT requiredPrimaryTypes (requiredPrimaryType+)>

          <!ELEMENT requiredPrimaryType (CDATA)>

    ]>

## Namespaces definition

Default namespaces are registered by repository at the start-up time

Your custom service can extend a set of namespaces with some application specific ones, declaring it in service's configuration file thanks to eXo component plugin mechanism, described as follows:

          <component-plugin>

              <name>add.namespaces</name>

              <set-method>addPlugin</set-method>

              <type>org.exoplatform.services.jcr.impl.AddNamespacesPlugin</type>

              <init-params>

                <properties-param>

                  <name>namespaces</name>

                  <property name="test" value="http://www.test.org/test"/>

                </properties-param>

              </init-params>

          </component-plugin>