Search in sources :

Example 1 with InvalidNodeTypeDefinitionException

use of javax.jcr.nodetype.InvalidNodeTypeDefinitionException in project jackrabbit by apache.

the class DefinitionValidator method checkForCircularInheritance.

/**
 * @param supertypes
 * @param inheritanceChain
 * @param ntdMap
 * @throws InvalidNodeTypeDefinitionException
 * @throws RepositoryException
 */
private void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntdMap) throws InvalidNodeTypeDefinitionException, RepositoryException {
    for (int i = 0; i < supertypes.length; i++) {
        Name stName = supertypes[i];
        int pos = inheritanceChain.lastIndexOf(stName);
        if (pos >= 0) {
            StringBuffer buf = new StringBuffer();
            for (int j = 0; j < inheritanceChain.size(); j++) {
                if (j == pos) {
                    buf.append("--> ");
                }
                buf.append(inheritanceChain.get(j));
                buf.append(" extends ");
            }
            buf.append("--> ");
            buf.append(stName);
            throw new InvalidNodeTypeDefinitionException("circular inheritance detected: " + buf.toString());
        }
        if (ntdMap.containsKey(stName)) {
            Name[] sta = ntdMap.get(stName).getSupertypes();
            if (sta.length > 0) {
                // check recursively
                inheritanceChain.push(stName);
                checkForCircularInheritance(sta, inheritanceChain, ntdMap);
                inheritanceChain.pop();
            }
        } else {
            throw new InvalidNodeTypeDefinitionException("Unknown supertype: " + stName);
        }
    }
}
Also used : InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name)

Example 2 with InvalidNodeTypeDefinitionException

use of javax.jcr.nodetype.InvalidNodeTypeDefinitionException in project jackrabbit by apache.

the class DefinitionValidator method checkForCircularNodeAutoCreation.

/**
 * @param childNodeENT
 * @param definingParentNTs
 * @param ntdMap
 * @throws InvalidNodeTypeDefinitionException
 */
private void checkForCircularNodeAutoCreation(EffectiveNodeType childNodeENT, Stack<Name> definingParentNTs, Map<Name, QNodeTypeDefinition> ntdMap) throws InvalidNodeTypeDefinitionException {
    // check for circularity through default node types of auto-created child nodes
    // (node type 'a' defines auto-created child node with default node type 'a')
    Name[] childNodeNTs = childNodeENT.getAllNodeTypes();
    for (int i = 0; i < childNodeNTs.length; i++) {
        Name nt = childNodeNTs[i];
        int pos = definingParentNTs.lastIndexOf(nt);
        if (pos >= 0) {
            StringBuffer buf = new StringBuffer();
            for (int j = 0; j < definingParentNTs.size(); j++) {
                if (j == pos) {
                    buf.append("--> ");
                }
                buf.append("node type ");
                buf.append(definingParentNTs.get(j));
                buf.append(" defines auto-created child node with default ");
            }
            buf.append("--> ");
            buf.append("node type ");
            buf.append(nt);
            throw new InvalidNodeTypeDefinitionException("circular node auto-creation detected: " + buf.toString());
        }
    }
    QNodeDefinition[] nodeDefs = childNodeENT.getAutoCreateQNodeDefinitions();
    for (int i = 0; i < nodeDefs.length; i++) {
        Name dnt = nodeDefs[i].getDefaultPrimaryType();
        Name definingNT = nodeDefs[i].getDeclaringNodeType();
        try {
            if (dnt != null) {
                // check recursively
                definingParentNTs.push(definingNT);
                EffectiveNodeType ent = entProvider.getEffectiveNodeType(new Name[] { dnt }, ntdMap);
                checkForCircularNodeAutoCreation(ent, definingParentNTs, ntdMap);
                definingParentNTs.pop();
            }
        } catch (NoSuchNodeTypeException e) {
            String msg = definingNT + " defines invalid default node type for child node " + nodeDefs[i].getName();
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        } catch (ConstraintViolationException e) {
            String msg = definingNT + " defines invalid default node type for child node " + nodeDefs[i].getName();
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        }
    }
}
Also used : InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 3 with InvalidNodeTypeDefinitionException

use of javax.jcr.nodetype.InvalidNodeTypeDefinitionException in project jackrabbit by apache.

the class DefinitionValidator method validateNodeTypeDef.

/**
 * @param ntDef
 * @param validatedDefs Map of nodetype names and nodetype definitions
 * that are known to be valid or are already registered. This map is used to
 * validated dependencies and check for circular inheritance
 * @return
 * @throws InvalidNodeTypeDefinitionException
 * @throws RepositoryException
 */
