From commits-return-2914-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Thu Oct 05 07:03:02 2006 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 40462 invoked from network); 5 Oct 2006 07:03:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Oct 2006 07:03:02 -0000 Received: (qmail 3737 invoked by uid 500); 5 Oct 2006 07:03:02 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 3708 invoked by uid 500); 5 Oct 2006 07:03:01 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 3699 invoked by uid 99); 5 Oct 2006 07:03:01 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2006 00:03:01 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:63598] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 10/00-20288-61EA4254 for ; Thu, 05 Oct 2006 00:02:55 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C51E41A981A; Thu, 5 Oct 2006 00:02:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453118 - /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Date: Thu, 05 Oct 2006 07:02:19 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061005070219.C51E41A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: angela Date: Thu Oct 5 00:02:19 2006 New Revision: 453118 URL: http://svn.apache.org/viewvc?view=rev&rev=453118 Log: work in progress - simplify mixin-validation - throw exception if mixin to be added is not valid. Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?view=diff&rev=453118&r1=453117&r2=453118 ============================================================================== --- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java (original) +++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Thu Oct 5 00:02:19 2006 @@ -668,9 +668,11 @@ public void addMixin(String mixinName) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException { checkIsWritable(); - QName[] mixinQNames = new QName[] {getQName(mixinName)}; + QName mixinQName = getQName(mixinName); try { - isValidMixin(mixinQNames); + if (!isValidMixin(mixinQName)) { + throw new ConstraintViolationException("Cannot add '" + mixinName + "' mixin type."); + } } catch (NodeTypeConflictException e) { throw new ConstraintViolationException(e.getMessage()); } @@ -678,11 +680,9 @@ // merge existing mixins and new mixins to one Array without modifying // the node state. QName[] currentMixins = getNodeState().getMixinTypeNames(); - QName[] allMixins = new QName[currentMixins.length + mixinQNames.length]; + QName[] allMixins = new QName[currentMixins.length + 1]; System.arraycopy(currentMixins, 0, allMixins, 0, currentMixins.length); - for (int i = 0; i < mixinQNames.length; i++) { - allMixins[currentMixins.length + i] = mixinQNames[i]; - } + allMixins[currentMixins.length] = mixinQName; // perform the operation Operation op = SetMixin.create(getNodeState(), allMixins); session.getSessionItemStateManager().execute(op); @@ -744,8 +744,8 @@ // locks, versioning, acces restriction. session.getValidator().checkIsWritable(getNodeState(), ItemStateValidator.CHECK_ALL); // then make sure the new mixin would not conflict. - return isValidMixin(new QName[] {getQName(mixinName)}); - } catch (RepositoryException e) { + return isValidMixin(getQName(mixinName)); + } catch (NoSuchNodeTypeException e) { log.debug("Cannot add mixin '" + mixinName + "': " + e.getMessage()); return false; } catch (NodeTypeConflictException e) { @@ -1467,7 +1467,7 @@ return qName; } - private boolean isValidMixin(QName[] mixinNames) throws RepositoryException, NodeTypeConflictException { + private boolean isValidMixin(QName mixinName) throws NoSuchNodeTypeException, NodeTypeConflictException { NodeTypeManagerImpl ntMgr = session.getNodeTypeManager(); // get list of existing nodetypes @@ -1476,30 +1476,27 @@ EffectiveNodeType entExisting = session.getValidator().getEffectiveNodeType(existingNts); // first check characteristics of each mixin - for (int i = 0; i < mixinNames.length; i++) { - QName mixinName = mixinNames[i]; - NodeType mixin = ntMgr.getNodeType(mixinName); - if (!mixin.isMixin()) { - log.error(mixin.getName() + ": not a mixin node type"); - return false; - } - NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName); - if (primaryType.isNodeType(mixinName)) { - log.error(mixin.getName() + ": already contained in primary node type"); - return false; - } - // check if adding new mixin conflicts with existing nodetypes - if (entExisting.includesNodeType(mixinName)) { - log.error(mixin.getName() + ": already contained in mixin types"); - return false; - } + NodeType mixin = ntMgr.getNodeType(mixinName); + if (!mixin.isMixin()) { + log.error(mixin.getName() + ": not a mixin node type"); + return false; + } + NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName); + if (primaryType.isNodeType(mixinName)) { + log.error(mixin.getName() + ": already contained in primary node type"); + return false; + } + // check if adding new mixin conflicts with existing nodetypes + if (entExisting.includesNodeType(mixinName)) { + log.error(mixin.getName() + ": already contained in mixin types"); + return false; } // second, build new effective node type for nts including the new mixin // types, detecting eventual incompatibilities - QName[] resultingNts = new QName[existingNts.length + mixinNames.length]; + QName[] resultingNts = new QName[existingNts.length + 1]; System.arraycopy(existingNts, 0, resultingNts, 0, existingNts.length); - System.arraycopy(mixinNames, 0, resultingNts, existingNts.length, mixinNames.length); + resultingNts[existingNts.length] = mixinName; session.getValidator().getEffectiveNodeType(resultingNts); // all validations succeeded: return true