You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/12/18 18:30:58 UTC
svn commit: r605265 - in /directory/apacheds/branches/bigbang/core-entry/src:
main/java/org/apache/directory/server/core/entry/
test/java/org/apache/directory/server/core/entry/
Author: elecharny
Date: Tue Dec 18 09:30:47 2007
New Revision: 605265
URL: http://svn.apache.org/viewvc?rev=605265&view=rev
Log:
o Added some helper method in ServerEntryUtils class to convert attributes
o Removed them from the ServerEntry classes
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/ServerAttribute.java
directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.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=605265&r1=605264&r2=605265&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 Tue Dec 18 09:30:47 2007
@@ -27,8 +27,6 @@
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;
@@ -621,20 +619,5 @@
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=605265&r1=605264&r2=605265&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 Tue Dec 18 09:30:47 2007
@@ -37,10 +37,6 @@
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;
/**
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=605265&r1=605264&r2=605265&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 Tue Dec 18 09:30:47 2007
@@ -54,6 +54,7 @@
*/
String getUpId();
+
/**
* Checks to see if this attribute is valid along with the values it contains.
*
Modified: 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=605265&r1=605264&r2=605265&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java Tue Dec 18 09:30:47 2007
@@ -20,13 +20,19 @@
import java.util.Iterator;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
/**
@@ -66,6 +72,89 @@
return attributes;
}
+
+ /**
+ * Convert a BasicAttribute or a AttributeImpl to a ServerAtribute
+ *
+ * @param attributes the BasicAttributes or AttributesImpl instance to convert
+ * @param registries The registries, needed ro build a ServerEntry
+ * @param dn The DN which is needed by the ServerEntry
+ * @return An instance of a ServerEntry object
+ */
+ public static DefaultServerAttribute toServerAttribute( Attribute attribute, AttributeType attributeType )
+ {
+ try
+ {
+ DefaultServerAttribute serverAttribute = new DefaultServerAttribute( attributeType );
+
+ for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements(); )
+ {
+ Object value = values.nextElement();
+
+ if ( value instanceof String )
+ {
+ serverAttribute.add( (String)value );
+ }
+ else if ( value instanceof byte[] )
+ {
+ serverAttribute.add( (byte[])value );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ return serverAttribute;
+ }
+ catch ( NamingException ne )
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Convert a BasicAttributes or a AttributesImpl to a ServerEntry
+ *
+ * @param attributes the BasicAttributes or AttributesImpl instance to convert
+ * @param registries The registries, needed ro build a ServerEntry
+ * @param dn The DN which is needed by the ServerEntry
+ * @return An instance of a ServerEntry object
+ */
+ public static DefaultServerEntry toServerEntry( Attributes attributes, LdapDN dn, Registries registries )
+ {
+ if ( ( attributes instanceof BasicAttributes ) || ( attributes instanceof AttributesImpl ) )
+ {
+ try
+ {
+ DefaultServerEntry entry = new DefaultServerEntry( dn, registries );
+
+ for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); )
+ {
+ Attribute attr = attrs.nextElement();
+ AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( attr.getID() );
+ DefaultServerAttribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );
+
+ if ( serverAttribute != null )
+ {
+ entry.put( serverAttribute );
+ }
+ }
+
+ return entry;
+ }
+ catch ( NamingException ne )
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
/**
* Convert a ServerEntry into a BasicAttributes. The DN is lost
@@ -94,5 +183,45 @@
}
return attributes;
+ }
+
+
+ /**
+ * Convert a ServerAttributeEntry into a BasicAttribute.
+ *
+ * @return An instance of a BasicAttribute() object
+ */
+ public static Attribute toBasicAttribute( ServerAttribute<ServerValue<?>> attr )
+ {
+ Attribute attribute = new BasicAttribute( attr.getUpId(), false );
+
+ for ( Iterator<ServerValue<?>> iter = attr.getAll(); iter.hasNext();)
+ {
+ Value<?> value = iter.next();
+
+ attribute.add( value.get() );
+ }
+
+ return attribute;
+ }
+
+
+ /**
+ * Convert a ServerAttributeEntry into a AttributeImpl.
+ *
+ * @return An instance of a BasicAttribute() object
+ */
+ public Attribute toAttributeImpl( EntryAttribute<Value<?>> attr )
+ {
+ Attribute attribute = new AttributeImpl( attr.getUpId(), false );
+
+ for ( Iterator<Value<?>> iter = attr.getAll(); iter.hasNext();)
+ {
+ Value<?> value = iter.next();
+
+ attribute.add( value.get() );
+ }
+
+ return attribute;
}
}
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=605265&r1=605264&r2=605265&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Tue Dec 18 09:30:47 2007
@@ -474,7 +474,7 @@
attr.add( "Test2" );
attr.add( "Test3" );
- Attribute attribute = attr.toAttribute();
+ Attribute attribute = ServerEntryUtils.toBasicAttribute( attr );
assertEquals( "1.1",attribute.getID() );
assertEquals( 3, attribute.size() );