Search in sources :

Example 16 with QNodeTypeDefinition

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

the class NodeTypeRegistry method toString.

//--------------------------------------------------------------< Object >
/**
     * {@inheritDoc}
     */
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("NodeTypeRegistry (" + super.toString() + ")\n");
    builder.append("Registered NodeTypes:\n");
    for (QNodeTypeDefinition ntd : registeredNTDefs.values()) {
        builder.append(ntd.getName());
        builder.append("\n");
        builder.append("\tSupertypes: " + Arrays.toString(ntd.getSupertypes()) + "\n");
        builder.append("\tMixin\t" + ntd.isMixin() + "\n");
        builder.append("\tOrderableChildNodes\t" + ntd.hasOrderableChildNodes() + "\n");
        builder.append("\tPrimaryItemName\t" + (ntd.getPrimaryItemName() == null ? "<null>" : ntd.getPrimaryItemName().toString()) + "\n");
        QPropertyDefinition[] pd = ntd.getPropertyDefs();
        for (QPropertyDefinition aPd : pd) {
            builder.append("\tPropertyDefinition\n");
            builder.append(" (declared in " + aPd.getDeclaringNodeType() + ")\n");
            builder.append("\t\tName\t\t" + (aPd.definesResidual() ? "*" : aPd.getName().toString()) + "\n");
            String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
            builder.append("\t\tRequiredType\t" + type + "\n");
            QValueConstraint[] vca = aPd.getValueConstraints();
            StringBuilder constraints = new StringBuilder();
            if (vca == null) {
                constraints.append("<null>");
            } else {
                for (QValueConstraint aVca : vca) {
                    if (constraints.length() > 0) {
                        constraints.append(", ");
                    }
                    constraints.append(aVca.getString());
                }
            }
            builder.append("\t\tValueConstraints\t" + constraints + "\n");
            QValue[] defVals = aPd.getDefaultValues();
            StringBuilder defaultValues = new StringBuilder();
            if (defVals == null) {
                defaultValues.append("<null>");
            } else {
                for (QValue defVal : defVals) {
                    if (defaultValues.length() > 0) {
                        defaultValues.append(", ");
                    }
                    defaultValues.append(defVal.toString());
                }
            }
            builder.append("\t\tDefaultValue\t" + defaultValues + "\n");
            builder.append("\t\tAutoCreated\t" + aPd.isAutoCreated() + "\n");
            builder.append("\t\tMandatory\t" + aPd.isMandatory() + "\n");
            builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()) + "\n");
            builder.append("\t\tProtected\t" + aPd.isProtected() + "\n");
            builder.append("\t\tMultiple\t" + aPd.isMultiple() + "\n");
        }
        QNodeDefinition[] nd = ntd.getChildNodeDefs();
        for (QNodeDefinition aNd : nd) {
            builder.append("\tNodeDefinition\\n");
            builder.append(" (declared in " + aNd.getDeclaringNodeType() + ")\\n");
            builder.append("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()) + "\n");
            Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
            if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
                for (Name reqPrimaryType : reqPrimaryTypes) {
                    builder.append("\t\tRequiredPrimaryType\t" + reqPrimaryType + "\n");
                }
            }
            Name defPrimaryType = aNd.getDefaultPrimaryType();
            if (defPrimaryType != null) {
                builder.append("\n\t\tDefaultPrimaryType\t" + defPrimaryType + "\n");
            }
            builder.append("\n\t\tAutoCreated\t" + aNd.isAutoCreated() + "\n");
            builder.append("\t\tMandatory\t" + aNd.isMandatory() + "\n");
            builder.append("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()) + "\n");
            builder.append("\t\tProtected\t" + aNd.isProtected() + "\n");
            builder.append("\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings() + "\n");
        }
    }
    builder.append(entCache);
    return builder.toString();
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition)

Example 17 with QNodeTypeDefinition

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

the class NodeTypeRegistry method checkForCircularInheritance.

static void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntDefCache) throws InvalidNodeTypeDefException, RepositoryException {
    for (Name nt : supertypes) {
        int pos = inheritanceChain.lastIndexOf(nt);
        if (pos >= 0) {
            StringBuilder buf = new StringBuilder();
            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(nt);
            throw new InvalidNodeTypeDefException("circular inheritance detected: " + buf.toString());
        }
        try {
            QNodeTypeDefinition ntd = ntDefCache.get(nt);
            Name[] sta = ntd.getSupertypes();
            if (sta.length > 0) {
                // check recursively
                inheritanceChain.push(nt);
                checkForCircularInheritance(sta, inheritanceChain, ntDefCache);
                inheritanceChain.pop();
            }
        } catch (NoSuchNodeTypeException nsnte) {
            String msg = "unknown supertype: " + nt;
            log.debug(msg);
            throw new InvalidNodeTypeDefException(msg, nsnte);
        }
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QValueConstraint(org.apache.jackrabbit.spi.QValueConstraint) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 18 with QNodeTypeDefinition

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

the class NodeTypeRegistry method getEffectiveNodeType.

/**
     * Returns an effective node type representation of the given node types.
     *
     * @param ntNames  array of node type names
     * @param entCache cache of already-built effective node types
     * @param ntdCache cache of node type definitions
     * @return the desired effective node type
     * @throws NodeTypeConflictException if the effective node type representation
     *                                   could not be built due to conflicting
     *                                   node type definitions.
     * @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
     *                                 could not be resolved.
     */
static EffectiveNodeType getEffectiveNodeType(Name[] ntNames, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws NodeTypeConflictException, NoSuchNodeTypeException {
    EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
    // 1. check if aggregate has already been built
    if (entCache.contains(key)) {
        return entCache.get(key);
    }
    // 2. make sure we've got the definitions of the specified node types
    for (Name ntName : ntNames) {
        if (!ntdCache.containsKey(ntName)) {
            throw new NoSuchNodeTypeException(ntName.toString());
        }
    }
    // 3. build aggregate
    EffectiveNodeTypeCache.Key requested = key;
    EffectiveNodeType result = null;
    synchronized (entCache) {
        // build list of 'best' existing sub-aggregates
        while (key.getNames().length > 0) {
            // find the (sub) key that matches the current key the best
            EffectiveNodeTypeCache.Key subKey = entCache.findBest(key);
            if (subKey != null) {
                EffectiveNodeType ent = entCache.get(subKey);
                if (result == null) {
                    result = ent;
                } else {
                    result = result.merge(ent);
                    // store intermediate result
                    entCache.put(result);
                }
                // subtract the result from the temporary key
                key = key.subtract(subKey);
            } else {
                /**
                     * no matching sub-aggregates found:
                     * build aggregate of remaining node types through iteration
                     */
                Name[] remainder = key.getNames();
                for (Name aRemainder : remainder) {
                    QNodeTypeDefinition ntd = ntdCache.get(aRemainder);
                    EffectiveNodeType ent = EffectiveNodeType.create(ntd, entCache, ntdCache);
                    // store new effective node type
                    entCache.put(ent);
                    if (result == null) {
                        result = ent;
                    } else {
                        result = result.merge(ent);
                        // store intermediate result (sub-aggregate)
                        entCache.put(result);
                    }
                }
                break;
            }
        }
    }
    // the redundant nodetypes
    if (!entCache.contains(requested)) {
        entCache.put(requested, result);
    }
    // we're done
    return result;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 19 with QNodeTypeDefinition

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

the class NodeTypeRegistry method internalUnregister.

private void internalUnregister(Name name) throws NoSuchNodeTypeException {
    QNodeTypeDefinition ntd = registeredNTDefs.get(name);
    if (ntd == null) {
        throw new NoSuchNodeTypeException(name.toString());
    }
    registeredNTDefs.remove(name);
    entCache.invalidate(name);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 20 with QNodeTypeDefinition

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

the class NodeTypeRegistry method reregisterNodeType.

/**
     * Internal implementation of {@link #reregisterNodeType(QNodeTypeDefinition)}.
     *
     * @param ntd node type definition
     * @param external whether this invocation should be considered external
     * @return the new effective node type
     * @throws NoSuchNodeTypeException if <code>ntd</code> refers to an
     *                                 unknown node type
     * @throws InvalidNodeTypeDefException if the node type definition
     *                                     is invalid
     * @throws RepositoryException if another error occurs
     */
private EffectiveNodeType reregisterNodeType(QNodeTypeDefinition ntd, boolean external) throws NoSuchNodeTypeException, InvalidNodeTypeDefException, RepositoryException {
    EffectiveNodeType entNew;
    synchronized (this) {
        Name name = ntd.getName();
        if (!registeredNTDefs.containsKey(name)) {
            throw new NoSuchNodeTypeException(name.toString());
        }
        if (builtInNTDefs.contains(name)) {
            throw new RepositoryException(name.toString() + ": can't reregister built-in node type.");
        }
        /**
             * validate new node type definition
             */
        ntd = checkNtBaseSubtyping(ntd, registeredNTDefs);
        validateNodeTypeDef(ntd, entCache, registeredNTDefs, nsReg, false);
        /**
             * build diff of current and new definition and determine type of change
             */
        QNodeTypeDefinition ntdOld = registeredNTDefs.get(name);
        NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
        if (!diff.isModified()) {
            // the definition has not been modified, there's nothing to do here...
            return getEffectiveNodeType(name);
        }
        // make sure existing content would not conflict
        // with new node type definition
        checkForConflictingContent(ntd, diff);
        /**
             * re-register node type definition and update caches &
             * notify listeners on re-registration
             */
        internalUnregister(name);
        // remove old node type definition from store
        customNTDefs.remove(name);
        entNew = internalRegister(ntd);
        // add new node type definition to store
        customNTDefs.add(ntd);
        // persist node type definitions
        persistCustomNodeTypeDefs(customNTDefs);
        // notify listeners
        notifyReRegistered(name);
    }
    // inform cluster if this is not an external invocation
    if (!external && eventChannel != null) {
        eventChannel.reregistered(ntd);
    }
    return entNew;
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) NodeTypeDefDiff(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff)

Aggregations

QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)57 Name (org.apache.jackrabbit.spi.Name)21 ArrayList (java.util.ArrayList)13 RepositoryException (javax.jcr.RepositoryException)11 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)9 NodeType (javax.jcr.nodetype.NodeType)6 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)6 HashMap (java.util.HashMap)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)4 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)4 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)4 QValueConstraint (org.apache.jackrabbit.spi.QValueConstraint)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 QNodeTypeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)4 CompactNodeTypeDefReader (org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader)3 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)3 NamespaceMapping (org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping)3 QDefinitionBuilderFactory (org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory)3 QNodeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)3