Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7ABEE7884 for ; Wed, 21 Dec 2011 16:58:08 +0000 (UTC) Received: (qmail 71714 invoked by uid 500); 21 Dec 2011 16:58:08 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 71676 invoked by uid 500); 21 Dec 2011 16:58:08 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 71669 invoked by uid 99); 21 Dec 2011 16:58:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2011 16:58:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2011 16:58:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6A863238897D for ; Wed, 21 Dec 2011 16:57:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1221802 - in /directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry: DefaultEntry.java Entry.java ImmutableEntry.java Date: Wed, 21 Dec 2011 16:57:46 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111221165746.6A863238897D@eris.apache.org> Author: elecharny Date: Wed Dec 21 16:57:45 2011 New Revision: 1221802 URL: http://svn.apache.org/viewvc?rev=1221802&view=rev Log: Added the apply( SchemaManager ) to the Entry interface, and impelmented the method in the inherited classes Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1221802&r1=1221801&r2=1221802&view=diff ============================================================================== --- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java (original) +++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java Wed Dec 21 16:57:45 2011 @@ -37,7 +37,9 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.model.ldif.LdapLdifException; import org.apache.directory.shared.ldap.model.ldif.LdifAttributesReader; import org.apache.directory.shared.ldap.model.message.ResultCodeEnum; +import org.apache.directory.shared.ldap.model.name.Ava; import org.apache.directory.shared.ldap.model.name.Dn; +import org.apache.directory.shared.ldap.model.name.Rdn; import org.apache.directory.shared.ldap.model.schema.AttributeType; import org.apache.directory.shared.ldap.model.schema.SchemaManager; import org.apache.directory.shared.util.Base64; @@ -586,6 +588,65 @@ public final class DefaultEntry implemen return schemaManager.lookupAttributeTypeRegistry( upId ); } + + + /** + * Adds missing Rdn's attributes and values to the entry. + * + * @param dn the Dn + * @param entry the entry + */ + private void addRdnAttributesToEntry( SchemaManager schemaManager ) throws LdapException + { + if ( Dn.isNullOrEmpty( dn ) ) + { + return; + } + + Rdn rdn = dn.getRdn(); + + // Loop on all the AVAs + for ( Ava ava : rdn ) + { + Value value = ava.getNormValue(); + Value upValue = ava.getUpValue(); + String upId = ava.getUpType(); + + // Check that the entry contains this Ava + if ( !contains( upId, value ) ) + { + String message = "The Rdn '" + upId + "=" + upValue + "' is not present in the entry"; + LOG.warn( message ); + + // We don't have this attribute : add it. + // Two cases : + // 1) The attribute does not exist + if ( !containsAttribute( upId ) ) + { + AttributeType attributeType = schemaManager.getAttributeType( upId ); + + add( upId, attributeType, value ); + } + // 2) The attribute exists + else + { + AttributeType at = schemaManager.lookupAttributeTypeRegistry( upId ); + + // 2.1 if the attribute is single valued, replace the value + if ( at.isSingleValued() ) + { + removeAttributes( upId ); + add( upId, value ); + } + // 2.2 the attribute is multi-valued : add the missing value + else + { + add( upId, value ); + } + } + } + } + } //------------------------------------------------------------------------- @@ -975,6 +1036,30 @@ public final class DefaultEntry implemen /** + * {@inheritDoc} + */ + public void apply( SchemaManager schemaManager ) throws LdapException + { + if ( dn.getSchemaManager() == null ) + { + dn.apply( schemaManager ); + } + + for ( Attribute attribute : attributes.values() ) + { + if ( attribute.getAttributeType() == null ) + { + AttributeType attributeType = schemaManager.getAttributeType( attribute.getId() ); + attribute.apply( attributeType ); + } + } + + addRdnAttributesToEntry( schemaManager ); + this.schemaManager = schemaManager; + } + + + /** * Clone an entry. All the element are duplicated, so a modification on * the original object won't affect the cloned object, as a modification * on the cloned object has no impact on the original object Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java?rev=1221802&r1=1221801&r2=1221802&view=diff ============================================================================== --- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java (original) +++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Entry.java Wed Dec 21 16:57:45 2011 @@ -29,6 +29,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.shared.ldap.model.name.Dn; import org.apache.directory.shared.ldap.model.schema.AttributeType; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; /** @@ -48,6 +49,13 @@ import org.apache.directory.shared.ldap. public interface Entry extends Cloneable, Iterable, Externalizable { /** + * Apply the SchemaManager to this entry + * @param schemaManager The SchemaManager + * @throws LdapException if there is some problem in the DN or in the Attributes + */ + void apply( SchemaManager schemaManager ) throws LdapException; + + /** * Remove all the attributes for this entry. The Dn is not reset */ void clear(); Modified: directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java?rev=1221802&r1=1221801&r2=1221802&view=diff ============================================================================== --- directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java (original) +++ directory/shared/branches/shared-txns/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ImmutableEntry.java Wed Dec 21 16:57:45 2011 @@ -31,6 +31,7 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.shared.ldap.model.name.Dn; import org.apache.directory.shared.ldap.model.schema.AttributeType; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; import org.apache.directory.shared.util.exception.NotImplementedException; @@ -168,6 +169,16 @@ public class ImmutableEntry implements E /** + * {@inheritDoc} + */ + public void apply( SchemaManager schemaManager ) + { + new Exception().printStackTrace(); + throw new NotImplementedException( "Cannot apply the schemaManager : the entry " + entry.getDn() + " is immutable." ); + } + + + /** * Clone an entry. All the element are duplicated, so a modification on * the original object won't affect the cloned object, as a modification * on the cloned object has no impact on the original object