Search in sources :

Example 1 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.

the class TypeEditorProvider method isTrivialChange.

private boolean isTrivialChange(ReadOnlyNodeTypeManager ntBefore, ReadOnlyNodeTypeManager ntAfter, String nodeType) {
    NodeType nb, na;
    try {
        nb = ntBefore.getNodeType(nodeType);
    } catch (NoSuchNodeTypeException ex) {
        LOG.info(nodeType + " not present in 'before' state");
        return true;
    } catch (RepositoryException ex) {
        LOG.info("getting node type", ex);
        return false;
    }
    try {
        na = ntAfter.getNodeType(nodeType);
    } catch (NoSuchNodeTypeException ex) {
        LOG.info(nodeType + " was removed");
        return false;
    } catch (RepositoryException ex) {
        LOG.info("getting node type", ex);
        return false;
    }
    NodeTypeDefDiff diff = NodeTypeDefDiff.create(nb, na);
    if (!diff.isModified()) {
        LOG.info("Node type " + nodeType + " was not changed");
        return true;
    } else if (diff.isTrivial()) {
        LOG.info("Node type change for " + nodeType + " appears to be trivial");
        return true;
    } else {
        LOG.info("Node type change for " + nodeType + " requires repository scan: " + diff);
        return false;
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 2 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.

the class ReadWriteNodeTypeManager method registerNodeTypes.

@Override
public final NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] ntds, boolean allowUpdate) throws RepositoryException {
    Root root = getWriteRoot();
    try {
        Tree tree = getOrCreateNodeTypes(root);
        for (NodeTypeDefinition ntd : ntds) {
            NodeTypeTemplateImpl template;
            if (ntd instanceof NodeTypeTemplateImpl) {
                template = (NodeTypeTemplateImpl) ntd;
            } else {
                // some external template implementation, copy before proceeding
                template = new NodeTypeTemplateImpl(getNamePathMapper(), ntd);
            }
            template.writeTo(tree, allowUpdate);
        }
        root.commit();
        refresh();
        List<NodeType> types = new ArrayList<NodeType>(ntds.length);
        for (NodeTypeDefinition ntd : ntds) {
            types.add(getNodeType(ntd.getName()));
        }
        return new NodeTypeIteratorAdapter(types);
    } catch (CommitFailedException e) {
        String message = "Failed to register node types.";
        throw e.asRepositoryException(message);
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) NodeType(javax.jcr.nodetype.NodeType) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 3 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.

the class NodeTypeImpl method getDeclaredSupertypes.

@Override
public NodeType[] getDeclaredSupertypes() {
    NodeType[] supertypes = NO_NODE_TYPES;
    String[] oakNames = getNames(JCR_SUPERTYPES);
    if (oakNames != null && oakNames.length > 0) {
        supertypes = new NodeType[oakNames.length];
        Tree root = definition.getParent();
        for (int i = 0; i < oakNames.length; i++) {
            Tree type = root.getChild(oakNames[i]);
            checkState(type.exists());
            supertypes[i] = new NodeTypeImpl(type, mapper);
        }
    }
    return supertypes;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 4 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.

the class NodeTypeImpl method internalGetPropertyDefinitions.

Collection<PropertyDefinition> internalGetPropertyDefinitions() {
    // TODO distinguish between additive and overriding property definitions. See 3.7.6.8 Item Definitions in Subtypes
    Collection<PropertyDefinition> definitions = new ArrayList<PropertyDefinition>();
    definitions.addAll(Arrays.asList(getDeclaredPropertyDefinitions()));
    for (NodeType type : getSupertypes()) {
        definitions.addAll(Arrays.asList(type.getDeclaredPropertyDefinitions()));
    }
    return definitions;
}
Also used : NodeType(javax.jcr.nodetype.NodeType) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 5 with NodeType

use of javax.jcr.nodetype.NodeType in project jackrabbit-oak by apache.

the class EffectiveNodeType method addNodeType.

private void addNodeType(NodeTypeImpl type) {
    String name = type.getName();
    if (!nodeTypes.containsKey(name)) {
        nodeTypes.put(name, type);
        NodeType[] supertypes = type.getDeclaredSupertypes();
        for (NodeType supertype : supertypes) {
            // FIXME
            addNodeType((NodeTypeImpl) supertype);
        }
    }
}
Also used : NodeType(javax.jcr.nodetype.NodeType)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)272 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)84 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)81 Node (javax.jcr.Node)63 Value (javax.jcr.Value)60 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)55 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)46 NodeDefinition (javax.jcr.nodetype.NodeDefinition)45 RepositoryException (javax.jcr.RepositoryException)41 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 Session (javax.jcr.Session)29 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 NoSuchNodeTypeException (javax.jcr.nodetype.NoSuchNodeTypeException)15 Name (org.apache.jackrabbit.spi.Name)15 HashSet (java.util.HashSet)14 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)12 NodeIterator (javax.jcr.NodeIterator)7 Property (javax.jcr.Property)7 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)7