3.1.2.2.4. More How-tos

Adding a new PropertyDefinition

NodeTypeValue myNodeTypeValue = nodeTypeManager.getNodeTypeValue(myNodeTypeName);

List<PropertyDefinitionValue> props = new ArrayList<PropertyDefinitionValue>();
props.add(new PropertyDefinitionValue("tt",
                                      true,
                                      true,
                                      1,
                                      false,
                                      new ArrayList<String>(),
                                      false,
                                      PropertyType.STRING,
                                      new ArrayList<String>()));
myNodeTypeValue.setDeclaredPropertyDefinitionValues(props);
nodeTypeManager.registerNodeType(myNodeTypeValue, ExtendedNodeTypeManager.REPLACE_IF_EXISTS);

Adding a new child NodeDefinition

NodeTypeValue myNodeTypeValue = nodeTypeManager.getNodeTypeValue(myNodeTypeName);


List<NodeDefinitionValue> nodes = new ArrayList<NodeDefinitionValue>();
nodes.add(new NodeDefinitionValue("child",
                                      false,
                                      false,
                                      1,
                                      false,
                                      "nt:base",
                                      new ArrayList<String>(),
                                      false));
testNValue.setDeclaredChildNodeDefinitionValues(nodes);
nodeTypeManager.registerNodeType(myNodeTypeValue, ExtendedNodeTypeManager.REPLACE_IF_EXISTS);

Changing/Removing existing PropertyDefinition or child NodeDefinition

Note

The existing data must be consistent before you change or remove any existing definition. JCR does not allow you to change the node type in the way in which the existing data would be incompatible with a new node type. But if these changes are needed, you can do it in several phases, consistently changing the node type and the existing data.

Example: Add a new residual property definition with the "downloadCount" name to the "myNodeType" existing node type.

There are two limitations that do not allow you to make the task with a single call of the registerNodeType method.

  • Existing nodes of the "myNodeType" type, which does not contain the "downloadCount" property that conflicts with your needed node type.

  • The "myNodeType" registered node type will not allow you to add the "downloadCount" property because it has no such specific properties.

To complete the task, you need to do the following steps:

  1. Change the "myNodeType" existing node type by adding the mandatory "downloadCount" property.

  2. Add the "myNodeType" node type with the "downloadCount" property to all the existing node types.

  3. Change the definition of the "downloadCount" property of the node type "myNodeType" to mandatory.


Changing the list of super types

NodeTypeValue testNValue = nodeTypeManager.getNodeTypeValue("exo:myNodeType");


List<String> superType  = testNValue.getDeclaredSupertypeNames();
superType.add("mix:versionable");
testNValue.setDeclaredSupertypeNames(superType);
nodeTypeManager.registerNodeType(testNValue, ExtendedNodeTypeManager.REPLACE_IF_EXISTS);
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus