Search in sources :

Example 56 with QNodeTypeDefinition

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

the class ClusterNode method process.

/**
 * {@inheritDoc}
 */
public void process(NodeTypeRecord record) {
    if (nodeTypeListener == null) {
        String msg = "NodeType listener unavailable.";
        log.error(msg);
        return;
    }
    Collection coll = record.getCollection();
    try {
        switch(record.getOperation()) {
            case NodeTypeRecord.REGISTER:
                nodeTypeListener.externalRegistered(coll);
                break;
            case NodeTypeRecord.UNREGISTER:
                nodeTypeListener.externalUnregistered(coll);
                break;
            case NodeTypeRecord.REREGISTER:
                QNodeTypeDefinition ntd = (QNodeTypeDefinition) coll.iterator().next();
                nodeTypeListener.externalReregistered(ntd);
                break;
        }
    } catch (InvalidNodeTypeDefException e) {
        String msg = "Unable to deliver node type operation: " + e.getMessage();
        log.error(msg);
    } catch (RepositoryException e) {
        String msg = "Unable to deliver node type operation: " + e.getMessage();
        log.error(msg);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefException(org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException) Collection(java.util.Collection) RepositoryException(javax.jcr.RepositoryException)

Example 57 with QNodeTypeDefinition

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

the class EffectiveNodeType method create.

/**
 * Package private factory method.
 * <p>
 * Creates an effective node type representation of a node type definition.
 * Note that the definitions of all referenced node types must be contained
 * in <code>ntdCache</code>.
 *
 * @param ntd      node type definition
 * @param entCache cache of already-built effective node types
 * @param ntdCache cache of node type definitions, used to resolve dependencies
 * @return an effective node type representation of the given node type definition.
 * @throws NodeTypeConflictException if the node type definition is invalid,
 *                                   e.g. due to ambiguous child definitions.
 * @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
 *                                 could not be resolved.
 */
static EffectiveNodeType create(QNodeTypeDefinition ntd, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws NodeTypeConflictException, NoSuchNodeTypeException {
    // create empty effective node type instance
    EffectiveNodeType ent = new EffectiveNodeType();
    Name ntName = ntd.getName();
    // prepare new instance
    ent.mergedNodeTypes.add(ntName);
    ent.allNodeTypes.add(ntName);
    // map of all item definitions (maps id to definition)
    // used to effectively detect ambiguous child definitions where
    // ambiguity is defined in terms of definition identity
    Set<QItemDefinition> itemDefs = new HashSet<QItemDefinition>();
    QNodeDefinition[] cnda = ntd.getChildNodeDefs();
    for (QNodeDefinition aCnda : cnda) {
        // this node type definition
        if (itemDefs.contains(aCnda)) {
            // conflict
            String msg;
            if (aCnda.definesResidual()) {
                msg = ntName + " contains ambiguous residual child node definitions";
            } else {
                msg = ntName + " contains ambiguous definitions for child node named " + aCnda.getName();
            }
            log.debug(msg);
            throw new NodeTypeConflictException(msg);
        } else {
            itemDefs.add(aCnda);
        }
        if (aCnda.definesResidual()) {
            // residual node definition
            ent.unnamedItemDefs.add(aCnda);
        } else {
            // named node definition
            Name name = aCnda.getName();
            List<QItemDefinition> defs = ent.namedItemDefs.get(name);
            if (defs == null) {
                defs = new ArrayList<QItemDefinition>();
                ent.namedItemDefs.put(name, defs);
            }
            if (defs.size() > 0) {
                /**
                 * there already exists at least one definition with that
                 * name; make sure none of them is auto-create
                 */
                for (QItemDefinition def : defs) {
                    if (aCnda.isAutoCreated() || def.isAutoCreated()) {
                        // conflict
                        String msg = "There are more than one 'auto-create' item definitions for '" + name + "' in node type '" + ntName + "'";
                        log.debug(msg);
                        throw new NodeTypeConflictException(msg);
                    }
                }
            }
            defs.add(aCnda);
        }
    }
    QPropertyDefinition[] pda = ntd.getPropertyDefs();
    for (QPropertyDefinition aPda : pda) {
        // this node type definition
        if (itemDefs.contains(aPda)) {
            // conflict
            String msg;
            if (aPda.definesResidual()) {
                msg = ntName + " contains ambiguous residual property definitions";
            } else {
                msg = ntName + " contains ambiguous definitions for property named " + aPda.getName();
            }
            log.debug(msg);
            throw new NodeTypeConflictException(msg);
        } else {
            itemDefs.add(aPda);
        }
        if (aPda.definesResidual()) {
            // residual property definition
            ent.unnamedItemDefs.add(aPda);
        } else {
            // named property definition
            Name name = aPda.getName();
            List<QItemDefinition> defs = ent.namedItemDefs.get(name);
            if (defs == null) {
                defs = new ArrayList<QItemDefinition>();
                ent.namedItemDefs.put(name, defs);
            }
            if (defs.size() > 0) {
                /**
                 * there already exists at least one definition with that
                 * name; make sure none of them is auto-create
                 */
                for (QItemDefinition def : defs) {
                    if (aPda.isAutoCreated() || def.isAutoCreated()) {
                        // conflict
                        String msg = "There are more than one 'auto-create' item definitions for '" + name + "' in node type '" + ntName + "'";
                        log.debug(msg);
                        throw new NodeTypeConflictException(msg);
                    }
                }
            }
            defs.add(aPda);
        }
    }
    // resolve supertypes recursively
    Name[] supertypes = ntd.getSupertypes();
    if (supertypes.length > 0) {
        EffectiveNodeType base = NodeTypeRegistry.getEffectiveNodeType(supertypes, entCache, ntdCache);
        ent.internalMerge(base, true);
    }
    // resolve 'orderable child nodes' attribute value (JCR-1947)
    if (ntd.hasOrderableChildNodes()) {
        ent.orderableChildNodes = true;
    } else {
        Name[] nta = ent.getInheritedNodeTypes();
        for (Name aNta : nta) {
            QNodeTypeDefinition def = ntdCache.get(aNta);
            if (def.hasOrderableChildNodes()) {
                ent.orderableChildNodes = true;
                break;
            }
        }
    }
    // resolve 'primary item' attribute value (JCR-1947)
    if (ntd.getPrimaryItemName() != null) {
        ent.primaryItemName = ntd.getPrimaryItemName();
    } else {
        Name[] nta = ent.getInheritedNodeTypes();
        for (Name aNta : nta) {
            QNodeTypeDefinition def = ntdCache.get(aNta);
            if (def.getPrimaryItemName() != null) {
                ent.primaryItemName = def.getPrimaryItemName();
                break;
            }
        }
    }
    // we're done
    return ent;
}
Also used : QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) HashSet(java.util.HashSet)

Example 58 with QNodeTypeDefinition

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

the class PropertyTypeRegistry method nodeTypeRegistered.

public void nodeTypeRegistered(Name ntName) {
    try {
        QNodeTypeDefinition def = registry.getNodeTypeDef(ntName);
        QPropertyDefinition[] propDefs = def.getPropertyDefs();
        synchronized (typeMapping) {
            for (QPropertyDefinition propDef : propDefs) {
                int type = propDef.getRequiredType();
                if (!propDef.definesResidual() && type != PropertyType.UNDEFINED) {
                    Name name = propDef.getName();
                    // only remember defined property types
                    TypeMapping[] types = typeMapping.get(name);
                    if (types == null) {
                        types = new TypeMapping[1];
                    } else {
                        TypeMapping[] tmp = new TypeMapping[types.length + 1];
                        System.arraycopy(types, 0, tmp, 0, types.length);
                        types = tmp;
                    }
                    types[types.length - 1] = new TypeMapping(ntName, type, propDef.isMultiple());
                    typeMapping.put(name, types);
                }
            }
        }
    } catch (NoSuchNodeTypeException e) {
        log.error("Unable to get newly registered node type definition for name: " + ntName);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) Name(org.apache.jackrabbit.spi.Name) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Aggregations

QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)58 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)7 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)6 HashMap (java.util.HashMap)5 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)4 InvalidNodeTypeDefException (org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException)4 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)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 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