public EffectiveNodeType validateNodeTypeDef(QNodeTypeDefinition ntDef, Map<Name, QNodeTypeDefinition> validatedDefs) throws InvalidNodeTypeDefinitionException, RepositoryException {
    /**
     * the effective (i.e. merged and resolved) node type resulting from
     * the specified node type definition;
     * the effective node type will finally be created after the definition
     * has been verified and checked for conflicts etc.; in some cases it
     * will be created already at an earlier stage during the validation
     * of child node definitions
     */
    EffectiveNodeType ent = null;
    Name name = ntDef.getName();
    if (name == null) {
        String msg = "no name specified";
        log.debug(msg);
        throw new InvalidNodeTypeDefinitionException(msg);
    }
    checkNamespace(name);
    // validate supertypes
    Name[] supertypes = ntDef.getSupertypes();
    if (supertypes.length > 0) {
        for (int i = 0; i < supertypes.length; i++) {
            checkNamespace(supertypes[i]);
            /**
             * simple check for infinite recursion
             * (won't trap recursion on a deeper inheritance level)
             */
            if (name.equals(supertypes[i])) {
                String msg = "[" + name + "] invalid supertype: " + supertypes[i] + " (infinite recursion))";
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg);
            }
            /* compare to given nt-name set and not to registered nodetypes */
            if (!validatedDefs.containsKey(supertypes[i])) {
                String msg = "[" + name + "] invalid supertype: " + supertypes[i];
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg);
            }
        }
        /**
         * check for circularity in inheritance chain
         * ('a' extends 'b' extends 'a')
         */
        Stack<Name> inheritanceChain = new Stack<Name>();
        inheritanceChain.push(name);
        checkForCircularInheritance(supertypes, inheritanceChain, validatedDefs);
    }
    /**
     * build effective (i.e. merged and resolved) node type from supertypes
     * and check for conflicts
     */
    if (supertypes.length > 0) {
        try {
            EffectiveNodeType est = entProvider.getEffectiveNodeType(supertypes, validatedDefs);
            // make sure that all primary types except nt:base extend from nt:base
            if (!ntDef.isMixin() && !NameConstants.NT_BASE.equals(ntDef.getName()) && !est.includesNodeType(NameConstants.NT_BASE)) {
                String msg = "[" + name + "] all primary node types except" + " nt:base itself must be (directly or indirectly) derived from nt:base";
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg);
            }
        } catch (ConstraintViolationException e) {
            String msg = "[" + name + "] failed to validate supertypes";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        } catch (NoSuchNodeTypeException e) {
            String msg = "[" + name + "] failed to validate supertypes";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        }
    } else {
        // no supertypes specified: has to be either a mixin type or nt:base
        if (!ntDef.isMixin() && !NameConstants.NT_BASE.equals(ntDef.getName())) {
            String msg = "[" + name + "] all primary node types except nt:base itself must be (directly or indirectly) derived from nt:base";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
    }
    checkNamespace(ntDef.getPrimaryItemName());
    // validate property definitions
    QPropertyDefinition[] pda = ntDef.getPropertyDefs();
    for (int i = 0; i < pda.length; i++) {
        QPropertyDefinition pd = pda[i];
        /**
         * sanity check:
         * make sure declaring node type matches name of node type definition
         */
        if (!name.equals(pd.getDeclaringNodeType())) {
            String msg = "[" + name + "#" + pd.getName() + "] invalid declaring node type specified";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        checkNamespace(pd.getName());
        // check that auto-created properties specify a name
        if (pd.definesResidual() && pd.isAutoCreated()) {
            String msg = "[" + name + "#" + pd.getName() + "] auto-created properties must specify a name";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        // check that auto-created properties specify a type
        if (pd.getRequiredType() == PropertyType.UNDEFINED && pd.isAutoCreated()) {
            String msg = "[" + name + "#" + pd.getName() + "] auto-created properties must specify a type";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        /* check default values:
             * make sure type of value is consistent with required property type
             * Note: default internal values are built from the required type,
             * thus check for match with pd.getRequiredType is redundant.
             */
        QValue[] defVals = pd.getDefaultValues();
        /* check that default values satisfy value constraints.
             * Note however, that no check is performed if autocreated property-
             * definitions define a default value. JSR170 does not require this.
             */
        ValueConstraint.checkValueConstraints(pd, defVals);
        /* ReferenceConstraint:
             * the specified node type must be registered, with one notable
             * exception: the node type just being registered
             */
        QValueConstraint[] constraints = pd.getValueConstraints();
        if (constraints != null && constraints.length > 0) {
            if (pd.getRequiredType() == PropertyType.REFERENCE) {
                for (QValueConstraint constraint : constraints) {
                    // TODO improve. don't rely on a specific factory impl
                    Name ntName = NameFactoryImpl.getInstance().create(constraint.getString());
                    /* compare to given ntd map and not registered nts only */
                    if (!name.equals(ntName) && !validatedDefs.containsKey(ntName)) {
                        String msg = "[" + name + "#" + pd.getName() + "] invalid REFERENCE value constraint '" + ntName + "' (unknown node type)";
                        log.debug(msg);
                        throw new InvalidNodeTypeDefinitionException(msg);
                    }
                }
            }
        }
    }
    // validate child-node definitions
    QNodeDefinition[] cnda = ntDef.getChildNodeDefs();
    for (int i = 0; i < cnda.length; i++) {
        QNodeDefinition cnd = cnda[i];
        /* make sure declaring node type matches name of node type definition */
        if (!name.equals(cnd.getDeclaringNodeType())) {
            String msg = "[" + name + "#" + cnd.getName() + "] invalid declaring node type specified";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        checkNamespace(cnd.getName());
        // check that auto-created child-nodes specify a name
        if (cnd.definesResidual() && cnd.isAutoCreated()) {
            String msg = "[" + name + "#" + cnd.getName() + "] auto-created child-nodes must specify a name";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        // check that auto-created child-nodes specify a default primary type
        if (cnd.getDefaultPrimaryType() == null && cnd.isAutoCreated()) {
            String msg = "[" + name + "#" + cnd.getName() + "] auto-created child-nodes must specify a default primary type";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg);
        }
        // check default primary type
        Name dpt = cnd.getDefaultPrimaryType();
        checkNamespace(dpt);
        boolean referenceToSelf = false;
        EffectiveNodeType defaultENT = null;
        if (dpt != null) {
            // check if this node type specifies itself as default primary type
            if (name.equals(dpt)) {
                referenceToSelf = true;
            }
            /**
             * the default primary type must be registered, with one notable
             * exception: the node type just being registered
             */
            if (!name.equals(dpt) && !validatedDefs.containsKey(dpt)) {
                String msg = "[" + name + "#" + cnd.getName() + "] invalid default primary type '" + dpt + "'";
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg);
            }
            /**
             * build effective (i.e. merged and resolved) node type from
             * default primary type and check for conflicts
             */
            try {
                if (!referenceToSelf) {
                    defaultENT = entProvider.getEffectiveNodeType(new Name[] { dpt }, validatedDefs);
                } else {
                    /**
                     * the default primary type is identical with the node
                     * type just being registered; we have to instantiate it
                     * 'manually'
                     */
                    ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
                    defaultENT = ent;
                }
                if (cnd.isAutoCreated()) {
                    /**
                     * check for circularity through default primary types
                     * of auto-created child nodes (node type 'a' defines
                     * auto-created child node with default primary type 'a')
                     */
                    Stack<Name> definingNTs = new Stack<Name>();
                    definingNTs.push(name);
                    checkForCircularNodeAutoCreation(defaultENT, definingNTs, validatedDefs);
                }
            } catch (ConstraintViolationException e) {
                String msg = "[" + name + "#" + cnd.getName() + "] failed to validate default primary type";
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg, e);
            } catch (NoSuchNodeTypeException e) {
                String msg = "[" + name + "#" + cnd.getName() + "] failed to validate default primary type";
                log.debug(msg);
                throw new InvalidNodeTypeDefinitionException(msg, e);
            }
        }
        // check required primary types
        Name[] reqTypes = cnd.getRequiredPrimaryTypes();
        if (reqTypes != null && reqTypes.length > 0) {
            for (int n = 0; n < reqTypes.length; n++) {
                Name rpt = reqTypes[n];
                checkNamespace(rpt);
                referenceToSelf = false;
                /**
                 * check if this node type specifies itself as required
                 * primary type
                 */
                if (name.equals(rpt)) {
                    referenceToSelf = true;
                }
                /**
                 * the required primary type must be registered, with one
                 * notable exception: the node type just being registered
                 */
                if (!name.equals(rpt) && !validatedDefs.containsKey(rpt)) {
                    String msg = "[" + name + "#" + cnd.getName() + "] invalid required primary type: " + rpt;
                    log.debug(msg);
                    throw new InvalidNodeTypeDefinitionException(msg);
                }
                /**
                 * check if default primary type satisfies the required
                 * primary type constraint
                 */
                if (defaultENT != null && !defaultENT.includesNodeType(rpt)) {
                    String msg = "[" + name + "#" + cnd.getName() + "] default primary type does not satisfy required primary type constraint " + rpt;
                    log.debug(msg);
                    throw new InvalidNodeTypeDefinitionException(msg);
                }
                /**
                 * build effective (i.e. merged and resolved) node type from
                 * required primary type constraint and check for conflicts
                 */
                try {
                    if (!referenceToSelf) {
                        entProvider.getEffectiveNodeType(new Name[] { rpt }, validatedDefs);
                    } else {
                        /**
                         * the required primary type is identical with the
                         * node type just being registered; we have to
                         * instantiate it 'manually'
                         */
                        if (ent == null) {
                            ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
                        }
                    }
                } catch (ConstraintViolationException e) {
                    String msg = "[" + name + "#" + cnd.getName() + "] failed to validate required primary type constraint";
                    log.debug(msg);
                    throw new InvalidNodeTypeDefinitionException(msg, e);
                } catch (NoSuchNodeTypeException e) {
                    String msg = "[" + name + "#" + cnd.getName() + "] failed to validate required primary type constraint";
                    log.debug(msg);
                    throw new InvalidNodeTypeDefinitionException(msg, e);
                }
            }
        }
    }
    /**
     * now build effective (i.e. merged and resolved) node type from
     * this node type definition; this will potentially detect more
     * conflicts or problems
     */
    if (ent == null) {
        try {
            ent = entProvider.getEffectiveNodeType(ntDef, validatedDefs);
        } catch (ConstraintViolationException e) {
            String msg = "[" + name + "] failed to resolve node type definition";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        } catch (NoSuchNodeTypeException e) {
            String msg = "[" + name + "] failed to resolve node type definition";
            log.debug(msg);
            throw new InvalidNodeTypeDefinitionException(msg, e);
        }
    }
    return ent;
}
Also used : InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) QValue(org.apache.jackrabbit.spi.QValue) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) Stack(java.util.Stack) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 4 with InvalidNodeTypeDefinitionException

