Search in sources :

Example 16 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class EffectiveNodeType method getNamedPropDefs.

public QPropertyDefinition[] getNamedPropDefs(Name name) {
    List<QItemDefinition> list = namedItemDefs.get(name);
    if (list == null || list.size() == 0) {
        return QPropertyDefinition.EMPTY_ARRAY;
    }
    ArrayList<QPropertyDefinition> defs = new ArrayList<QPropertyDefinition>(list.size());
    for (QItemDefinition def : list) {
        if (!def.definesNode()) {
            defs.add((QPropertyDefinition) def);
        }
    }
    if (defs.size() == 0) {
        return QPropertyDefinition.EMPTY_ARRAY;
    }
    return defs.toArray(new QPropertyDefinition[defs.size()]);
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Example 17 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class EffectiveNodeType method clone.

@Override
protected Object clone() {
    EffectiveNodeType clone = new EffectiveNodeType();
    clone.mergedNodeTypes.addAll(mergedNodeTypes);
    clone.inheritedNodeTypes.addAll(inheritedNodeTypes);
    clone.allNodeTypes.addAll(allNodeTypes);
    for (Name name : namedItemDefs.keySet()) {
        List<QItemDefinition> list = namedItemDefs.get(name);
        clone.namedItemDefs.put(name, new ArrayList<QItemDefinition>(list));
    }
    clone.unnamedItemDefs.addAll(unnamedItemDefs);
    clone.orderableChildNodes = orderableChildNodes;
    clone.primaryItemName = primaryItemName;
    return clone;
}
Also used : QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 18 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class NodeTypeDefinitionImpl method getDeclaredChildNodeDefinitions.

/**
     * {@inheritDoc}
     */
public NodeDefinition[] getDeclaredChildNodeDefinitions() {
    QItemDefinition[] cnda = ntd.getChildNodeDefs();
    NodeDefinition[] nodeDefs = new NodeDefinition[cnda.length];
    for (int i = 0; i < cnda.length; i++) {
        nodeDefs[i] = new NodeDefinitionImpl(cnda[i], null, resolver);
    }
    return nodeDefs;
}
Also used : NodeDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl) NodeDefinition(javax.jcr.nodetype.NodeDefinition) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Example 19 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class EffectiveNodeTypeImpl method internalMerge.

/**
     * Internal helper method which merges another <code>EffectiveNodeType</code>
     * instance with <i>this</i> instance.
     * <p>
     * Warning: This instance might be in an inconsistent state if an exception
     * is thrown.
     *
     * @param other
     * @param supertype true if the merge is a result of inheritance, i.e. <code>other</code>
     *                  represents one or more supertypes of this instance; otherwise false, i.e.
     *                  the merge is the result of an explicit aggregation
     * @throws ConstraintViolationException
     */
