Search in sources :

Example 21 with QNodeTypeDefinition

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

the class ClusterRecordTest method testNodeTypeReregistration.

/**
     * Test producing and consuming a node type reregistration.
     * @throws Exception
     */
public void testNodeTypeReregistration() throws Exception {
    QNodeTypeDefinitionBuilder ntd = new QNodeTypeDefinitionBuilder();
    ntd.setName(NameFactoryImpl.getInstance().create("", "test"));
    ntd.setSupertypes(new Name[] { NameConstants.NT_BASE });
    ArrayList<QNodeTypeDefinition> list = new ArrayList<QNodeTypeDefinition>();
    list.add(ntd.build());
    NodeTypeEvent event = new NodeTypeEvent(NodeTypeEvent.REREGISTER, list);
    master.reregistered(ntd.build());
    SimpleEventListener listener = new SimpleEventListener();
    slave.setListener((NodeTypeEventListener) listener);
    slave.sync();
    assertEquals(1, listener.getClusterEvents().size());
    assertEquals(listener.getClusterEvents().get(0), event);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeEvent(org.apache.jackrabbit.core.cluster.SimpleEventListener.NodeTypeEvent) ArrayList(java.util.ArrayList) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Example 22 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 23 with QNodeTypeDefinition

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

the class NodeTypeManagerImpl method getNodeType.

/**
     * @param name node type name
     * @return node type
     * @throws NoSuchNodeTypeException if the nodetype does not exit
     */
@Override
public NodeTypeImpl getNodeType(Name name) throws NoSuchNodeTypeException {
    synchronized (ntCache) {
        NodeTypeImpl nt = ntCache.get(name);
        if (nt == null) {
            NodeTypeRegistry registry = context.getNodeTypeRegistry();
            EffectiveNodeType ent = registry.getEffectiveNodeType(name);
            QNodeTypeDefinition def = registry.getNodeTypeDef(name);
            nt = new NodeTypeImpl(ent, def, this, context, context.getValueFactory(), context.getDataStore());
            ntCache.put(name, nt);
        }
        return nt;
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition)

Example 24 with QNodeTypeDefinition

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

the class NodeTypeRegistry method getEffectiveNodeType.

/**
     * @param ntName node type name
     * @param entCache cache of already-built effective node types
     * @param ntdCache cache of node type definitions
     * @return the effective node type
     * @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
     *                                 could not be resolved.
     */
static EffectiveNodeType getEffectiveNodeType(Name ntName, EffectiveNodeTypeCache entCache, Map<Name, QNodeTypeDefinition> ntdCache) throws NoSuchNodeTypeException {
    // 1. check if effective node type has already been built
    EffectiveNodeTypeCache.Key key = entCache.getKey(new Name[] { ntName });
    EffectiveNodeType ent = entCache.get(key);
    if (ent != null) {
        return ent;
    }
    // 2. make sure we've got the definition of the specified node type
    QNodeTypeDefinition ntd = ntdCache.get(ntName);
    if (ntd == null) {
        throw new NoSuchNodeTypeException(ntName.toString());
    }
    // 3. build effective node type
    synchronized (entCache) {
        try {
            ent = EffectiveNodeType.create(ntd, entCache, ntdCache);
            // store new effective node type
            entCache.put(ent);
            return ent;
        } catch (NodeTypeConflictException ntce) {
            // should never get here as all known node types should be valid!
            String msg = "internal error: encountered invalid registered node type " + ntName;
            log.debug(msg);
            throw new NoSuchNodeTypeException(msg, ntce);
        }
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 25 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)

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