use of javax.jcr.nodetype.InvalidNodeTypeDefinitionException in project jackrabbit by apache.

the class DefinitionValidator method validateNodeTypeDefs.

/**
 * Validate each QNodeTypeDefinition present in the given collection.
 *
 * @param ntDefs
 * @param validatedDefs
 * @return Map mapping the definition to the resulting effective nodetype
 * @throws InvalidNodeTypeDefinitionException
 * @throws RepositoryException
 */
public Map<QNodeTypeDefinition, EffectiveNodeType> validateNodeTypeDefs(Collection<QNodeTypeDefinition> ntDefs, Map<Name, QNodeTypeDefinition> validatedDefs) throws InvalidNodeTypeDefinitionException, RepositoryException {
    // tmp. map containing names/defs of validated nodetypes
    Map<Name, QNodeTypeDefinition> tmpMap = new HashMap<Name, QNodeTypeDefinition>(validatedDefs);
    for (QNodeTypeDefinition ntd : ntDefs) {
        tmpMap.put(ntd.getName(), ntd);
    }
    // map of nodetype definitions and effective nodetypes to be registered
    Map<QNodeTypeDefinition, EffectiveNodeType> ntMap = new HashMap<QNodeTypeDefinition, EffectiveNodeType>();
    List<QNodeTypeDefinition> list = new ArrayList<QNodeTypeDefinition>(ntDefs);
    // iterate over definitions until there are no more definitions with
    // unresolved (i.e. unregistered) dependencies or an error occurs;
    // number of validated nt's per iteration
    int count = -1;
    while (list.size() > 0 && count != 0) {
        count = 0;
        Iterator<QNodeTypeDefinition> iterator = list.iterator();
        while (iterator.hasNext()) {
            QNodeTypeDefinition ntd = iterator.next();
            // check if definition has unresolved dependencies
            /* Note: don't compared to 'registered' nodetypes since registr. is performed later on */
            Collection<Name> dependencies = ntd.getDependencies();
            if (tmpMap.keySet().containsAll(dependencies)) {
                EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpMap);
                ntMap.put(ntd, ent);
                // remove it from list
                iterator.remove();
                // increase count
                count++;
            }
        }
    }
    if (list.size() > 0) {
        StringBuffer msg = new StringBuffer();
        msg.append("the following node types could not be registered because of unresolvable dependencies: ");
        Iterator<QNodeTypeDefinition> iterator = list.iterator();
        while (iterator.hasNext()) {
            msg.append(iterator.next().getName());
            msg.append(" ");
        }
        log.error(msg.toString());
        throw new InvalidNodeTypeDefinitionException(msg.toString());
    }
    return ntMap;
}
Also used : InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition)

