code: public NodeDefinition getDefinition() throws RepositoryException
     {
        checkValid();
  
        if (nodeDefinition == null)
        {
  
           NodeTypeDataManager nodeTypesHolder = session.getWorkspace().getNodeTypesHolder();
           ExtendedNodeTypeManager nodeTypeManager = (ExtendedNodeTypeManager)session.getWorkspace().getNodeTypeManager();
  
           if (this.isRoot())
           { // root - no parent
              if (nodeDefinition == null)
              {
                 NodeType required =
                    nodeTypeManager.getNodeType(locationFactory.createJCRName(Constants.NT_BASE).getAsString());
                 InternalQName requiredName = sysLocFactory.parseJCRName(required.getName()).getInternalName();
                 NodeDefinitionData ntData =
                    new NodeDefinitionData(null, null, true, true, OnParentVersionAction.ABORT, false,
                       new InternalQName[]{requiredName}, null, true);
                 this.nodeDefinition =
                    new NodeDefinitionImpl(ntData, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
                       .getValueFactory(), session.getTransientNodesManager());
              }
           }
           else
           {
  
              NodeData parent = (NodeData)dataManager.getItemData(getParentIdentifier());
  
              this.definition =
                 nodeTypesHolder.getChildNodeDefinition(getInternalName(), nodeData().getPrimaryTypeName(), parent
                    .getPrimaryTypeName(), parent.getMixinTypeNames());
  
              if (definition == null)
              {
                 throw new ConstraintViolationException("Node definition not found for " + getPath());
              }
  
              InternalQName[] rnames = definition.getRequiredPrimaryTypes();
              NodeType[] rnts = new NodeType[rnames.length];
              for (int j = 0; j < rnames.length; j++)
              {
                 rnts[j] = nodeTypeManager.findNodeType(rnames[j]);
              }
  
              nodeDefinition =
                 new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
                    .getValueFactory(), session.getTransientNodesManager());
           }
        }
  
        return nodeDefinition;
     }
docs: {@inheritDoc}