eXo JCR implementation supports two ways of Nodetypes registration:

The ExtendedNodeTypeManager (from JCR 1.11) interface provides the following methods related to registering node types:

public static final int IGNORE_IF_EXISTS  = 0;


public static final int FAIL_IF_EXISTS    = 2;
public static final int REPLACE_IF_EXISTS = 4;
/**
 * Registers node type using value object.
 */
void registerNodeType(NodeTypeValue nodeTypeValue, int alreadyExistsBehaviour) throws RepositoryException;
/**
 * Registers all node types using XML binding value objects from xml stream.
 */
void registerNodeTypes(InputStream xml, int alreadyExistsBehaviour) throws RepositoryException;
/**
 * Return <code>NodeTypeValue</code> for a given nodetype name. Used for
 * nodetype update. Value can be edited and registered via
 * <code>registerNodeType(NodeTypeValue nodeTypeValue, int alreadyExistsBehaviour)</code>
 */
NodeTypeValue getNodeTypeValue(String ntName) throws NoSuchNodeTypeException, RepositoryException;
/**
 * Registers or updates the specified <code>Collection</code> of
 * <code>NodeTypeValue</code> objects.
 */
public NodeTypeIterator registerNodeTypes(Collection<NodeTypeValue> values,
                                            int alreadyExistsBehaviour) throws UnsupportedRepositoryOperationException,
                                                                       RepositoryException;
/**
 * Unregisters the specified node type.
 */
public void unregisterNodeType(String name) throws UnsupportedRepositoryOperationException,
                                             NoSuchNodeTypeException,
                                             RepositoryException;
/**
 * Unregisters the specified set of node types.<p/> Used to unregister a set
 * of node types with mutual dependencies.
 */
public void unregisterNodeTypes(String[] names) throws UnsupportedRepositoryOperationException,
                                                 NoSuchNodeTypeException,
                                                 RepositoryException;

The NodeTypeValue interface represents a simple container structure used to define node types which are then registered through the ExtendedNodeTypeManager.registerNodeType method. The implementation of this interface does not contain any validation logic.

/**

 * @return Returns the declaredSupertypeNames.
 */
public List<String> getDeclaredSupertypeNames();
/**
 * @param declaredSupertypeNames
 *The declaredSupertypeNames to set.
 */
public void setDeclaredSupertypeNames(List<String> declaredSupertypeNames);
/**
 * @return Returns the mixin.
 */
public boolean isMixin();
/**
 * @param mixin
 *The mixin to set.
 */
public void setMixin(boolean mixin);
/**
 * @return Returns the name.
 */
public String getName();
/**
 * @param name
 *The name to set.
 */
public void setName(String name);
/**
 * @return Returns the orderableChild.
 */
public boolean isOrderableChild();
/**
 * @param orderableChild
 *The orderableChild to set.
 */
public void setOrderableChild(boolean orderableChild);
/**
 * @return Returns the primaryItemName.
 */
public String getPrimaryItemName();
/**
 * @param primaryItemName
 *The primaryItemName to set.
 */
public void setPrimaryItemName(String primaryItemName);
/**
 * @return Returns the declaredChildNodeDefinitionNames.
 */
public List<NodeDefinitionValue> getDeclaredChildNodeDefinitionValues();
/**
 * @param declaredChildNodeDefinitionNames
 *The declaredChildNodeDefinitionNames to set.
 */
public void setDeclaredChildNodeDefinitionValues(List<NodeDefinitionValue> declaredChildNodeDefinitionValues);
/**
 * @return Returns the declaredPropertyDefinitionNames.
 */
public List<PropertyDefinitionValue> getDeclaredPropertyDefinitionValues();
/**
 * @param declaredPropertyDefinitionNames
 *The declaredPropertyDefinitionNames to set.
 */
public void setDeclaredPropertyDefinitionValues(List<PropertyDefinitionValue> declaredPropertyDefinitionValues);

The NodeDefinitionValue interface extends ItemDefinitionValue with the addition of writing methods, enabling the characteristics of a child node definition to be set, after that the NodeDefinitionValue is added to a NodeTypeValue.

/**

 * @return Returns the declaredSupertypeNames.
 */
public List<String> getDeclaredSupertypeNames();
/**
 * @param declaredSupertypeNames
 *The declaredSupertypeNames to set.
 */
public void setDeclaredSupertypeNames(List<String> declaredSupertypeNames);
/**
 * @return Returns the mixin.
 */
public boolean isMixin();
/**
 * @param mixin
 *The mixin to set.
 */
public void setMixin(boolean mixin);
/**
 * @return Returns the name.
 */
public String getName();
/**
 * @param name
 *The name to set.
 */
public void setName(String name);
/**
 * @return Returns the orderableChild.
 */
public boolean isOrderableChild();
/**
 * @param orderableChild
 *The orderableChild to set.
 */
public void setOrderableChild(boolean orderableChild);
/**
 * @return Returns the primaryItemName.
 */
public String getPrimaryItemName();
/**
 * @param primaryItemName
 *The primaryItemName to set.
 */
public void setPrimaryItemName(String primaryItemName);
/**
 * @return Returns the declaredChildNodeDefinitionNames.
 */
public List<NodeDefinitionValue> getDeclaredChildNodeDefinitionValues();
/**
 * @param declaredChildNodeDefinitionNames
 *The declaredChildNodeDefinitionNames to set.
 */
public void setDeclaredChildNodeDefinitionValues(List<NodeDefinitionValue> declaredChildNodeDefinitionValues);
/**
 * @return Returns the declaredPropertyDefinitionNames.
 */
public List<PropertyDefinitionValue> getDeclaredPropertyDefinitionValues();
/**
 * @param declaredPropertyDefinitionNames
 *The declaredPropertyDefinitionNames to set.
 */
public void setDeclaredPropertyDefinitionValues(List<PropertyDefinitionValue> declaredPropertyDefinitionValues);

eXo JCR implementation supports various methods of the node-type registration.

ExtendedNodeTypeManager nodeTypeManager = (ExtendedNodeTypeManager) session.getWorkspace()

                                                             .getNodeTypeManager();
NodeTypeValue testNValue = new NodeTypeValue();
List<String> superType = new ArrayList<String>();
superType.add("nt:base");
testNValue.setName("exo:myNodeType");
testNValue.setPrimaryItemName("");
testNValue.setDeclaredSupertypeNames(superType);
List<PropertyDefinitionValue> props = new ArrayList<PropertyDefinitionValue>();
props.add(new PropertyDefinitionValue("*",
                                      false,
                                      false,
                                      1,
                                      false,
                                      new ArrayList<String>(),
                                      false,
                                      0,
                                      new ArrayList<String>()));
testNValue.setDeclaredPropertyDefinitionValues(props);
nodeTypeManager.registerNodeType(testNValue, ExtendedNodeTypeManager.FAIL_IF_EXISTS);
Copyright © 2009-2012. All rights reserved. eXo Platform SAS