Example 5 with InvalidNodeTypeDefinitionException

use of javax.jcr.nodetype.InvalidNodeTypeDefinitionException in project jackrabbit by apache.

the class NodeTypeManagerImpl method registerNodeTypes.

// --------------------------------------------------< new JSR 283 methods >
/**
 * Registers or updates the specified <code>Collection</code> of
 * <code>NodeTypeDefinition</code> objects. This method is used to register
 * or update a set of node types with mutual dependencies. Returns an
 * iterator over the resulting <code>NodeType</code> objects.
 * <p>
 * The effect of the method is "all or nothing"; if an error occurs, no node
 * types are registered or updated.
 * <p>
 * Throws an <code>InvalidNodeTypeDefinitionException</code> if a
 * <code>NodeTypeDefinition</code> within the <code>Collection</code> is
 * invalid or if the <code>Collection</code> contains an object of a type
 * other than <code>NodeTypeDefinition</code>.
 * <p>
 * Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code>
 * is <code>false</code> and a <code>NodeTypeDefinition</code> within the
 * <code>Collection</code> specifies a node type name that is already
 * registered.
 * <p>
 * Throws an <code>UnsupportedRepositoryOperationException</code> if this
 * implementation does not support node type registration.
 *
 * @param definitions a collection of <code>NodeTypeDefinition</code>s
 * @param allowUpdate a boolean
 * @return the registered node types.
 * @throws InvalidNodeTypeDefinitionException if a
 *  <code>NodeTypeDefinition</code> within the <code>Collection</code> is
 *  invalid or if the <code>Collection</code> contains an object of a type
 *  other than <code>NodeTypeDefinition</code>.
 * @throws NodeTypeExistsException if <code>allowUpdate</code> is
 *  <code>false</code> and a <code>NodeTypeDefinition</code> within the
 *  <code>Collection</code> specifies a node type name that is already
 *  registered.
 * @throws UnsupportedRepositoryOperationException if this implementation
 *  does not support node type registration.
 * @throws RepositoryException if another error occurs.
 * @since JCR 2.0
 */
