Package org.apache.jackrabbit.core.nodetype

Examples of org.apache.jackrabbit.core.nodetype.NodeTypeImpl


        }

        // mix:referenceable needs special handling because it has
        // special semantics:
        // it can only be removed if there no more references to this node
        NodeTypeImpl mixin = ntMgr.getNodeType(mixinName);
        if (isReferenceable(mixin)
                && !entResulting.includesNodeType(MIX_REFERENCEABLE)) {
            if (node.getReferences().hasNext()) {
                throw new ConstraintViolationException(
                        mixinName + " can not be removed:"
                        + " the node is being referenced through at least"
                        + " one property of type REFERENCE");
            }
        }

        // mix:lockable: the mixin cannot be removed if the node is
        // currently locked even if the editing session is the lock holder.
        if ((NameConstants.MIX_LOCKABLE.equals(mixinName)
                || mixin.isDerivedFrom(NameConstants.MIX_LOCKABLE))
                && !entResulting.includesNodeType(NameConstants.MIX_LOCKABLE)
                && node.isLocked()) {
            throw new ConstraintViolationException(
                    mixinName + " can not be removed: the node is locked.");
        }

        NodeState thisState = (NodeState) node.getOrCreateTransientItemState();

        // collect information about properties and nodes which require further
        // action as a result of the mixin removal; we need to do this *before*
        // actually changing the assigned mixin types, otherwise we wouldn't
        // be able to retrieve the current definition of an item.
        Map<PropertyId, PropertyDefinition> affectedProps =
            new HashMap<PropertyId, PropertyDefinition>();
        Map<ChildNodeEntry, NodeDefinition> affectedNodes =
            new HashMap<ChildNodeEntry, NodeDefinition>();
        try {
            Set<Name> names = thisState.getPropertyNames();
            for (Name propName : names) {
                PropertyId propId =
                    new PropertyId(thisState.getNodeId(), propName);
                PropertyState propState =
                    (PropertyState) stateMgr.getItemState(propId);
                PropertyDefinition oldDef = itemMgr.getDefinition(propState);
                // check if property has been defined by mixin type
                // (or one of its supertypes)
                NodeTypeImpl declaringNT =
                    (NodeTypeImpl) oldDef.getDeclaringNodeType();
                if (!entResulting.includesNodeType(declaringNT.getQName())) {
                    // the resulting effective node type doesn't include the
                    // node type that declared this property
                    affectedProps.put(propId, oldDef);
                }
            }

            List<ChildNodeEntry> entries = thisState.getChildNodeEntries();
            for (ChildNodeEntry entry : entries) {
                NodeState nodeState =
                    (NodeState) stateMgr.getItemState(entry.getId());
                NodeDefinition oldDef = itemMgr.getDefinition(nodeState);
                // check if node has been defined by mixin type
                // (or one of its supertypes)
                NodeTypeImpl declaringNT =
                    (NodeTypeImpl) oldDef.getDeclaringNodeType();
                if (!entResulting.includesNodeType(declaringNT.getQName())) {
                    // the resulting effective node type doesn't include the
                    // node type that declared this child node
                    affectedNodes.put(entry, oldDef);
                }
            }
View Full Code Here


        if (nodeTypes != null) {
            Set<NodeType> eventTypes = eventState.getNodeTypes(session.getNodeTypeManager());
            boolean match = false;
            for (int i = 0; i < nodeTypes.length && !match; i++) {
                for (Iterator<NodeType> iter = eventTypes.iterator(); iter.hasNext();) {
                    NodeTypeImpl nodeType = (NodeTypeImpl) iter.next();
                    match |= nodeType.getQName().equals(nodeTypes[i].getQName())
                            || nodeType.isDerivedFrom(nodeTypes[i].getQName());
                }
            }
            if (!match) {
                return true;
            }
View Full Code Here

                }
            }, null);
            if (ntName[0] == null) {
                ntName[0] = NameConstants.NT_BASE;
            }
            NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
            PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
            for (PropertyDefinition pd : propDefs) {
                QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
                if (!propDef.definesResidual() && !propDef.isMultiple()) {
                    columns.put(propDef.getName(), columnForName(propDef.getName()));
                }
View Full Code Here

        context.getItemValidator().checkRemove(srcParentNode, options, Permission.NONE);
        context.getItemValidator().checkModify(destParentNode, options, Permission.NONE);

        // check constraints
        // get applicable definition of target node at new location
        NodeTypeImpl nt = (NodeTypeImpl) targetNode.getPrimaryNodeType();
        org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl newTargetDef;
        try {
            newTargetDef = destParentNode.getApplicableChildNodeDefinition(destPath.getName(), nt.getQName());
        } catch (RepositoryException re) {
            String msg = destAbsPath + ": no definition found in parent node's node type for new node";
            log.debug(msg);
            throw new ConstraintViolationException(msg, re);
        }
View Full Code Here

        PropertyDefinition def = prop.getDefinition();
        if (def.isProtected()) {
            return false;
        } else if (node.isSame(prop.getParent())) {
            NodeTypeImpl declaringNt = (NodeTypeImpl) prop.getDefinition().getDeclaringNodeType();
            return declaringNt.isNodeType(UserConstants.NT_REP_AUTHORIZABLE);
        } else {
            // another non-protected property somewhere in the subtree of this
            // authorizable node -> is a property that can be set using #setProperty.
            return true;
        }
View Full Code Here

        if (nodeTypes != null) {
            Set<NodeType> eventTypes = eventState.getNodeTypes(session.getNodeTypeManager());
            boolean match = false;
            for (int i = 0; i < nodeTypes.length && !match; i++) {
                for (NodeType eventType : eventTypes) {
                    NodeTypeImpl nodeType = (NodeTypeImpl) eventType;
                    match |= nodeType.getQName().equals(nodeTypes[i].getQName())
                            || nodeType.isDerivedFrom(nodeTypes[i].getQName());
                }
            }
            if (!match) {
                return true;
            }
View Full Code Here

        Path nodePath = PathFactoryImpl.getInstance().create(
                getPrimaryPath(), nodeName, true);

        // Check the explicitly specified node type (if any)
        NodeTypeImpl nt = null;
        if (nodeTypeName != null) {
            nt = sessionContext.getNodeTypeManager().getNodeType(nodeTypeName);
            if (nt.isMixin()) {
                throw new ConstraintViolationException(
                        "Unable to add a node with a mixin node type: "
                        + sessionContext.getJCRName(nodeTypeName));
            } else if (nt.isAbstract()) {
                throw new ConstraintViolationException(
                        "Unable to add a node with an abstract node type: "
                        + sessionContext.getJCRName(nodeTypeName));
            } else {
                // adding a node with explicit specifying the node type name
View Full Code Here

        // check state of this instance
        sanityCheck();

        Name ntName = sessionContext.getQName(mixinName);
        NodeTypeManagerImpl ntMgr = sessionContext.getNodeTypeManager();
        NodeTypeImpl mixin = ntMgr.getNodeType(ntName);
        if (!mixin.isMixin()) {
            return false;
        }

        int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT
                | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD;
        int permissions = Permission.NODE_TYPE_MNGMT;
        // special handling of mix:(simple)versionable. since adding the mixin alters
        // the version storage jcr:versionManagement privilege is required
        // in addition.
        if (NameConstants.MIX_VERSIONABLE.equals(ntName)
                || NameConstants.MIX_SIMPLE_VERSIONABLE.equals(ntName)) {
            permissions |= Permission.VERSION_MNGMT;
        }
        if (!sessionContext.getItemValidator().canModify(this, options, permissions)) {
            return false;
        }

        final Name primaryTypeName = data.getNodeState().getNodeTypeName();

        NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName);
        if (primaryType.isDerivedFrom(ntName)) {
            // mixin already inherited -> addMixin is allowed but has no effect.
            return true;
        }

        // build effective node type of mixins & primary type
View Full Code Here

        sessionContext.getItemValidator().checkRemove(parent, options, Permission.NONE);
        sessionContext.getItemValidator().checkModify(parent, options, Permission.NONE);

        // check constraints
        // get applicable definition of renamed target node
        NodeTypeImpl nt = (NodeTypeImpl) getPrimaryNodeType();
        org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl newTargetDef;
        try {
            newTargetDef = parent.getApplicableChildNodeDefinition(qName, nt.getQName());
        } catch (RepositoryException re) {
            String msg = safeGetJCRPath() + ": no definition found in parent node's node type for renamed node";
            log.debug(msg);
            throw new ConstraintViolationException(msg, re);
        }
        // if there's already a node with that name also check same-name sibling
        // setting of new node; just checking same-name sibling setting on
        // existing node is not sufficient since same-name sibling nodes don't
        // necessarily have identical definitions
        if (existing != null && !newTargetDef.allowsSameNameSiblings()) {
            throw new ItemExistsException(
                    "Same name siblings not allowed: " + existing);
        }

        // check permissions:
        // 1. on the parent node the session must have permission to manipulate the child-entries
        AccessManager acMgr = sessionContext.getAccessManager();
        if (!acMgr.isGranted(parent.getPrimaryPath(), qName, Permission.MODIFY_CHILD_NODE_COLLECTION)) {
            String msg = "Not allowed to rename node " + safeGetJCRPath() + " to " + newName;
            log.debug(msg);
            throw new AccessDeniedException(msg);
        }
        // 2. in case of nt-changes the session must have permission to change
        //    the primary node type on this node itself.
        if (!nt.getName().equals(newTargetDef.getName()) && !(acMgr.isGranted(getPrimaryPath(), Permission.NODE_TYPE_MNGMT))) {
            String msg = "Not allowed to rename node " + safeGetJCRPath() + " to " + newName;
            log.debug(msg);
            throw new AccessDeniedException(msg);
        }
View Full Code Here

                // the transient item is a node
                NodeState nodeState = (NodeState) itemState;
                ItemId id = nodeState.getNodeId();
                NodeDefinition nodeDef = (NodeDefinition) def;
                // primary type
                NodeTypeImpl pnt = ntMgr.getNodeType(nodeState.getNodeTypeName());
                // effective node type (primary type incl. mixins)
                EffectiveNodeType ent = getEffectiveNodeType(
                        context.getRepositoryContext().getNodeTypeRegistry(),
                        nodeState);
                /**
                 * if the transient node was added (i.e. if it is 'new') or if
                 * its primary type has changed, check its node type against the
                 * required node type in its definition
                 */
                boolean primaryTypeChanged =
                        nodeState.getStatus() == ItemState.STATUS_NEW;
                if (!primaryTypeChanged) {
                    NodeState overlaid =
                            (NodeState) nodeState.getOverlayedState();
                    if (overlaid != null) {
                        Name newName = nodeState.getNodeTypeName();
                        Name oldName = overlaid.getNodeTypeName();
                        primaryTypeChanged = !newName.equals(oldName);
                    }
                }
                if (primaryTypeChanged) {
                    for (NodeType ntReq : nodeDef.getRequiredPrimaryTypes()) {
                        Name ntName = ((NodeTypeImpl) ntReq).getQName();
                        if (!(pnt.getQName().equals(ntName)
                                || pnt.isDerivedFrom(ntName))) {
                            /**
                             * the transient node's primary node type does not
                             * satisfy the 'required primary types' constraint
                             */
                            String msg = itemMgr.safeGetJCRPath(id)
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.nodetype.NodeTypeImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.