You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2007/10/28 07:51:47 UTC

svn commit: r589282 - in /directory: apacheds/branches/bigbang/core-entry/ apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/

Author: akarasulu
Date: Sat Oct 27 23:51:46 2007
New Revision: 589282

URL: http://svn.apache.org/viewvc?rev=589282&view=rev
Log:
more progress this time on ServerEntry

Added:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
Modified:
    directory/apacheds/branches/bigbang/core-entry/pom.xml
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java

Modified: directory/apacheds/branches/bigbang/core-entry/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/pom.xml?rev=589282&r1=589281&r2=589282&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/pom.xml (original)
+++ directory/apacheds/branches/bigbang/core-entry/pom.xml Sat Oct 27 23:51:46 2007
@@ -31,5 +31,14 @@
   </description>
 
   <packaging>jar</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <version>${pom.version}</version>
+      <artifactId>apacheds-schema-registries</artifactId>
+    </dependency>
+  </dependencies>
+  
 </project>
 

Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java?rev=589282&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java (added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java Sat Oct 27 23:51:46 2007
@@ -0,0 +1,318 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.entry;
+
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.NotImplementedException;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.NamingException;
+import java.util.*;
+
+
+/**
+ * A default implementation of a ServerEntry which should suite most
+ * use cases.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultServerEntry implements ServerEntry
+{
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultServerEntry.class );
+
+    private Set<ObjectClass> allObjectClasses = new HashSet<ObjectClass>();
+    private Set<ObjectClass> abstractObjectClasses = new HashSet<ObjectClass>();
+    private Set<ObjectClass> auxiliaryObjectClasses = new HashSet<ObjectClass>();
+    private Set<ObjectClass> structuralObjectClasses = new HashSet<ObjectClass>();
+
+    private Set<AttributeType> mayList = new HashSet<AttributeType>();
+    private Set<AttributeType> mustList = new HashSet<AttributeType>();
+
+    private Map<AttributeType, ServerAttribute> serverAttributeMap = new HashMap<AttributeType, ServerAttribute>();
+    private final transient Registries registries;
+    private transient AttributeType objectClassAT;
+    private LdapDN dn;
+
+
+    public DefaultServerEntry( LdapDN dn, Registries registries ) throws NamingException
+    {
+        this.dn = dn;
+        this.registries = registries;
+
+        objectClassAT = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT );
+        setObjectClassAttribute( new ServerAttribute( objectClassAT ) );
+    }
+
+
+    private ServerAttribute setObjectClassAttribute( ServerAttribute objectClassAttribute ) throws NamingException
+    {
+        // grab the current value before we clear all sets of schema entities
+        ServerAttribute temp = serverAttributeMap.get( objectClassAT );
+
+        mayList.clear();
+        mustList.clear();
+        allObjectClasses.clear();
+        auxiliaryObjectClasses.clear();
+        structuralObjectClasses.clear();
+        abstractObjectClasses.clear();
+
+        // if the OC has nothing in it then just setup instead of searching below
+        if ( objectClassAttribute.size() == 0 )
+        {
+            serverAttributeMap.put( objectClassAT, objectClassAttribute );
+            return temp;
+        }
+
+        // add all objectclasses as provided by the objectClassAttribute
+        for ( ServerValue value : objectClassAttribute )
+        {
+            ObjectClass objectClass = registries.getObjectClassRegistry().lookup(
+                    ( String ) value.getNormalizedValue() );
+
+            allObjectClasses.add( objectClass );
+        }
+
+        // copy all the existing object classes so we can add ancestors while iterating
+        Set<ObjectClass> copied = new HashSet<ObjectClass>();
+        copied.addAll( allObjectClasses );
+        for ( ObjectClass objectClass : copied )
+        {
+            allObjectClasses.addAll( addAncestors( objectClass, new HashSet<ObjectClass>() ) );
+        }
+
+        // now create sets of the different kinds of objectClasses
+        for ( ObjectClass objectClass : allObjectClasses )
+        {
+            switch ( objectClass.getType().getValue() )
+            {
+                case( ObjectClassTypeEnum.STRUCTURAL_VAL ):
+                    structuralObjectClasses.add( objectClass );
+                    break;
+                case( ObjectClassTypeEnum.AUXILIARY_VAL ):
+                    auxiliaryObjectClasses.add( objectClass );
+                    break;
+                case( ObjectClassTypeEnum.ABSTRACT_VAL ):
+                    abstractObjectClasses.add( objectClass );
+                    break;
+                default:
+                    throw new IllegalStateException( "Unrecognized objectClass type value: " + objectClass.getType() );
+            }
+
+            // now go through all objectClassses to collect the must an may list attributes
+            Collections.addAll( mayList, objectClass.getMayList() );
+            Collections.addAll( mustList, objectClass.getMustList() );
+        }
+
+        serverAttributeMap.put( objectClassAT, objectClassAttribute );
+        return temp;
+    }
+
+
+    private Set<ObjectClass> addAncestors( ObjectClass descendant, Set<ObjectClass> ancestors ) throws NamingException
+    {
+        if ( descendant == null )
+        {
+            return ancestors;
+        }
+
+        ObjectClass[] superClasses = descendant.getSuperClasses();
+        if ( superClasses == null || superClasses.length == 0 )
+        {
+            return ancestors;
+        }
+
+        for ( ObjectClass ancestor : superClasses )
+        {
+            ancestors.add( ancestor );
+            addAncestors( ancestor, ancestors );
+        }
+
+        return ancestors;
+    }
+
+
+    public ObjectClass getStructuralObjectClass()
+    {
+        if ( structuralObjectClasses.isEmpty() )
+        {
+            return null;
+        }
+        return structuralObjectClasses.iterator().next();
+    }
+
+
+    public Set<ObjectClass> getAuxiliaryObjectClasses()
+    {
+        return Collections.unmodifiableSet( auxiliaryObjectClasses );
+    }
+
+
+    public Set<ObjectClass> getObjectClasses()
+    {
+        return Collections.unmodifiableSet( allObjectClasses );
+    }
+
+
+    public Set<AttributeType> getMustList()
+    {
+        return Collections.unmodifiableSet( mustList );
+    }
+
+
+    public Set<AttributeType> getMayList()
+    {
+        return Collections.unmodifiableSet( mayList );
+    }
+
+
+    public boolean isValid()
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public ServerAttribute get( AttributeType attributeType )
+    {
+        return serverAttributeMap.get( attributeType );
+    }
+
+
+    public ServerAttribute put( ServerAttribute serverAttribute ) throws NamingException
+    {
+        if ( serverAttribute.getType().equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( serverAttribute );
+        }
+
+        return serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
+    }
+
+
+    public ServerAttribute remove( ServerAttribute serverAttribute ) throws NamingException
+    {
+        if ( serverAttribute.getType().equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( serverAttribute );
+        }
+        return serverAttributeMap.remove( serverAttribute.getType() );
+    }
+
+
+    public ServerAttribute put( AttributeType attributeType, ServerValue<?> val ) throws NamingException
+    {
+        ServerAttribute serverAttribute = new ServerAttribute( attributeType );
+        serverAttribute.add( val );
+
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( serverAttribute );
+        }
+
+        return serverAttributeMap.put( attributeType, serverAttribute );
+    }
+
+
+    public ServerAttribute put( AttributeType attributeType, String val ) throws NamingException
+    {
+        ServerAttribute serverAttribute = new ServerAttribute( attributeType );
+        serverAttribute.add( val );
+
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( serverAttribute );
+        }
+
+        return serverAttributeMap.put( attributeType, serverAttribute );
+    }
+
+
+    public ServerAttribute put( AttributeType attributeType, byte[] val ) throws NamingException
+    {
+        ServerAttribute serverAttribute = new ServerAttribute( attributeType );
+        serverAttribute.add( val );
+
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( serverAttribute );
+        }
+
+        return serverAttributeMap.put( attributeType, serverAttribute );
+    }
+
+
+    public ServerAttribute remove( OID oid ) throws NamingException
+    {
+        AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( oid.toString() );
+        ServerAttribute serverAttribute = serverAttributeMap.remove( attributeType );
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            return setObjectClassAttribute( new ServerAttribute( objectClassAT) );
+        }
+        return serverAttribute;
+    }
+
+
+    public void clear()
+    {
+        serverAttributeMap.clear();
+
+        try
+        {
+            setObjectClassAttribute( new ServerAttribute( objectClassAT ) );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to properly set the objectClass attribute on clear";
+            LOG.error( msg, e );
+            throw new IllegalStateException( msg, e );
+        }
+    }
+
+
+    public LdapDN getDn()
+    {
+        return dn;
+    }
+
+
+    public void setDn( LdapDN dn )
+    {
+        this.dn = dn;
+    }
+
+
+    public Iterator<ServerAttribute> iterator()
+    {
+        return Collections.unmodifiableMap( serverAttributeMap ).values().iterator();
+    }
+
+
+    public int size()
+    {
+        return serverAttributeMap.size();
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java?rev=589282&r1=589281&r2=589282&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java Sat Oct 27 23:51:46 2007
@@ -20,7 +20,6 @@
 
 
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 
 import javax.naming.NamingException;
@@ -29,17 +28,21 @@
 
 
 /**
- * Document me!
+ * A server side entry attribute aware of schema.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ServerAttribute implements EntryAttribute<ServerValue<?>>
+public class ServerAttribute implements EntryAttribute<ServerValue<?>>, Iterable<ServerValue<?>>
 {
     private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
     private AttributeType attributeType;
 
 
+    // maybe have some additional convenience constructors which take
+    // an initial value as a string or a byte[]
+
+
     public ServerAttribute( AttributeType attributeType )
     {
         this.attributeType = attributeType;
@@ -126,7 +129,7 @@
     }
 
 
-    public Value<?> get()
+    public ServerValue<?> get()
     {
         if ( values.isEmpty() )
         {
@@ -139,7 +142,7 @@
 
     public Iterator<? extends ServerValue<?>> getAll()
     {
-        return values.iterator();
+        return iterator();
     }
 
 
@@ -166,5 +169,11 @@
     {
         ServerStringValue ssv = new ServerStringValue( attributeType, val );
         return values.remove( ssv );
+    }
+
+
+    public Iterator<ServerValue<?>> iterator()
+    {
+        return values.iterator();
     }
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java?rev=589282&r1=589281&r2=589282&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java Sat Oct 27 23:51:46 2007
@@ -21,20 +21,20 @@
 
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 
+import javax.naming.NamingException;
 import java.util.Set;
 
 
 /**
- * Document me!
+ * A server side entry which is schema aware.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface ServerEntry extends Entry
+public interface ServerEntry extends Entry<ServerAttribute>, Iterable<ServerAttribute>
 {
     // -----------------------------------------------------------------------
     // Schema Related Methods
@@ -79,7 +79,7 @@
      *
      * @return the combinded set of all required attributes
      */
-    Set<ServerAttribute> getMustList();
+    Set<AttributeType> getMustList();
 
 
     /**
@@ -88,7 +88,7 @@
      *
      * @return the combined set of all optional attributes
      */
-    Set<ServerAttribute> getMayList();
+    Set<AttributeType> getMayList();
 
 
     /**
@@ -126,7 +126,7 @@
      * @return the old attribute with the same OID, if exists; otherwise
      *         <code>null</code>
      */
-    ServerAttribute put( ServerAttribute attribute );
+    ServerAttribute put( ServerAttribute attribute ) throws NamingException;
 
 
     /**
@@ -144,8 +144,9 @@
      * @param val the value of the new attribute to be put
      * @return the old attribute with the same OID, if exists; otherwise
      *         <code>null</code>
+     * @throws NamingException if there are failures
      */
-    ServerAttribute put( AttributeType attributeType, Value<?> val );
+    ServerAttribute put( AttributeType attributeType, ServerValue<?> val ) throws NamingException;
 
 
     /**
@@ -163,8 +164,9 @@
      * @param val the value of the new attribute to be put
      * @return the old attribute with the same identifier, if exists; otherwise
      *         <code>null</code>
+     * @throws NamingException if there are failures
      */
-    ServerAttribute put( AttributeType attributeType, String val );
+    ServerAttribute put( AttributeType attributeType, String val ) throws NamingException;
 
 
     /**
@@ -182,8 +184,9 @@
      * @param val the value of the new attribute to be put
      * @return the old attribute with the same identifier, if exists; otherwise
      *         <code>null</code>
+     * @throws NamingException if there are failures
      */
-    ServerAttribute put( AttributeType attributeType, byte[] val );
+    ServerAttribute put( AttributeType attributeType, byte[] val ) throws NamingException;
 
 
     /**
@@ -193,6 +196,7 @@
      *
      * @param oid the numeric object identifier of the attribute to be removed
      * @return the removed attribute, if exists; otherwise <code>null</code>
+     * @throws NamingException if there are failures
      */
-    ServerAttribute remove( OID oid );
+    ServerAttribute remove( OID oid ) throws NamingException;
 }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java?rev=589282&r1=589281&r2=589282&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/entry/Entry.java Sat Oct 27 23:51:46 2007
@@ -21,6 +21,7 @@
 
 import org.apache.directory.shared.ldap.name.LdapDN;
 
+import javax.naming.NamingException;
 import java.util.Iterator;
 
 
@@ -30,7 +31,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public interface Entry
+public interface Entry<T extends EntryAttribute<?>>
 {
     /**
      * Removes all the attributes.
@@ -61,7 +62,7 @@
      *
      * @return an enumeration of all contained attributes
      */
-    Iterator<? extends EntryAttribute> getAll();
+    Iterator<T> iterator();
 
 
     /**
@@ -74,7 +75,7 @@
      * @return the old attribute with the same OID, if exists; otherwise
      *         <code>null</code>
      */
-    EntryAttribute put( EntryAttribute attribute );
+    T put( T attribute ) throws NamingException;
 
 
     /**
@@ -85,7 +86,7 @@
       * @param attribute the attribute to be removed
       * @return the removed attribute, if exists; otherwise <code>null</code>
       */
-    EntryAttribute remove( EntryAttribute attribute );
+    T remove( T attribute ) throws NamingException;
 
 
     /**