directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r604962 - in /directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry: DefaultServerAttribute.java DefaultServerEntry.java ServerEntry.java ServerEntryUtils.java
Date Mon, 17 Dec 2007 18:40:38 GMT
Author: elecharny
Date: Mon Dec 17 10:40:37 2007
New Revision: 604962

URL: http://svn.apache.org/viewvc?rev=604962&view=rev
Log:
Added a serverUtils class to handle conversions between Attributes instances
Added some more methods into the ServerEntry classes

Added:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
Modified:
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerEntry.java
    directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntry.java

Modified: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java?rev=604962&r1=604961&r2=604962&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
(original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/DefaultServerAttribute.java
Mon Dec 17 10:40:37 2007
@@ -27,6 +27,8 @@
 import org.slf4j.LoggerFactory;
 
 import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.InvalidAttributeValueException;
 
 import java.util.Iterator;
@@ -619,5 +621,20 @@
     public Iterator<ServerValue<?>> iterator()
     {
         return values.iterator();
+    }
+    
+    
+    public Attribute toAttribute()
+    {
+        BasicAttribute attribute = new BasicAttribute( upId, false );
+
+        for ( Iterator<ServerValue<?>> iter=iterator(); iter.hasNext();)
+        {
+            ServerValue<?> value = iter.next();
+            
+            attribute.add( value.get() );
+        }
+        
+        return attribute;
     }
 }

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=604962&r1=604961&r2=604962&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
Mon Dec 17 10:40:37 2007
@@ -37,6 +37,10 @@
 import org.slf4j.LoggerFactory;
 
 import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
 
 
 /**
@@ -94,6 +98,12 @@
     }
 
 
+    public void addObjectClass( ObjectClassAttribute objectClassAttribute ) throws NamingException
+    {
+        this.objectClassAttribute = objectClassAttribute;
+    }
+
+
     public boolean hasObjectClass( ObjectClass objectClass )
     {
         return objectClassAttribute.hasObjectClass( objectClass );
@@ -411,5 +421,16 @@
     public int size()
     {
         return serverAttributeMap.size();
+    }
+    
+    
+    /**
+     * Gest all the attributes type (ObjectClasses, May and Must)
+     *
+     * @return The combined set of all the attributes, including ObjectClass.
+     */
+    public Set<AttributeType> getAttributeTypes()
+    {
+        return serverAttributeMap.keySet();
     }
 }

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=604962&r1=604961&r2=604962&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
Mon Dec 17 10:40:37 2007
@@ -148,6 +148,14 @@
      */
     Set<AttributeType> getMayList();
 
+    
+    /**
+     * Gets all the attributes type (ObjectClasses, May and Must)
+     *
+     * @return The combined set of all the attributes, including ObjectClass.
+     */
+    Set<AttributeType> getAttributeTypes();
+    
 
     /**
      * Fail fast check performed to determine entry consistency according to schema

Added: directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=604962&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
(added)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
Mon Dec 17 10:40:37 2007
@@ -0,0 +1,98 @@
+/*
+ * 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 java.util.Iterator;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+/**
+ * A helper class used to manipulate Entries, Attributes and Values.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerEntryUtils
+{
+    /**
+     * Convert a ServerEntry into a AttributesImpl. The DN is lost
+     * during this conversion, as the Attributes object does not store
+     * this element.
+     *
+     * @return An instance of a AttributesImpl() object
+     */
+    public static Attributes toAttributesImpl( ServerEntry<?> entry )
+    {
+        Attributes attributes = new AttributesImpl();
+
+        for ( AttributeType attributeType:entry.getAttributeTypes() )
+        {
+            Attribute attribute = new AttributeImpl( attributeType.getName() );
+            
+            ServerAttribute<?> attr = entry.get( attributeType );
+            
+            for ( Iterator<ServerValue<?>> iter = attr.iterator(); iter.hasNext();)
+            {
+                ServerValue<?> value = iter.next();
+                attribute.add( value );
+            }
+            
+            attributes.put( attribute );
+        }
+        
+        return attributes;
+    }
+
+
+    /**
+     * Convert a ServerEntry into a BasicAttributes. The DN is lost
+     * during this conversion, as the Attributes object does not store
+     * this element.
+     *
+     * @return An instance of a BasicAttributes() object
+     */
+    public static Attributes toBasicAttributes( ServerEntry<?> entry )
+    {
+        Attributes attributes = new BasicAttributes( true );
+
+        for ( AttributeType attributeType:entry.getAttributeTypes() )
+        {
+            Attribute attribute = new BasicAttribute( attributeType.getName(), true );
+            
+            ServerAttribute<?> attr = entry.get( attributeType );
+            
+            for ( Iterator<ServerValue<?>> iter = attr.iterator(); iter.hasNext();)
+            {
+                ServerValue<?> value = iter.next();
+                attribute.add( value );
+            }
+            
+            attributes.put( attribute );
+        }
+        
+        return attributes;
+    }
+}



Mime
View raw message