Search in sources :

Example 46 with NodeType

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

the class NodeImpl method internalSetPrimaryType.

private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException {
    // TODO: figure out the right place for this check
    // throws on not found
    NodeType nt = getNodeTypeManager().getNodeType(nodeTypeName);
    if (nt.isAbstract() || nt.isMixin()) {
        throw new ConstraintViolationException(getNodePath());
    }
    // TODO: END
    PropertyState state = PropertyStates.createProperty(JCR_PRIMARYTYPE, getOakName(nodeTypeName), NAME);
    dlg.setProperty(state, true, true);
    dlg.setOrderableChildren(nt.hasOrderableChildNodes());
}
Also used : NodeType(javax.jcr.nodetype.NodeType) EffectiveNodeType(org.apache.jackrabbit.oak.spi.nodetype.EffectiveNodeType) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 47 with NodeType

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

the class GQL method collectNodeTypes.

/**
 * Resolves and collects all node types that match <code>ntName</code>.
 *
 * @param ntName the name of a node type (optionally without prefix).
 * @throws RepositoryException if an error occurs while reading from the
 *                             node type manager.
 */
private void collectNodeTypes(String ntName) throws RepositoryException {
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    String[] resolvedNames = resolveNodeTypeName(ntName);
    // now resolve node type hierarchy
    for (String resolvedName : resolvedNames) {
        try {
            NodeType base = ntMgr.getNodeType(resolvedName);
            if (base.isMixin()) {
                // search for nodes where jcr:mixinTypes is set to this mixin
                addTypeConstraint(new MixinComparision(resolvedName));
            } else {
                // search for nodes where jcr:primaryType is set to this type
                addTypeConstraint(new PrimaryTypeComparision(resolvedName));
            }
            // now search for all node types that are derived from base
            NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
            while (allTypes.hasNext()) {
                NodeType nt = allTypes.nextNodeType();
                NodeType[] superTypes = nt.getSupertypes();
                if (Arrays.asList(superTypes).contains(base)) {
                    if (nt.isMixin()) {
                        addTypeConstraint(new MixinComparision(nt.getName()));
                    } else {
                        addTypeConstraint(new PrimaryTypeComparision(nt.getName()));
                    }
                }
            }
        } catch (NoSuchNodeTypeException e) {
            // add anyway -> will not match anything
            addTypeConstraint(new PrimaryTypeComparision(resolvedName));
        }
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 48 with NodeType

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

the class GQL method resolvePropertyName.

/**
 * Resolves the given property name. If the name has a prefix then the name
 * is returned immediately as is. Otherwise the node type manager is
 * searched for a property definition that defines a named property with
 * a local name that matches the provided <code>name</code>. If such a match
 * is found the name of the property definition is returned.
 *
 * @param name the name of a property (optionally without a prefix).
 * @return the resolved property name.
 * @throws RepositoryException if an error occurs while reading from the
 *                             node type manager.
 */
private String resolvePropertyName(String name) throws RepositoryException {
    if (isPrefixed(name)) {
        return name;
    }
    if (propertyNames == null) {
        propertyNames = new HashMap<String, String>();
        if (session != null) {
            NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
            NodeTypeIterator it = ntMgr.getAllNodeTypes();
            while (it.hasNext()) {
                NodeType nt = it.nextNodeType();
                PropertyDefinition[] defs = nt.getDeclaredPropertyDefinitions();
                for (PropertyDefinition def : defs) {
                    String pn = def.getName();
                    if (!pn.equals("*")) {
                        String localName = pn;
                        int idx = pn.indexOf(':');
                        if (idx != -1) {
                            localName = pn.substring(idx + 1);
                        }
                        propertyNames.put(localName, pn);
                    }
                }
            }
        }
    }
    String pn = propertyNames.get(name);
    if (pn != null) {
        return pn;
    } else {
        return name;
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 49 with NodeType

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

the class AbstractWorkspaceReferenceableTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // we assume referencing is supported by repository
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository supports references
    try {
        NodeType referenceableNt = ntMgr.getNodeType(mixReferenceable);
        if (referenceableNt == null) {
            throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 50 with NodeType

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

the class AbstractWorkspaceVersionableTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // we assume versioning is supported by repository
    NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
    // assert that this repository supports versioning
    try {
        NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
        if (versionableNt == null) {
            throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
        }
    } catch (NoSuchNodeTypeException e) {
        throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeType(javax.jcr.nodetype.NodeType) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

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