synchronized void internalMerge(EffectiveNodeTypeImpl other, boolean supertype) throws ConstraintViolationException {
    Name[] nta = other.getAllNodeTypes();
    int includedCount = 0;
    for (int i = 0; i < nta.length; i++) {
        if (includesNodeType(nta[i])) {
            // redundant node type
            log.debug("node type '" + nta[i] + "' is already contained.");
            includedCount++;
        }
    }
    if (includedCount == nta.length) {
        // total overlap, ignore
        return;
    }
    // named item definitions
    QItemDefinition[] defs = other.getNamedItemDefs();
    for (int i = 0; i < defs.length; i++) {
        QItemDefinition qDef = defs[i];
        if (includesNodeType(qDef.getDeclaringNodeType())) {
            // ignore redundant definitions
            continue;
        }
        Name name = qDef.getName();
        List<QItemDefinition> existingDefs = namedItemDefs.get(name);
        if (existingDefs != null) {
            if (existingDefs.size() > 0) {
                // there already exists at least one definition with that name
                for (int j = 0; j < existingDefs.size(); j++) {
                    QItemDefinition qItemDef = existingDefs.get(j);
                    // make sure none of them is auto-create
                    if (qDef.isAutoCreated() || qItemDef.isAutoCreated()) {
                        // conflict
                        String msg = "The item definition for '" + name + "' in node type '" + qDef.getDeclaringNodeType() + "' conflicts with the one of node type '" + qItemDef.getDeclaringNodeType() + "': name collision with auto-create definition";
                        log.debug(msg);
                        throw new ConstraintViolationException(msg);
                    }
                    // check ambiguous definitions
                    if (qDef.definesNode() == qItemDef.definesNode()) {
                        if (!qDef.definesNode()) {
                            // property definition
                            QPropertyDefinition pd = (QPropertyDefinition) qDef;
                            QPropertyDefinition epd = (QPropertyDefinition) qItemDef;
                            // compare type & multiValued flag
                            if (pd.getRequiredType() == epd.getRequiredType() && pd.isMultiple() == epd.isMultiple()) {
                                // conflict
                                String msg = "The property definition for '" + name + "' in node type '" + qDef.getDeclaringNodeType() + "' conflicts with the one of node type '" + qItemDef.getDeclaringNodeType() + "': ambiguous property definition. " + "they must differ in required type " + "or cardinality.";
                                log.debug(msg);
                                throw new ConstraintViolationException(msg);
                            }
                        } else {
                            // child node definition
                            // conflict
                            String msg = "The child node definition for '" + name + "' in node type '" + qDef.getDeclaringNodeType() + "' conflicts with the one of node type '" + qItemDef.getDeclaringNodeType() + "': ambiguous child node definition. name must differ.";
                            log.debug(msg);
                            throw new ConstraintViolationException(msg);
                        }
                    }
                }
            }
        } else {
            existingDefs = new ArrayList<QItemDefinition>();
            namedItemDefs.put(name, existingDefs);
        }
        existingDefs.add(qDef);
    }
    // residual item definitions
    defs = other.getUnnamedItemDefs();
    for (int i = 0; i < defs.length; i++) {
        QItemDefinition qDef = defs[i];
        if (includesNodeType(qDef.getDeclaringNodeType())) {
            // ignore redundant definitions
            continue;
        }
        for (QItemDefinition existing : unnamedItemDefs) {
            // compare with existing definition
            if (qDef.definesNode() == existing.definesNode()) {
                if (!qDef.definesNode()) {
                    // property definition
                    QPropertyDefinition pd = (QPropertyDefinition) qDef;
                    QPropertyDefinition epd = (QPropertyDefinition) existing;
                    // compare type & multiValued flag
                    if (pd.getRequiredType() == epd.getRequiredType() && pd.isMultiple() == epd.isMultiple() && pd.getOnParentVersion() == epd.getOnParentVersion()) {
                        // conflict
                        // TODO: need to take more aspects into account
                        // TODO: getMatchingPropDef needs to check this as well
                        String msg = "A property definition in node type '" + qDef.getDeclaringNodeType() + "' conflicts with node type '" + existing.getDeclaringNodeType() + "': ambiguous residual property definition";
                        log.debug(msg);
                        throw new ConstraintViolationException(msg);
                    }
                } else {
                    // child node definition
                    QNodeDefinition nd = (QNodeDefinition) qDef;
                    QNodeDefinition end = (QNodeDefinition) existing;
                    // compare required & default primary types
                    if (Arrays.equals(nd.getRequiredPrimaryTypes(), end.getRequiredPrimaryTypes()) && (nd.getDefaultPrimaryType() == null ? end.getDefaultPrimaryType() == null : nd.getDefaultPrimaryType().equals(end.getDefaultPrimaryType()))) {
                        // conflict
                        String msg = "A child node definition in node type '" + qDef.getDeclaringNodeType() + "' conflicts with node type '" + existing.getDeclaringNodeType() + "': ambiguous residual child node definition";
                        log.debug(msg);
                        throw new ConstraintViolationException(msg);
                    }
                }
            }
        }
        unnamedItemDefs.add(qDef);
    }
    for (int i = 0; i < nta.length; i++) {
        allNodeTypes.add(nta[i]);
    }
    if (supertype) {
        // implicit merge as result of inheritance
        // add other merged node types as supertypes
        nta = other.getMergedNodeTypes();
        for (int i = 0; i < nta.length; i++) {
            inheritedNodeTypes.add(nta[i]);
        }
        // add supertypes of other merged node types as supertypes
        nta = other.getInheritedNodeTypes();
        for (int i = 0; i < nta.length; i++) {
            inheritedNodeTypes.add(nta[i]);
        }
    } else {
        // explicit merge
        // merge with other merged node types
        nta = other.getMergedNodeTypes();
        for (int i = 0; i < nta.length; i++) {
            mergedNodeTypes.add(nta[i]);
        }
        // add supertypes of other merged node types as supertypes
        nta = other.getInheritedNodeTypes();
        for (int i = 0; i < nta.length; i++) {
            inheritedNodeTypes.add(nta[i]);
        }
    }
}
Also used : QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 20 with QItemDefinition

use of org.apache.jackrabbit.spi.QItemDefinition in project jackrabbit by apache.

the class ItemStateValidator method checkProtection.

/**
     * Checks if the definition of the given item state indicates a protected
     * status.
     *
     * @param itemState
     * @throws ConstraintViolationException If the definition of the given
     * item state indicates that the state is protected.
     * @see QItemDefinition#isProtected()
     */
private void checkProtection(ItemState itemState) throws ConstraintViolationException, RepositoryException {
    QItemDefinition def;
    if (itemState.isNode()) {
        def = ((NodeState) itemState).getDefinition();
    } else {
        def = ((PropertyState) itemState).getDefinition();
    }
    checkProtection(def);
}
Also used : QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition)

Aggregations

QItemDefinition (org.apache.jackrabbit.spi.QItemDefinition)22 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 Name (org.apache.jackrabbit.spi.Name)10 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)9 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)9 ArrayList (java.util.ArrayList)7 RepositoryException (javax.jcr.RepositoryException)6 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 NodeState (org.apache.jackrabbit.core.state.NodeState)5 HashSet (java.util.HashSet)4 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 AccessDeniedException (javax.jcr.AccessDeniedException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 PropertyId (org.apache.jackrabbit.core.id.PropertyId)3 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)3 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)3 AccessManager (org.apache.jackrabbit.core.security.AccessManager)3 PropertyState (org.apache.jackrabbit.core.state.PropertyState)3