7.4.2 Assigning a Primary Node Type

Assignment of a node type to a node on creation is done by supplying the node type name alongside the new node's path in a call to

Node.addNode(String relPath, String primaryNodeTypeName)

(see 7.1.4 Adding Nodes).

Alternatively, in many cases the application using the API will not need to explicitly supply a node type since the very name of the new child node will be enough to unambiguously determine its node type by reference to one of the node definitions contained in the node type of the parent node. In such cases, Node.addNode(String relPath) will be sufficient.

Automatic determination of node types is only required to work if the name of the node being added is explicitly named in a child node definition of the parent node type (or one of that type's supertypes; see 6.7.14 NodeDefinition). The implementation is not required to take residual definitions into account (see 6.7.15 Residual Definitions).

If the node type of the new child node cannot be determined automatically and no primary node type is explicitly specified, then a ConstraintViolationException is thrown (see 7.1.4 Adding Nodes).