code: public NodeDefinitionData getChildNodeDefinition(InternalQName nodeName, InternalQName nodeType,
        InternalQName parentNodeType, InternalQName[] parentMixinTypes) throws RepositoryException
     {
        NodeDefinitionData[] defs = getAllChildNodeDefinitions(getNodeTypeNames(parentNodeType, parentMixinTypes));
  
        NodeDefinitionData residualDef = null;
        NodeDefinitionData firstResidualDef = null;
  
        outer : for (NodeDefinitionData nodeDef : defs)
        {
           if (nodeDef.getName().equals(nodeName))
           {
              return nodeDef;
           }
           else if (nodeDef.isResidualSet())
           {
              // store first residual definition to be able to return
              if (firstResidualDef == null)
              {
                 firstResidualDef = nodeDef;
              }
  
              // check required primary types
              for (InternalQName requiredPrimaryType : nodeDef.getRequiredPrimaryTypes())
              {
                 if (!isNodeType(requiredPrimaryType, nodeType))
                 {
                    continue outer;
                 }
              }
  
              // when there are several suitable definitions take the most older
              if (residualDef == null
                 || isNodeType(residualDef.getRequiredPrimaryTypes()[0], nodeDef.getRequiredPrimaryTypes()[0]))
              {
                 residualDef = nodeDef;
              }
           }
        }
  
        return residualDef != null ? residualDef : firstResidualDef;
     }
docs: {@inheritDoc}