public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] definitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException {
    // make sure the editing session is allowed to register node types.
    context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT);
    NodeTypeRegistry registry = context.getNodeTypeRegistry();
    // split the node types into new and already registered node types.
    // this way we can register new node types together with already
    // registered node types which make circular dependencies possible
    List<QNodeTypeDefinition> addedDefs = new ArrayList<QNodeTypeDefinition>();
    List<QNodeTypeDefinition> modifiedDefs = new ArrayList<QNodeTypeDefinition>();
    for (NodeTypeDefinition definition : definitions) {
        // convert to QNodeTypeDefinition
        QNodeTypeDefinition def = toNodeTypeDef(definition);
        if (registry.isRegistered(def.getName())) {
            if (allowUpdate) {
                modifiedDefs.add(def);
            } else {
                throw new NodeTypeExistsException(definition.getName());
            }
        } else {
            addedDefs.add(def);
        }
    }
    try {
        ArrayList<NodeType> result = new ArrayList<NodeType>();
        // register new node types
        result.addAll(registerNodeTypes(addedDefs));
        // re-register already existing node types
        for (QNodeTypeDefinition nodeTypeDef : modifiedDefs) {
            registry.reregisterNodeType(nodeTypeDef);
            result.add(getNodeType(nodeTypeDef.getName()));
        }
        return new NodeTypeIteratorAdapter(result);
    } catch (InvalidNodeTypeDefException e) {
        throw new InvalidNodeTypeDefinitionException(e.getMessage(), e);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)

Aggregations

InvalidNodeTypeDefinitionException (javax.jcr.nodetype.InvalidNodeTypeDefinitionException)5 Name (org.apache.jackrabbit.spi.Name)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 ValueConstraint (org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)4 ArrayList (java.util.ArrayList)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)2 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)2 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 NodeType (javax.jcr.nodetype.NodeType)1 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)1 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)1 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1 QValue (org.apache.jackrabbit.spi.QValue)1