directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r590742 - in /directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry: BasicServerAttribute.java DefaultServerEntry.java ObjectClassAttribute.java ServerAttribute.java
Date Wed, 31 Oct 2007 16:48:02 GMT
Author: akarasulu
Date: Wed Oct 31 09:47:58 2007
New Revision: 590742

URL: http://svn.apache.org/viewvc?rev=590742&view=rev
Log:
moved all those sets of objectclasses into a new class: a special ServerAttritbute subtype
called ObjectClassAttribute

Added:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
      - copied, changed from r589966, 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/ObjectClassAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java

Copied: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java
(from r589966, 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/BasicServerAttribute.java?p2=directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/BasicServerAttribute.java&p1=directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java&r1=589966&r2=590742&rev=590742&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/BasicServerAttribute.java
Wed Oct 31 09:47:58 2007
@@ -19,7 +19,6 @@
 package org.apache.directory.server.core.entry;
 
 
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 
 import javax.naming.NamingException;
@@ -33,7 +32,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class ServerAttribute implements EntryAttribute<ServerValue<?>>, Iterable<ServerValue<?>>
+public class BasicServerAttribute implements ServerAttribute
 {
     private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
     private AttributeType attributeType;
@@ -43,14 +42,14 @@
     // an initial value as a string or a byte[]
 
 
-    public ServerAttribute( AttributeType attributeType )
+    public BasicServerAttribute( AttributeType attributeType )
     {
         this.attributeType = attributeType;
         setUpId( null, attributeType );
     }
 
 
-    public ServerAttribute( String upId, AttributeType attributeType )
+    public BasicServerAttribute( String upId, AttributeType attributeType )
     {
         this.attributeType = attributeType;
         setUpId( upId, attributeType );
@@ -68,7 +67,7 @@
      * @param val
      * @throws NamingException
      */
-    public ServerAttribute( AttributeType attributeType, ServerValue<?> val ) throws
NamingException
+    public BasicServerAttribute( AttributeType attributeType, ServerValue<?> val )
throws NamingException
     {
         this( null, attributeType, val );
     }
@@ -86,7 +85,7 @@
      * @param val
      * @throws NamingException
      */
-    public ServerAttribute( String upId, AttributeType attributeType, ServerValue<?>
val ) throws NamingException
+    public BasicServerAttribute( String upId, AttributeType attributeType, ServerValue<?>
val ) throws NamingException
     {
         this.attributeType = attributeType;
         if ( val == null )
@@ -125,13 +124,13 @@
     }
 
 
-    public ServerAttribute( AttributeType attributeType, String val ) throws NamingException
+    public BasicServerAttribute( AttributeType attributeType, String val ) throws NamingException
     {
         this( null, attributeType, val );
     }
 
 
-    public ServerAttribute( String upId, AttributeType attributeType, String val ) throws
NamingException
+    public BasicServerAttribute( String upId, AttributeType attributeType, String val ) throws
NamingException
     {
         this.attributeType = attributeType;
         if ( val == null )
@@ -153,13 +152,13 @@
     }
 
 
-    public ServerAttribute( AttributeType attributeType, byte[] val ) throws NamingException
+    public BasicServerAttribute( AttributeType attributeType, byte[] val ) throws NamingException
     {
         this( null, attributeType, val );
     }
 
 
-    public ServerAttribute( String upId, AttributeType attributeType, byte[] val ) throws
NamingException
+    public BasicServerAttribute( String upId, AttributeType attributeType, byte[] val ) throws
NamingException
     {
         this.attributeType = attributeType;
         if ( val == null )

Modified: 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=590742&r1=590741&r2=590742&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
Wed Oct 31 09:47:58 2007
@@ -25,7 +25,6 @@
 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;
 
@@ -44,15 +43,8 @@
 {
     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 ObjectClassAttribute objectClassAttribute;
     private final transient Registries registries;
     private transient AttributeType objectClassAT;
     private LdapDN dn;
@@ -64,197 +56,74 @@
         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;
+        setObjectClassAttribute( new ObjectClassAttribute( registries ) );
     }
 
 
-    private Set<ObjectClass> addAncestors( ObjectClass descendant, Set<ObjectClass>
ancestors ) throws NamingException
+    private ServerAttribute setObjectClassAttribute( ObjectClassAttribute objectClassAttribute
) 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;
+        this.objectClassAttribute = objectClassAttribute;
+        return serverAttributeMap.put( objectClassAT, objectClassAttribute );
     }
 
 
     public boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException
     {
-        throw new NotImplementedException();
+        return objectClassAttribute.addObjectClass( objectClass, alias );
     }
 
 
     public boolean addObjectClass( ObjectClass objectClass ) throws NamingException
     {
-        if ( allObjectClasses.contains( objectClass ) )
-        {
-            return false;
-        }
-
-        ServerAttribute serverAttribute = serverAttributeMap.get( objectClassAT );
-        String name = objectClass.getName();
-
-        if ( name == null )
-        {
-            name = objectClass.getOid();
-        }
-
-        serverAttribute.add( name );
-        Set<ObjectClass> ancestors = addAncestors( objectClass, new HashSet<ObjectClass>()
);
-        ancestors.add( objectClass );
-        // now create sets of the different kinds of objectClasses
-        for ( ObjectClass oc : ancestors )
-        {
-            switch ( oc.getType().getValue() )
-            {
-                case( ObjectClassTypeEnum.STRUCTURAL_VAL ):
-                    structuralObjectClasses.add( oc );
-                    break;
-                case( ObjectClassTypeEnum.AUXILIARY_VAL ):
-                    auxiliaryObjectClasses.add( oc );
-                    break;
-                case( ObjectClassTypeEnum.ABSTRACT_VAL ):
-                    abstractObjectClasses.add( oc );
-                    break;
-                default:
-                    throw new IllegalStateException( "Unrecognized objectClass type value:
" + oc.getType() );
-            }
-
-            // now go through all objectClassses to collect the must an may list attributes
-            Collections.addAll( mayList, oc.getMayList() );
-            Collections.addAll( mustList, oc.getMustList() );
-        }
-
-        return true;
+        return objectClassAttribute.addObjectClass( objectClass );
     }
 
 
     public boolean hasObjectClass( ObjectClass objectClass )
     {
-        return allObjectClasses.contains( objectClass );
+        return objectClassAttribute.hasObjectClass( objectClass );
     }
 
 
     public Set<ObjectClass> getAbstractObjectClasses()
     {
-        return Collections.unmodifiableSet( abstractObjectClasses );
+        return objectClassAttribute.getAbstractObjectClasses();
     }
 
 
     public ObjectClass getStructuralObjectClass()
     {
-        if ( structuralObjectClasses.isEmpty() )
-        {
-            return null;
-        }
-        return structuralObjectClasses.iterator().next();
+        return objectClassAttribute.getStructuralObjectClass();
     }
 
 
     public Set<ObjectClass> getStructuralObjectClasses()
     {
-        return Collections.unmodifiableSet( structuralObjectClasses );
+        return objectClassAttribute.getStructuralObjectClasses();
     }
 
 
     public Set<ObjectClass> getAuxiliaryObjectClasses()
     {
-        return Collections.unmodifiableSet( auxiliaryObjectClasses );
+        return objectClassAttribute.getAuxiliaryObjectClasses();
     }
 
 
     public Set<ObjectClass> getAllObjectClasses()
     {
-        return Collections.unmodifiableSet( allObjectClasses );
+        return objectClassAttribute.getAllObjectClasses();
     }
 
 
     public Set<AttributeType> getMustList()
     {
-        return Collections.unmodifiableSet( mustList );
+        return objectClassAttribute.getMustList();
     }
 
 
     public Set<AttributeType> getMayList()
     {
-        return Collections.unmodifiableSet( mayList );
+        return objectClassAttribute.getMayList();
     }
 
 
@@ -278,9 +147,19 @@
 
     public ServerAttribute put( ServerAttribute serverAttribute ) throws NamingException
     {
+        if ( serverAttribute.getType().equals( objectClassAT ) && serverAttribute
instanceof ObjectClassAttribute )
+        {
+            return setObjectClassAttribute( ( ObjectClassAttribute ) serverAttribute );
+        }
+
         if ( serverAttribute.getType().equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( serverAttribute );
+            ObjectClassAttribute objectClassAttribute = new ObjectClassAttribute( registries
);
+            for ( ServerValue<?> val : serverAttribute )
+            {
+                objectClassAttribute.add( val );
+            }
+            return setObjectClassAttribute( objectClassAttribute );
         }
 
         return serverAttributeMap.put( serverAttribute.getType(), serverAttribute );
@@ -303,8 +182,9 @@
     {
         if ( serverAttribute.getType().equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( serverAttribute );
+            return setObjectClassAttribute( new ObjectClassAttribute( registries ) );
         }
+
         return serverAttributeMap.remove( serverAttribute.getType() );
     }
 
@@ -319,26 +199,19 @@
         }
         else
         {
-            String name = attributeType.getName();
-            if ( name == null )
-            {
-                name = attributeType.getOid();
-            }
-            return put( name, attributeType, val );
+            return put( null, attributeType, val );
         }
     }
 
 
     public ServerAttribute put( String upId, AttributeType attributeType, ServerValue<?>
val ) throws NamingException
     {
-        ServerAttribute serverAttribute = new ServerAttribute( upId, attributeType, val );
-
         if ( attributeType.equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( serverAttribute );
+            return setObjectClassAttribute( new ObjectClassAttribute( upId, registries, val
) );
         }
 
-        return serverAttributeMap.put( attributeType, serverAttribute );
+        return serverAttributeMap.put( attributeType, new BasicServerAttribute( upId, attributeType,
val ) );
     }
 
 
@@ -346,37 +219,45 @@
     {
         ServerAttribute existing = serverAttributeMap.get( attributeType );
 
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            if ( existing != null )
+            {
+                return setObjectClassAttribute( new ObjectClassAttribute( existing.getUpId(),
registries, val ) );
+            }
+
+            return setObjectClassAttribute( new ObjectClassAttribute( registries, val ) );
+        }
+
         if ( existing != null )
         {
             return put( existing.getUpId(), attributeType, val );
         }
         else
         {
-            String name = attributeType.getName();
-            if ( name == null )
-            {
-                name = attributeType.getOid();
-            }
-            return put( name, attributeType, val );
+            return put( null, attributeType, val );
         }
     }
 
 
     public ServerAttribute put( String upId, AttributeType attributeType, String val ) throws
NamingException
     {
-        ServerAttribute serverAttribute = new ServerAttribute( upId, attributeType, val );
-
         if ( attributeType.equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( serverAttribute );
+            return setObjectClassAttribute( new ObjectClassAttribute( upId, registries, val
) );
         }
 
-        return serverAttributeMap.put( attributeType, serverAttribute );
+        return serverAttributeMap.put( attributeType, new BasicServerAttribute( upId, attributeType,
val ) );
     }
 
 
     public ServerAttribute put( AttributeType attributeType, byte[] val ) throws NamingException
     {
+        if ( attributeType.equals( objectClassAT ) )
+        {
+            throw new UnsupportedOperationException( "Only String values supported for objectClass
attribute" );
+        }
+
         ServerAttribute existing = serverAttributeMap.get( attributeType );
 
         if ( existing != null )
@@ -385,26 +266,19 @@
         }
         else
         {
-            String name = attributeType.getName();
-            if ( name == null )
-            {
-                name = attributeType.getOid();
-            }
-            return put( name, attributeType, val );
+            return put( null, attributeType, val );
         }
     }
 
 
     public ServerAttribute put( String upId, AttributeType attributeType, byte[] val ) throws
NamingException
     {
-        ServerAttribute serverAttribute = new ServerAttribute( upId, attributeType, val );
-
         if ( attributeType.equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( serverAttribute );
+            throw new UnsupportedOperationException( "Only String values supported for objectClass
attribute" );
         }
 
-        return serverAttributeMap.put( attributeType, serverAttribute );
+        return serverAttributeMap.put( attributeType, new BasicServerAttribute( upId, attributeType,
val ) );
     }
 
 
@@ -412,7 +286,7 @@
     {
         if ( attributeType.equals( objectClassAT ) )
         {
-            return setObjectClassAttribute( new ServerAttribute( objectClassAT ) );
+            return setObjectClassAttribute( new ObjectClassAttribute( registries ) );
         }
         else
         {
@@ -427,7 +301,7 @@
 
         try
         {
-            setObjectClassAttribute( new ServerAttribute( objectClassAT ) );
+            setObjectClassAttribute( new ObjectClassAttribute( registries ) );
         }
         catch ( NamingException e )
         {

Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java?rev=590742&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
(added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ObjectClassAttribute.java
Wed Oct 31 09:47:58 2007
@@ -0,0 +1,436 @@
+/*
+ * 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.ldap.constants.SchemaConstants;
+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.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Collections;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassAttribute implements ServerAttribute
+{
+    @SuppressWarnings ( { "UnusedDeclaration" } )
+    private static final Logger LOG = LoggerFactory.getLogger( ObjectClassAttribute.class
);
+
+    private HashSet<ServerValue<?>> values = new HashSet<ServerValue<?>>();
+    @SuppressWarnings ( { "FieldCanBeLocal", "UnusedDeclaration" } )
+    private Registries registries;
+    private AttributeType attributeType;
+    private String upId;
+
+    // Sets dealing with objectClass operations
+    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>();
+
+
+
+    // maybe have some additional convenience constructors which take
+    // an initial value as a string or a byte[]
+
+
+    public ObjectClassAttribute( Registries registries ) throws NamingException
+    {
+        this( null, registries );
+    }
+
+
+    public ObjectClassAttribute( String upId, Registries registries ) throws NamingException
+    {
+        setAttributeTypeAndRegistries( registries );
+        setUpId( upId, attributeType );
+    }
+
+
+    /**
+     * Doc me more!
+     *
+     * If the value does not correspond to the same attributeType, then it's
+     * wrapped value is copied into a new ServerValue which uses the specified
+     * attributeType.
+     */
+    public ObjectClassAttribute( Registries registries, ServerValue<?> val ) throws
NamingException
+    {
+        this( null, registries, val );
+    }
+
+
+    /**
+     * Doc me more!
+     *
+     * If the value does not correspond to the same attributeType, then it's
+     * wrapped value is copied into a new ServerValue which uses the specified
+     * attributeType.
+     */
+    public ObjectClassAttribute( String upId, Registries registries, ServerValue<?>
val ) throws NamingException
+    {
+        setAttributeTypeAndRegistries( registries );
+
+        if ( val == null )
+        {
+            values.add( new ServerStringValue( attributeType ) );
+        }
+        else if ( ! ( val instanceof ServerStringValue ) )
+        {
+            throw new UnsupportedOperationException( "Only String values supported for objectClass
attribute" );
+        }
+        else
+        {
+            values.add( val );
+        }
+
+        setUpId( upId, attributeType );
+    }
+
+
+    public ObjectClassAttribute( Registries registries, String val ) throws NamingException
+    {
+        this( null, registries, val );
+    }
+
+
+    public ObjectClassAttribute( String upId, Registries registries, String val ) throws
NamingException
+    {
+        setAttributeTypeAndRegistries( registries );
+        if ( val == null )
+        {
+            values.add( new ServerStringValue( attributeType ) );
+        }
+        else
+        {
+            values.add( new ServerStringValue( attributeType, val ) );
+        }
+
+        setUpId( upId, attributeType );
+    }
+
+
+    private void setAttributeTypeAndRegistries( Registries registries ) throws NamingException
+    {
+        this.registries = registries;
+        attributeType = registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASS_AT_OID
);
+    }
+
+
+    private void setUpId( String upId, AttributeType attributeType )
+    {
+        if ( upId == null )
+        {
+            String name = attributeType.getName();
+            if ( name == null )
+            {
+                this.upId = attributeType.getOid();
+            }
+            else
+            {
+                this.upId = name;
+            }
+        }
+    }
+
+
+
+    // -----------------------------------------------------------------------
+
+
+    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 boolean addObjectClass( ObjectClass objectClass, String alias ) throws NamingException
+    {
+        if ( allObjectClasses.contains( objectClass ) )
+        {
+            return false;
+        }
+
+        // add the value to the set of values
+        values.add( new ServerStringValue( attributeType, alias) );
+
+        Set<ObjectClass> ancestors = addAncestors( objectClass, new HashSet<ObjectClass>()
);
+        ancestors.add( objectClass );
+        // now create sets of the different kinds of objectClasses
+        for ( ObjectClass oc : ancestors )
+        {
+            switch ( oc.getType().getValue() )
+            {
+                case( ObjectClassTypeEnum.STRUCTURAL_VAL ):
+                    structuralObjectClasses.add( oc );
+                    break;
+                case( ObjectClassTypeEnum.AUXILIARY_VAL ):
+                    auxiliaryObjectClasses.add( oc );
+                    break;
+                case( ObjectClassTypeEnum.ABSTRACT_VAL ):
+                    abstractObjectClasses.add( oc );
+                    break;
+                default:
+                    throw new IllegalStateException( "Unrecognized objectClass type value:
" + oc.getType() );
+            }
+
+            // now go through all objectClassses to collect the must an may list attributes
+            Collections.addAll( mayList, oc.getMayList() );
+            Collections.addAll( mustList, oc.getMustList() );
+        }
+
+        return true;
+    }
+
+
+    public boolean addObjectClass( ObjectClass objectClass ) throws NamingException
+    {
+        String name = objectClass.getName();
+
+        if ( name == null )
+        {
+            name = objectClass.getOid();
+        }
+
+        return addObjectClass( objectClass, name );
+    }
+
+
+    public boolean hasObjectClass( ObjectClass objectClass )
+    {
+        return allObjectClasses.contains( objectClass );
+    }
+
+
+    public Set<ObjectClass> getAbstractObjectClasses()
+    {
+        return Collections.unmodifiableSet( abstractObjectClasses );
+    }
+
+
+    public ObjectClass getStructuralObjectClass()
+    {
+        if ( structuralObjectClasses.isEmpty() )
+        {
+            return null;
+        }
+        return structuralObjectClasses.iterator().next();
+    }
+
+
+    public Set<ObjectClass> getStructuralObjectClasses()
+    {
+        return Collections.unmodifiableSet( structuralObjectClasses );
+    }
+
+
+    public Set<ObjectClass> getAuxiliaryObjectClasses()
+    {
+        return Collections.unmodifiableSet( auxiliaryObjectClasses );
+    }
+
+
+    public Set<ObjectClass> getAllObjectClasses()
+    {
+        return Collections.unmodifiableSet( allObjectClasses );
+    }
+
+
+    public Set<AttributeType> getMustList()
+    {
+        return Collections.unmodifiableSet( mustList );
+    }
+
+
+    public Set<AttributeType> getMayList()
+    {
+        return Collections.unmodifiableSet( mayList );
+    }
+
+
+    /**
+     * Gets the attribute type associated with this ServerAttribute.
+     *
+     * @return the attributeType associated with this entry attribute
+     */
+    public AttributeType getType()
+    {
+        return attributeType;
+    }
+
+
+    /**
+     * Get's the user provided identifier for this entry.  This is the value
+     * that will be used as the identifier for the attribute within the
+     * entry.  If this is a commonName attribute for example and the user
+     * provides "COMMONname" instead when adding the entry then this is
+     * the format the user will have that entry returned by the directory
+     * server.  To do so we store this value as it was given and track it
+     * in the attribute using this property.
+     *
+     * @return the user provided identifier for this attribute
+     */
+    public String getUpId()
+    {
+        return upId;
+    }
+
+
+    /**
+     * Checks to see if this attribute is valid along with the values it contains.
+     *
+     * @return true if the attribute and it's values are valid, false otherwise
+     * @throws NamingException if there is a failure to check syntaxes of values
+     */
+    public boolean isValid() throws NamingException
+    {
+        for ( ServerValue value : values )
+        {
+            if ( ! value.isValid() )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+
+    public boolean add( ServerValue<?> val )
+    {
+        return values.add( val );
+    }
+
+
+    public boolean add( String val )
+    {
+        return values.add( new ServerStringValue( attributeType, val ) );
+    }
+
+
+    public boolean add( byte[] val )
+    {
+        throw new UnsupportedOperationException( "Binary values are not accepted by ObjectClassAttributes"
);
+    }
+
+
+    public void clear()
+    {
+        values.clear();
+    }
+
+
+    public boolean contains( ServerValue<?> val )
+    {
+        return values.contains( val );
+    }
+
+
+    public boolean contains( String val )
+    {
+        ServerStringValue ssv = new ServerStringValue( attributeType, val );
+        return values.contains( ssv );
+    }
+
+
+    public boolean contains( byte[] val )
+    {
+        throw new UnsupportedOperationException( "There are no binary values in an ObjectClass
attribute." );
+    }
+
+
+    public ServerValue<?> get()
+    {
+        if ( values.isEmpty() )
+        {
+            return null;
+        }
+
+        return values.iterator().next();
+    }
+
+
+    public Iterator<? extends ServerValue<?>> getAll()
+    {
+        return iterator();
+    }
+
+
+    public int size()
+    {
+        return values.size();
+    }
+
+
+    public boolean remove( ServerValue<?> val )
+    {
+        return values.remove( val );
+    }
+
+
+    public boolean remove( byte[] val )
+    {
+        throw new UnsupportedOperationException( "There are no binary values in an ObjectClass
attribute." );
+    }
+
+
+    public boolean remove( String val )
+    {
+        ServerStringValue ssv = new ServerStringValue( attributeType, val );
+        return values.remove( ssv );
+    }
+
+
+    public Iterator<ServerValue<?>> iterator()
+    {
+        return values.iterator();
+    }
+}

Added: 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=590742&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
(added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerAttribute.java
Wed Oct 31 09:47:58 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ServerAttribute extends EntryAttribute<ServerValue<?>>, Iterable<ServerValue<?>>
+{
+    AttributeType getType();
+
+
+    String getUpId();
+
+
+    boolean isValid() throws NamingException;
+}



Mime
View raw message