jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r961771 - /jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Date Thu, 08 Jul 2010 13:57:31 GMT
Author: stefan
Date: Thu Jul  8 13:57:30 2010
New Revision: 961771

URL: http://svn.apache.org/viewvc?rev=961771&view=rev
Log:
JCR-2659: Fails to remove a previously assigned mixin

Modified:
    jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java

Modified: jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=961771&r1=961770&r2=961771&view=diff
==============================================================================
--- jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/branches/1.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Thu Jul  8 13:57:30 2010
@@ -1336,200 +1336,6 @@ public class NodeImpl extends ItemImpl i
     }
 
     /**
-     * Same as {@link Node#removeMixin(String)} except that it takes a
-     * <code>Name</code> instead of a <code>String</code>.
-     *
-     * @see Node#removeMixin(String)
-     */
-    public void removeMixinOld(Name mixinName)
-            throws NoSuchNodeTypeException, VersionException,
-            ConstraintViolationException, LockException, RepositoryException {
-        // check state of this instance
-        sanityCheck();
-
-        int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_VERSIONING |
-                ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD;
-        int permissions = Permission.NODE_TYPE_MNGMT;
-        session.getValidator().checkModify(this, options, permissions);
-
-        // check if mixin is assigned
-        final NodeState state = data.getNodeState();
-        if (!state.getMixinTypeNames().contains(mixinName)) {
-            throw new NoSuchNodeTypeException();
-        }
-
-        NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
-        NodeTypeRegistry ntReg = ntMgr.getNodeTypeRegistry();
-
-        // build effective node type of remaining mixin's & primary type
-        Set remainingMixins = new HashSet(state.getMixinTypeNames());
-        // remove name of target mixin
-        remainingMixins.remove(mixinName);
-        EffectiveNodeType entResulting;
-        try {
-            // build effective node type representing primary type including remaining mixin's
-            entResulting = ntReg.getEffectiveNodeType(
-                    state.getNodeTypeName(), remainingMixins);
-        } catch (NodeTypeConflictException e) {
-            throw new ConstraintViolationException(e.getMessage(), e);
-        }
-
-        /**
-         * 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 ((NameConstants.MIX_REFERENCEABLE.equals(mixinName)
-                || mixin.isDerivedFrom(NameConstants.MIX_REFERENCEABLE))
-                && !entResulting.includesNodeType(NameConstants.MIX_REFERENCEABLE))
{
-            // removing this mixin would effectively remove mix:referenceable:
-            // make sure no references exist
-            PropertyIterator iter = getReferences();
-            if (iter.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)
-                && isLocked()) {
-            throw new ConstraintViolationException(mixinName + " can not be removed: the
node is locked.");
-        }
-
-
-        // modify the state of this node
-        NodeState thisState = (NodeState) getOrCreateTransientItemState();
-        thisState.setMixinTypeNames(remainingMixins);
-
-        // set jcr:mixinTypes property
-        setMixinTypesProperty(remainingMixins);
-
-        // shortcut
-        if (mixin.getChildNodeDefinitions().length == 0
-                && mixin.getPropertyDefinitions().length == 0) {
-            // the node type has neither property nor child node definitions,
-            // i.e. we're done
-            return;
-        }
-
-        // walk through properties and child nodes and remove those that aren't
-        // accommodated by the resulting new effective node type (see JCR-2130)
-        boolean success = false;
-        try {
-            // use temp set to avoid ConcurrentModificationException
-            HashSet set = new HashSet(thisState.getPropertyNames());
-            for (Iterator iter = set.iterator(); iter.hasNext();) {
-                Name propName = (Name) iter.next();
-                PropertyState propState = (PropertyState) stateMgr.getItemState(new PropertyId(thisState.getNodeId(),
propName));
-                // check if property has been defined by mixin type (or one of its supertypes)
-                PropertyDefinition def = itemMgr.getDefinition(propState);
-                NodeTypeImpl declaringNT = (NodeTypeImpl) def.getDeclaringNodeType();
-                if (!entResulting.includesNodeType(declaringNT.getQName())) {
-                    // the resulting effective node type doesn't include the
-                    // node type that declared this property
-
-                    // try to find new applicable definition first and
-                    // redefine property if possible (JCR-2130)
-                    try {
-                        PropertyImpl prop = (PropertyImpl) itemMgr.getItem(propState.getId());
-                        if (prop.getDefinition().isProtected()) {
-                            // remove 'orphaned' protected properties immediately
-                            removeChildProperty(propName);
-                            continue;
-                        }
-                        PropertyDefinitionImpl pdi = getApplicablePropertyDefinition(
-                                propName, propState.getType(),
-                                propState.isMultiValued(), false);
-                        if (pdi.getRequiredType() != PropertyType.UNDEFINED
-                                && pdi.getRequiredType() != propState.getType())
{
-                            // value conversion required
-                            if (propState.isMultiValued()) {
-                                // convert value
-                                Value[] values =
-                                        ValueHelper.convert(
-                                                prop.getValues(),
-                                                pdi.getRequiredType(),
-                                                session.getValueFactory());
-                                // redefine property
-                                prop.onRedefine(pdi.unwrap());
-                                // set converted values
-                                prop.setValue(values);
-                            } else {
-                                // convert value
-                                Value value =
-                                        ValueHelper.convert(
-                                                prop.getValue(),
-                                                pdi.getRequiredType(),
-                                                session.getValueFactory());
-                                // redefine property
-                                prop.onRedefine(pdi.unwrap());
-                                // set converted values
-                                prop.setValue(value);
-                            }
-                        } else {
-                            // redefine property
-                            prop.onRedefine(pdi.unwrap());
-                        }
-                    } catch (ValueFormatException vfe) {
-                        // value conversion failed, remove it
-                        removeChildProperty(propName);
-                    } catch (ConstraintViolationException cve) {
-                        // no suitable definition found for this property,
-                        // remove it
-                        removeChildProperty(propName);
-                    }
-                }
-            }
-            // use temp array to avoid ConcurrentModificationException
-            ArrayList list = new ArrayList(thisState.getChildNodeEntries());
-            // start from tail to avoid problems with same-name siblings
-            for (int i = list.size() - 1; i >= 0; i--) {
-                ChildNodeEntry entry = (ChildNodeEntry) list.get(i);
-                NodeState nodeState = (NodeState) stateMgr.getItemState(entry.getId());
-                NodeDefinition def = itemMgr.getDefinition(nodeState);
-                // check if node has been defined by mixin type (or one of its supertypes)
-                NodeTypeImpl declaringNT = (NodeTypeImpl) def.getDeclaringNodeType();
-                if (!entResulting.includesNodeType(declaringNT.getQName())) {
-                    // the resulting effective node type doesn't include the
-                    // node type that declared this child node
-
-                    try {
-                        NodeImpl node = (NodeImpl) itemMgr.getItem(nodeState.getId());
-                        if (node.getDefinition().isProtected()) {
-                            // remove 'orphaned' protected child node immediately
-                            removeChildNode(entry.getName(), entry.getIndex());
-                            continue;
-                        }
-                        NodeDefinitionImpl ndi = getApplicableChildNodeDefinition(
-                                entry.getName(),
-                                nodeState.getNodeTypeName());
-                        // redefine node
-                        node.onRedefine(ndi.unwrap());
-                    } catch (ConstraintViolationException cve) {
-                        // no suitable definition found for this child node,
-                        // remove it
-                        removeChildNode(entry.getName(), entry.getIndex());
-                    }
-                }
-            }
-            success = true;
-        } catch (ItemStateException e) {
-            throw new RepositoryException("Failed to clean up child items defined by removed
mixin " + session.getJCRName(mixinName));
-        } finally {
-            if (!success) {
-                // TODO JCR-1914: revert changes made to jcr:mixinTypes
-            }
-        }
-    }
-
-    /**
      * Same as {@link Node#isNodeType(String)} except that it takes a
      * <code>Name</code> instead of a <code>String</code>.
      *



Mime
View raw message