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 2011/03/04 19:36:40 UTC
svn commit: r1078090 [1/2] - in /directory/shared/trunk:
integ/src/test/java/org/apache/directory/shared/ldap/entry/
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/
ldap/model/src/main/java/org/apache/directory/shared/ldap/model/...
Author: elecharny
Date: Fri Mar 4 18:36:39 2011
New Revision: 1078090
URL: http://svn.apache.org/viewvc?rev=1078090&view=rev
Log:
Replaced the serializers
Added:
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializerTest.java
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntrySerializerTest.java
directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntrySerializer.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializerTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntrySerializerTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/ValueSerializerTest.java
Modified:
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/StringValueAttributeTypeTest.java
Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializerTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntryAttributeSerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,200 @@
+/*
+ * 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.shared.ldap.entry;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.EntryAttributeSerializer;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the EntryAttribute Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareEntryAttributeSerializerTest
+{
+ private static byte[] data1 = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private static byte[] data2 = new byte[] {0x05, 0x06, 0x07, 0x08};
+ private static byte[] data3 = new byte[] {0x09, 0x0A, 0x0B, 0x0C};
+
+ private static AttributeType cn = null;
+ private static AttributeType userCertificate = null;
+
+ private static SchemaManager schemaManager;
+
+ /**
+ * Initialize OIDs maps for normalization
+ */
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ schemaManager = new DefaultSchemaManager();
+ cn = schemaManager.getAttributeType( "cn" );
+ userCertificate = schemaManager.getAttributeType( "userCertificate" );
+ }
+
+
+ @Test
+ public void testEntryAttributeNoStringValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( cn );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeOneStringValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "CommonName", cn, "test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ assertEquals( "CommonName", attribute2.getUpId() );
+ }
+
+
+ @Test
+ public void testEntryAttributeManyStringValuesSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "CN", cn, "test1", "test2", "test3" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ assertEquals( "CN", attribute2.getUpId() );
+ }
+
+
+ @Test
+ public void testEntryAttributeNoBinaryValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( userCertificate );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeOneBinaryValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( userCertificate, data1 );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeManyBinaryValuesSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "UserCertificate", userCertificate, data1, data2, data3 );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ assertEquals( attribute1, attribute2 );
+ assertEquals( "UserCertificate", attribute2.getUpId() );
+ }
+}
Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntrySerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntrySerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntrySerializerTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareEntrySerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,142 @@
+/*
+ * 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.shared.ldap.entry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.EntrySerializer;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Entry Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareEntrySerializerTest
+{
+ private static SchemaManager schemaManager;
+
+ /**
+ * Initialize OIDs maps for normalization
+ */
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ schemaManager = new DefaultSchemaManager();
+ }
+
+
+ @Test
+ public void testEntryFullSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry(
+ schemaManager,
+ "dc=example, dc=com",
+ "ObjectClass: top",
+ "ObjectClass: domain",
+ "dc: example",
+ "l: test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( schemaManager, in );
+
+ assertEquals( entry1, entry2 );
+ assertTrue( entry2.contains( "2.5.4.0", "top", "domain" ) );
+ }
+
+
+ @Test
+ public void testEntryNoDnSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry(
+ schemaManager,
+ "",
+ "ObjectClass: top",
+ "ObjectClass: domain",
+ "dc: example",
+ "l: test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( schemaManager, in );
+
+ assertEquals( entry1, entry2 );
+ assertTrue( entry2.contains( "ObjectClass", "top", "domain" ) );
+ assertEquals( "", entry2.getDn().toString() );
+ }
+
+
+ @Test
+ public void testEntryNoAttributesSerialization() throws IOException, LdapException
+ {
+ Entry entry1 = LdifUtils.createEntry( schemaManager, "dc=example, dc=com" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntrySerializer.serialize( entry1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ Entry entry2 = EntrySerializer.deserialize( schemaManager, in );
+
+ assertEquals( entry1, entry2 );
+ assertEquals( 0, entry2.size() );
+ }
+}
Added: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java (added)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/entry/SchemaAwareValueSerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,327 @@
+/*
+ * 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.shared.ldap.entry;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.shared.ldap.model.entry.BinaryValue;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.util.StringConstants;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the Value Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareValueSerializerTest
+{
+ private static byte[] data = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private static BinaryValue bv1;
+ private static BinaryValue bv2;
+ private static BinaryValue bv3;
+ private static BinaryValue bv1n;
+ private static BinaryValue bv2n;
+ private static BinaryValue bv3n;
+ private static StringValue sv1;
+ private static StringValue sv2;
+ private static StringValue sv3;
+ private static StringValue sv1n;
+ private static StringValue sv2n;
+ private static StringValue sv3n;
+
+
+ private static SchemaManager schemaManager;
+
+ /**
+ * Initialize OIDs maps for normalization
+ */
+ @BeforeClass
+ public static void setup() throws Exception
+ {
+ schemaManager = new DefaultSchemaManager();
+ AttributeType cn = schemaManager.getAttributeType( "cn" );
+ AttributeType userCertificate = schemaManager.getAttributeType( "userCertificate" );
+
+ bv1 = new BinaryValue( userCertificate, data );
+ bv2 = new BinaryValue( userCertificate, StringConstants.EMPTY_BYTES );
+ bv3 = new BinaryValue( userCertificate );
+ bv1n = new BinaryValue( userCertificate, data );
+ bv2n = new BinaryValue( userCertificate, StringConstants.EMPTY_BYTES );
+ bv3n = new BinaryValue( userCertificate );
+ sv1 = new StringValue( cn, "test" );
+ sv2 = new StringValue( cn, "" );
+ sv3 = new StringValue( cn );
+ sv1n = new StringValue( cn, "test" );
+ sv2n = new StringValue( cn, "" );
+ sv3n = new StringValue( cn );
+ }
+
+
+ @Test
+ public void testBinaryValueWithDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv1, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithEmptyDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv2, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv2, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueNoDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ BinaryValue.serialize( bv3, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv3, bvDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv1, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithEmptyDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv2, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv2, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueNoDataSerialization() throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ StringValue.serialize( sv3, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv3, svDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv1n.normalize();
+
+ BinaryValue.serialize( bv1n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv1n, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv2n.normalize();
+
+ BinaryValue.serialize( bv2n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv2n, bvDeser );
+ }
+
+
+ @Test
+ public void testBinaryValueNoDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ bv3n.normalize();
+
+ BinaryValue.serialize( bv3n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ BinaryValue bvDeser = (BinaryValue)BinaryValue.deserialize( null, in );
+
+ assertEquals( bv3n, bvDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv1n.normalize();
+
+ StringValue.serialize( sv1n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv1n, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueWithEmptyDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv2n.normalize();
+
+ StringValue.serialize( sv2n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv2n, svDeser );
+ }
+
+
+ @Test
+ public void testStringValueNoDataNormalizedSerialization() throws IOException, LdapException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+ sv3n.normalize();
+
+ StringValue.serialize( sv3n, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ StringValue svDeser = (StringValue)StringValue.deserialize( null, in );
+
+ assertEquals( sv3n, svDeser );
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/AbstractValue.java Fri Mar 4 18:36:39 2011
@@ -19,13 +19,19 @@
*/
package org.apache.directory.shared.ldap.model.entry;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.schema.AttributeType;
import org.apache.directory.shared.ldap.model.schema.LdapComparator;
import org.apache.directory.shared.ldap.model.schema.MatchingRule;
import org.apache.directory.shared.ldap.model.schema.Normalizer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
+import org.apache.directory.shared.util.StringConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +47,7 @@ public abstract class AbstractValue<T> i
private static final Logger LOG = LoggerFactory.getLogger( AbstractValue.class );
/** reference to the attributeType zssociated with the value */
- protected AttributeType attributeType;
+ protected transient AttributeType attributeType;
/** the wrapped binary value */
protected T wrappedValue;
@@ -370,4 +376,216 @@ public abstract class AbstractValue<T> i
{
this.normalized = normalized;
}
+
+
+ /**
+ * Serializes a Value instance.
+ *
+ * @param value The Value instance to serialize
+ * @param out The stream into which we will write the serialized instance
+ * @throws IOException If the stream can't be written
+ */
+ @SuppressWarnings("unchecked")
+ public static void serialize( Value<?> value, ObjectOutput out ) throws IOException
+ {
+ // The Value type
+ out.writeBoolean( value.isBinary() );
+
+ // The AttributeType's OID if we have one
+ if ( value.getAttributeType() != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( value.getAttributeType().getOid() );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ // The UP value and norm value
+ if ( value.isBinary() )
+ {
+ byte[] upValue = (byte[])value.getReference();
+
+ if ( upValue == null )
+ {
+ out.writeInt( -1 );
+ }
+ else
+ {
+ out.writeInt( upValue.length );
+
+ if ( upValue.length > 0 )
+ {
+ out.write( upValue );
+ }
+ }
+
+ byte[] normValue = (byte[])value.getNormalizedValueReference();
+
+ if ( normValue == null )
+ {
+ out.writeInt( -1 );
+ }
+ else
+ {
+ out.writeInt( normValue.length );
+
+ if ( normValue.length > 0 )
+ {
+ out.write( normValue );
+ }
+ }
+ }
+ else
+ {
+ if ( ((AbstractValue<String>)value).wrappedValue != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( ((AbstractValue<String>)value).wrappedValue );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ if ( ((AbstractValue<String>)value).normalizedValue != null )
+ {
+ out.writeBoolean( true );
+ out.writeUTF( ((AbstractValue<String>)value).normalizedValue );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+ }
+
+ // The normalized flag
+ out.writeBoolean( value.isNormalized() );
+
+ // The valid flag
+ out.writeBoolean( value.isValid() );
+
+ // The same flag
+ if ( value.isBinary() )
+ {
+ out.writeBoolean( ((BinaryValue)value).isSame() );
+ }
+ else
+ {
+ out.writeBoolean( ((StringValue)value).isSame() );
+ }
+
+ // The computed hashCode
+ out.writeInt( value.hashCode() );
+
+ out.flush();
+ }
+
+
+ /**
+ * Deserializes a Value instance.
+ *
+ * @param schemaManager The schemaManager instance
+ * @param in The input stream from which the Value is read
+ * @return a deserialized Value
+ * @throws IOException If the stream can't be read
+ */
+ @SuppressWarnings("unchecked")
+ public static Value<?> deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
+ {
+ // The value type
+ boolean isBinary = in.readBoolean();
+
+ Value<?> value = null;
+
+ if ( isBinary )
+ {
+ value = new BinaryValue();
+ }
+ else
+ {
+ value = new StringValue();
+ }
+
+ // The attributeType presence's flag
+ boolean hasAttributeType = in.readBoolean();
+
+ if ( hasAttributeType )
+ {
+ String oid = in.readUTF();
+
+ if ( schemaManager != null )
+ {
+ ((AbstractValue<?>)value).attributeType = schemaManager.getAttributeType( oid );
+ }
+ }
+
+ if ( isBinary )
+ {
+ int upValueSize = in.readInt();
+
+ switch ( upValueSize )
+ {
+ case -1 :
+ break;
+
+ case 0 :
+ ((AbstractValue<byte[]>)value).wrappedValue = StringConstants.EMPTY_BYTES;
+ break;
+
+ default :
+ ((AbstractValue<byte[]>)value).wrappedValue = new byte[upValueSize];
+ in.read( ((AbstractValue<byte[]>)value).wrappedValue );
+ break;
+ }
+
+ int normValueSize = in.readInt();
+
+ switch ( normValueSize )
+ {
+ case -1 :
+ break;
+
+ case 0 :
+ ((AbstractValue<byte[]>)value).normalizedValue = StringConstants.EMPTY_BYTES;
+ break;
+
+ default :
+ ((AbstractValue<byte[]>)value).normalizedValue = new byte[normValueSize];
+ in.read( ((AbstractValue<byte[]>)value).normalizedValue );
+ break;
+ }
+ }
+ else
+ {
+ boolean notNull = in.readBoolean();
+
+ if ( notNull )
+ {
+ ((AbstractValue<String>)value).wrappedValue = in.readUTF();
+ }
+
+ notNull = in.readBoolean();
+
+ if ( notNull )
+ {
+ ((AbstractValue<String>)value).normalizedValue = in.readUTF();
+ }
+ }
+
+ // The normalized flag
+ ((AbstractValue<?>)value).normalized = in.readBoolean();
+
+ // The valid flag
+ ((AbstractValue<?>)value).valid = in.readBoolean();
+
+ // The same flag
+ ((AbstractValue<?>)value).same = in.readBoolean();
+
+ // The computed hashCode
+ ((AbstractValue<?>)value).h = in.readInt();
+
+ return value;
+ }
}
\ No newline at end of file
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/BinaryValue.java Fri Mar 4 18:36:39 2011
@@ -30,6 +30,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.schema.AttributeType;
import org.apache.directory.shared.ldap.model.schema.LdapComparator;
import org.apache.directory.shared.ldap.model.schema.Normalizer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
import org.apache.directory.shared.ldap.model.schema.comparators.ByteArrayComparator;
import org.apache.directory.shared.util.StringConstants;
@@ -54,9 +55,6 @@ public class BinaryValue extends Abstrac
/** logger for reporting errors that might not be handled properly upstream */
private static final Logger LOG = LoggerFactory.getLogger( BinaryValue.class );
- /** The computed hashcode. We don't want to compute it each time the hashcode() method is called */
- private volatile int h;
-
/**
* Creates a BinaryValue without an initial wrapped value.
@@ -637,160 +635,13 @@ public class BinaryValue extends Abstrac
}
}
-
+
/**
- * We will write the value and the normalized value, only
- * if the normalized value is different.
- *
- * If the value is empty, a flag is written at the beginning with
- * the value true, otherwise, a false is written.
- *
- * The data will be stored following this structure :
- * [length] the wrapped length. Can be -1, if wrapped is null
- * [value length]
- * [UP value] if not empty
- * [normalized] (will be false if the value can't be normalized)
- * [same] (a flag set to true if the normalized value equals the UP value)
- * [Norm value] (the normalized value if different from the UP value, and not empty)
- *
- * @param out the buffer in which we will stored the serialized form of the value
- * @throws IOException if we can't write into the buffer
- */
- public void serialize( ObjectOutput out ) throws IOException
- {
- if ( wrappedValue != null )
- {
- // write a the wrapped length
- out.writeInt( wrappedValue.length );
-
- // Write the data if not empty
- if ( wrappedValue.length > 0 )
- {
- // The data
- out.write( wrappedValue );
-
- // Normalize the data
- try
- {
- normalize();
-
- if ( !normalized )
- {
- // We may not have a normalizer. Just get out
- // after having writen the flag
- out.writeBoolean( false );
- }
- else
- {
- // Write a flag indicating that the data has been normalized
- out.writeBoolean( true );
-
- if ( Arrays.equals( getReference(), normalizedValue ) )
- {
- // Write the 'same = true' flag
- out.writeBoolean( true );
- }
- else
- {
- // Write the 'same = false' flag
- out.writeBoolean( false );
-
- // Write the normalized value length
- out.writeInt( normalizedValue.length );
-
- if ( normalizedValue.length > 0 )
- {
- // Write the normalized value if not empty
- out.write( normalizedValue );
- }
- }
- }
- }
- catch ( LdapException ne )
- {
- // The value can't be normalized, we don't write the
- // normalized value.
- normalizedValue = null;
- out.writeBoolean( false );
- }
- }
- }
- else
- {
- // Write -1 indicating that the value is null
- out.writeInt( -1 );
- }
- }
-
-
- /**
- *
- * Deserialize a BinaryValue.
- *
- * @param in the buffer containing the bytes with the serialized value
- * @throws IOException
- * @throws ClassNotFoundException
+ * {@inheritDoc}
*/
- public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
+ public static BinaryValue deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
{
- // The UP value length
- int wrappedLength = in.readInt();
-
- if ( wrappedLength == -1 )
- {
- // If the value is null, the length will be set to -1
- same = true;
- wrappedValue = null;
- }
- else if ( wrappedLength == 0 )
- {
- wrappedValue = StringConstants.EMPTY_BYTES;
- same = true;
- normalized = true;
- normalizedValue = wrappedValue;
- }
- else
- {
- wrappedValue = new byte[wrappedLength];
-
- // Read the data
- in.readFully( wrappedValue );
-
- // Check if we have a normalized value
- normalized = in.readBoolean();
-
- if ( normalized )
- {
- // Read the 'same' flag
- same = in.readBoolean();
-
- if ( !same )
- {
- // Read the normalizedvalue length
- int normalizedLength = in.readInt();
-
- if ( normalizedLength > 0 )
- {
- normalizedValue = new byte[normalizedLength];
-
- // Read the normalized value
- if ( in.read( normalizedValue, 0, normalizedLength ) == -1 )
- {
- throw new IOException( I18n.err( I18n.ERR_04480_END_OF_STREAM ) );
- }
- }
- else
- {
- normalizedValue = StringConstants.EMPTY_BYTES;
- }
- }
- else
- {
- normalizedValue = new byte[wrappedLength];
- System.arraycopy( wrappedValue, 0, normalizedValue, 0, wrappedLength );
- }
- }
- }
+ return (BinaryValue)AbstractValue.deserialize( schemaManager, in );
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntry.java Fri Mar 4 18:36:39 2011
@@ -315,7 +315,7 @@ public class DefaultEntry implements Ent
public DefaultEntry( SchemaManager schemaManager, Dn dn, EntryAttribute... attributes )
{
this.schemaManager = schemaManager;
-
+
if ( dn == null )
{
this.dn = Dn.EMPTY_DN;
@@ -326,18 +326,40 @@ public class DefaultEntry implements Ent
normalizeDN( this.dn );
}
- initObjectClassAT();
-
- for ( EntryAttribute attribute : attributes )
+ if ( schemaManager == null )
{
- // Store a new ServerAttribute
- try
+ if ( attributes != null )
{
- put( attribute );
+ for ( EntryAttribute attribute : attributes )
+ {
+ if ( attribute == null )
+ {
+ continue;
+ }
+
+ // Store a new ClientAttribute
+ this.attributes.put( attribute.getId(), attribute );
+ }
}
- catch ( LdapException ne )
+ }
+ else
+ {
+ initObjectClassAT();
+
+ if ( attributes != null )
{
- LOG.warn( "The ServerAttribute '{}' does not exist. It has been discarded", attribute );
+ for ( EntryAttribute attribute : attributes )
+ {
+ // Store a new ServerAttribute
+ try
+ {
+ put( attribute );
+ }
+ catch ( LdapException ne )
+ {
+ LOG.warn( "The ServerAttribute '{}' does not exist. It has been discarded", attribute );
+ }
+ }
}
}
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/DefaultEntryAttribute.java Fri Mar 4 18:36:39 2011
@@ -160,6 +160,27 @@ public class DefaultEntryAttribute imple
/**
* Create a new instance of a EntryAttribute, without ID nor value.
+ */
+ /* No qualifier */ DefaultEntryAttribute( AttributeType attributeType, String upId, String normId, boolean isHR, int hashCode, Value<?>... values)
+ {
+ this.attributeType = attributeType;
+ this.upId = upId;
+ this.id = normId;
+ this.isHR = isHR;
+ this.h = hashCode;
+
+ if ( values != null )
+ {
+ for ( Value<?> value : values )
+ {
+ this.values.add( value );
+ }
+ }
+ }
+
+
+ /**
+ * Create a new instance of a EntryAttribute, without ID nor value.
*
* @param attributeType the attributeType for the empty attribute added into the entry
*/
@@ -2421,11 +2442,11 @@ public class DefaultEntryAttribute imple
// Write the value, using the correct method
if ( value instanceof StringValue)
{
- ((StringValue)value).serialize( out );
+ StringValue.serialize( value, out );
}
else
{
- ((BinaryValue)value).serialize( out );
+ BinaryValue.serialize( value, out );
}
}
}
@@ -2462,13 +2483,11 @@ public class DefaultEntryAttribute imple
if ( isHR )
{
- value = new StringValue( attributeType );
- ((StringValue)value).deserialize( in );
+ value = StringValue.deserialize( null, in );
}
else
{
- value = new BinaryValue( attributeType );
- ((BinaryValue)value).deserialize( in );
+ value = BinaryValue.deserialize( null, in );
}
try
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializer.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,133 @@
+/*
+ * 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.shared.ldap.model.entry;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which serialize and deserialize a EntryAttribute.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryAttributeSerializer
+{
+ /** The LoggerFactory used by this class */
+ protected static final Logger LOG = LoggerFactory.getLogger( EntryAttributeSerializer.class );
+
+ /**
+ * Private constructor.
+ */
+ private EntryAttributeSerializer()
+ {
+ }
+
+
+ /**
+ * Serializes a EntryAttribute instance.
+ *
+ * @param principal The EntryAttribute instance to serialize
+ * @param out The stream into which we will write the serialized instance
+ * @throws IOException If the stream can't be written
+ */
+ public static void serialize( EntryAttribute attribute, ObjectOutput out ) throws IOException
+ {
+ // The UP id
+ out.writeUTF( attribute.getUpId() );
+
+ // The Norm id
+ out.writeUTF( attribute.getId() );
+
+ // The isHR flag
+ out.writeBoolean( attribute.isHR() );
+
+ // The computed hashCode
+ out.writeInt( attribute.hashCode() );
+
+ // The number of values
+ int nbValues = attribute.size();
+ out.writeInt( nbValues );
+
+ if ( nbValues > 0 )
+ {
+ for ( Value<?> value : attribute )
+ {
+ AbstractValue.serialize( value, out );
+ }
+ }
+
+ out.flush();
+ }
+
+
+ /**
+ * Deserializes a EntryAttribute instance.
+ *
+ * @param schemaManager The schemaManager instance
+ * @param in The input stream from which the EntryAttribute is read
+ * @return a deserialized EntryAttribute
+ * @throws IOException If the stream can't be read
+ */
+ public static EntryAttribute deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
+ {
+ // The UP id
+ String upId = in.readUTF();
+
+ // The Norm id
+ String normId = in.readUTF();
+
+ // The isHR flag
+ boolean isHR = in.readBoolean();
+
+ // The computed hashCode
+ int hashCode = in.readInt();
+
+ // The number of values
+ int nbValues = in.readInt();
+ Value<?>[] values = new Value<?>[ nbValues ];
+
+ if ( nbValues > 0 )
+ {
+ for ( int i = 0; i < nbValues; i++ )
+ {
+ Value<?> value = AbstractValue.deserialize( schemaManager, in );
+ values[i] = value;
+ }
+ }
+
+ AttributeType attributeType = null;
+
+ if ( schemaManager != null )
+ {
+ attributeType = schemaManager.getAttributeType( upId );
+ }
+
+ // The EntryAttribute
+ EntryAttribute attribute = new DefaultEntryAttribute( attributeType, upId, normId, isHR, hashCode, values );
+
+ return attribute;
+ }
+}
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntrySerializer.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntrySerializer.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/EntrySerializer.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,113 @@
+/*
+ * 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.shared.ldap.model.entry;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+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.name.DnSerializer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which serialize and deserialize an Entry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntrySerializer
+{
+ /** The LoggerFactory used by this class */
+ protected static final Logger LOG = LoggerFactory.getLogger( EntrySerializer.class );
+
+ /**
+ * Private constructor.
+ */
+ private EntrySerializer()
+ {
+ }
+
+
+ /**
+ * Serializes a Entry instance.
+ *
+ * @param principal The Entry instance to serialize
+ * @param out The stream into which we will write the serialized instance
+ * @throws IOException If the stream can't be written
+ */
+ public static void serialize( Entry entry, ObjectOutput out ) throws IOException
+ {
+ // First, the Dn
+ DnSerializer.serialize( entry.getDn(), out );
+
+ // Then the attributes.
+ int nbAttributes = entry.size();
+ out.writeInt( nbAttributes );
+
+ // Iterate through the attributes
+ if ( nbAttributes > 0 )
+ {
+ for ( EntryAttribute attribute : entry )
+ {
+ EntryAttributeSerializer.serialize( attribute, out );
+ }
+ }
+
+ out.flush();
+ }
+
+
+ /**
+ * Deserializes a Entry instance.
+ *
+ * @param schemaManager The schemaManager instance
+ * @param in The input stream from which the Entry is read
+ * @return a deserialized Entry
+ * @throws IOException If the stream can't be read
+ */
+ public static Entry deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException, LdapInvalidDnException
+ {
+ // The Dn
+ Dn dn = DnSerializer.deserialize( schemaManager, in );
+
+ // The attributes
+ int nbAttributes = in.readInt();
+
+ EntryAttribute[] attributes = null;
+
+ if ( nbAttributes > 0 )
+ {
+ attributes = new EntryAttribute[ nbAttributes ];
+
+ for ( int i = 0; i < nbAttributes; i++ )
+ {
+ EntryAttribute attribute = EntryAttributeSerializer.deserialize( schemaManager, in );
+ attributes[i] = attribute;
+ }
+ }
+
+ Entry entry = new DefaultEntry( schemaManager, dn, attributes );
+
+ return entry;
+ }
+}
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/ModificationSerializer.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,87 @@
+/*
+ * 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.shared.ldap.model.entry;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which serialize and deserialize a Modification.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModificationSerializer
+{
+ /** The LoggerFactory used by this class */
+ protected static final Logger LOG = LoggerFactory.getLogger( ModificationSerializer.class );
+
+ /**
+ * Private constructor.
+ */
+ private ModificationSerializer()
+ {
+ }
+
+
+ /**
+ * Serializes a Modification instance.
+ *
+ * @param principal The Modification instance to serialize
+ * @param out The stream into which we will write the serialized instance
+ * @throws IOException If the stream can't be written
+ */
+ public static void serialize( Modification modification, ObjectOutput out ) throws IOException
+ {
+ // The operation
+ out.writeInt( modification.getOperation().getValue() );
+
+ // The EntryAttribute
+ EntryAttributeSerializer.serialize( modification.getAttribute(), out );
+
+ out.flush();
+ }
+
+
+ /**
+ * Deserializes a Modification instance.
+ *
+ * @param schemaManager The schemaManager instance
+ * @param in The input stream from which the Modification is read
+ * @return a deserialized Modification
+ * @throws IOException If the stream can't be read
+ */
+ public static Modification deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
+ {
+ // The operation
+ ModificationOperation operation = ModificationOperation.getOperation( in.readInt() );
+
+ // The EntryAttribute
+ EntryAttribute attribute = EntryAttributeSerializer.deserialize( schemaManager, in );
+
+ Modification modification = new DefaultModification( operation, attribute );
+
+ return modification;
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/StringValue.java Fri Mar 4 18:36:39 2011
@@ -25,12 +25,13 @@ import java.io.ObjectOutput;
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.exception.LdapException;
-import org.apache.directory.shared.util.exception.NotImplementedException;
import org.apache.directory.shared.ldap.model.schema.AttributeType;
import org.apache.directory.shared.ldap.model.schema.LdapComparator;
import org.apache.directory.shared.ldap.model.schema.Normalizer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.util.Strings;
import org.apache.directory.shared.util.Unicode;
+import org.apache.directory.shared.util.exception.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -546,110 +547,15 @@ public class StringValue extends Abstrac
/**
- * We will write the value and the normalized value, only
- * if the normalized value is different.
- *
- * If the value is empty, a flag is written at the beginning with
- * the value true, otherwise, a false is written.
- *
- * The data will be stored following this structure :
- * [empty value flag]
- * [UP value]
- * [normalized] (will be false if the value can't be normalized)
- * [same] (a flag set to true if the normalized value equals the UP value)
- * [Norm value] (the normalized value if different from the UP value)
- *
- * @param out the buffer in which we will stored the serialized form of the value
- * @throws IOException if we can't write into the buffer
+ * {@inheritDoc}
*/
- public void serialize( ObjectOutput out ) throws IOException
+ public static StringValue deserialize( SchemaManager schemaManager, ObjectInput in ) throws IOException
{
- if ( wrappedValue != null )
- {
- // write a flag indicating that the value is not null
- out.writeBoolean( true );
-
- // Write the data
- Unicode.writeUTF(out, wrappedValue);
-
- // Normalize the data
- try
- {
- normalize();
- out.writeBoolean( true );
-
- if ( wrappedValue.equals( normalizedValue ) )
- {
- out.writeBoolean( true );
- }
- else
- {
- out.writeBoolean( false );
- Unicode.writeUTF(out, normalizedValue);
- }
- }
- catch ( LdapException ne )
- {
- // The value can't be normalized, we don't write the
- // normalized value.
- normalizedValue = null;
- out.writeBoolean( false );
- }
- }
- else
- {
- // Write a flag indicating that the value is null
- out.writeBoolean( false );
- }
-
- out.flush();
+ return (StringValue)AbstractValue.deserialize( schemaManager, in );
}
/**
- * Deserialize a StringValue.
- *
- * @param in the buffer containing the bytes with the serialized value
- * @throws IOException
- * @throws ClassNotFoundException
- */
- public void deserialize( ObjectInput in ) throws IOException, ClassNotFoundException
- {
- // If the value is null, the flag will be set to false
- if ( !in.readBoolean() )
- {
- wrappedValue = null;
- normalizedValue = null;
- return;
- }
-
- // Read the value
- String wrapped = Unicode.readUTF(in);
-
- wrappedValue = wrapped;
-
- // Read the normalized flag
- normalized = in.readBoolean();
-
- if ( normalized )
- {
- normalized = true;
-
- // Read the 'same' flag
- if ( in.readBoolean() )
- {
- normalizedValue = wrapped;
- }
- else
- {
- // The normalized value is different. Read it
- normalizedValue = Unicode.readUTF(in);
- }
- }
- }
-
-
- /**
* @see Object#toString()
*/
public String toString()
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/entry/Value.java Fri Mar 4 18:36:39 2011
@@ -23,7 +23,6 @@ package org.apache.directory.shared.ldap
import java.io.Externalizable;
import org.apache.directory.shared.ldap.model.exception.LdapException;
-
import org.apache.directory.shared.ldap.model.schema.AttributeType;
import org.apache.directory.shared.ldap.model.schema.Normalizer;
import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntry.java Fri Mar 4 18:36:39 2011
@@ -30,8 +30,15 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.directory.shared.ldap.model.entry.*;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
import org.apache.directory.shared.ldap.model.entry.StringValue;
+import org.apache.directory.shared.ldap.model.entry.Value;
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.model.message.Control;
@@ -54,11 +61,8 @@ import org.apache.directory.shared.util.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class LdifEntry implements Cloneable, Externalizable
+public class LdifEntry implements Cloneable
{
- /** The serial version UID */
- private static final long serialVersionUID = 2L;
-
/** Used in toArray() */
public static final Modification[] EMPTY_MODS = new Modification[0];
@@ -88,7 +92,7 @@ public class LdifEntry implements Clonea
/**
- * Creates a new Entry object.
+ * Creates a new LdifEntry object.
*/
public LdifEntry()
{
@@ -101,6 +105,19 @@ public class LdifEntry implements Clonea
/**
+ * Creates a new LdifEntry object, storing an Entry
+ */
+ public LdifEntry( Entry entry )
+ {
+ changeType = ChangeType.None; // Default LDIF content
+ modificationList = new LinkedList<Modification>();
+ modificationItems = new HashMap<String, Modification>();
+ this.entry = entry;
+ controls = null;
+ }
+
+
+ /**
* Set the Distinguished Name
*
* @param dn The Distinguished Name
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/ldif/LdifEntrySerializer.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,236 @@
+/*
+ * 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.shared.ldap.model.ldif;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.EntrySerializer;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationSerializer;
+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.name.DnSerializer;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.util.Unicode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which serialize and deserialize a LdifEntry.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdifEntrySerializer
+{
+ /** The LoggerFactory used by this class */
+ protected static final Logger LOG = LoggerFactory.getLogger( LdifEntrySerializer.class );
+
+ /**
+ * Private constructor.
+ */
+ private LdifEntrySerializer()
+ {
+ }
+
+
+ /**
+ * Serializes a LdifEntry instance.
+ *
+ * @param principal The LdifEntry instance to serialize
+ * @param out The stream into which we will write the serialized instance
+ * @throws IOException If the stream can't be written
+ */
+ public static void serialize( LdifEntry ldifEntry, ObjectOutput out ) throws IOException
+ {
+ // The changeType
+ out.writeInt( ldifEntry.getChangeType().getChangeType() );
+
+ switch ( ldifEntry.getChangeType() )
+ {
+ case Add :
+ // We write the entry
+ EntrySerializer.serialize( ldifEntry.getEntry(), out );
+
+ break;
+
+ case Delete :
+ // We just have to store the deleted DN
+ DnSerializer.serialize( ldifEntry.getDn(), out );
+
+ break;
+
+ case ModDn :
+ case ModRdn :
+ DnSerializer.serialize( ldifEntry.getDn(), out );
+ out.writeBoolean( ldifEntry.isDeleteOldRdn() );
+
+ if ( ldifEntry.getNewRdn() != null )
+ {
+ out.writeBoolean( true );
+ Unicode.writeUTF( out, ldifEntry.getNewRdn() );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ if ( ldifEntry.getNewSuperior() != null )
+ {
+ out.writeBoolean( true );
+ Unicode.writeUTF( out, ldifEntry.getNewSuperior() );
+ }
+ else
+ {
+ out.writeBoolean( false );
+ }
+
+ break;
+
+ case Modify :
+ DnSerializer.serialize( ldifEntry.getDn(), out );
+ // Read the modification
+ out.writeInt( ldifEntry.getModificationItems().size() );
+
+ for ( Modification modification : ldifEntry.getModificationItems() )
+ {
+ ModificationSerializer.serialize( modification, out );
+ }
+
+ break;
+ }
+
+
+ // The controls
+ if ( ldifEntry.hasControls() )
+ {
+ // Write the controls
+ out.writeInt( ldifEntry.getControls().size() );
+
+ for ( LdifControl ldifControl : ldifEntry.getControls().values() )
+ {
+ LdifControlSerializer.serialize( ldifControl, out );
+ }
+ }
+ else
+ {
+ out.writeInt( 0 );
+ }
+
+ out.flush();
+ }
+
+
+ /**
+ * Deserializes a LdifEntry instance.
+ *
+ * @param schemaManager The SchemaManager (can be null)
+ * @param in The input stream from which the LdifEntry is read
+ * @return a deserialized LdifEntry
+ * @throws IOException If the stream can't be read
+ */
+ public static LdifEntry deserialize( SchemaManager schemaManager, ObjectInput in )
+ throws IOException, LdapInvalidDnException
+ {
+ // The ChangeType
+ ChangeType changeType = ChangeType.getChangeType( in.readInt() );
+
+ LdifEntry ldifEntry = null;
+
+ switch ( changeType )
+ {
+ case Add :
+ Entry entry = EntrySerializer.deserialize( schemaManager, in );
+ ldifEntry = new LdifEntry( entry );
+ ldifEntry.setChangeType( changeType );
+
+ break;
+
+ case Delete :
+ Dn dn = DnSerializer.deserialize( schemaManager, in );
+ ldifEntry = new LdifEntry();
+ ldifEntry.setChangeType( changeType );
+ ldifEntry.setDn( dn );
+
+ break;
+
+ case ModDn :
+ case ModRdn :
+ ldifEntry = new LdifEntry();
+
+ dn = DnSerializer.deserialize( schemaManager, in );
+ ldifEntry.setDn( dn );
+ boolean deleteOldRdn = in.readBoolean();
+ ldifEntry.setChangeType( changeType );
+ ldifEntry.setDeleteOldRdn( deleteOldRdn );
+
+ // The newRDN
+ if ( in.readBoolean() )
+ {
+ String newRdn = Unicode.readUTF(in);
+ ldifEntry.setNewRdn( newRdn );
+ }
+
+ // The newSuperior
+ if ( in.readBoolean() )
+ {
+ String newSuperior = Unicode.readUTF(in);
+ ldifEntry.setNewSuperior( newSuperior );
+ }
+
+ break;
+
+ case Modify :
+ ldifEntry = new LdifEntry();
+ dn = DnSerializer.deserialize( schemaManager, in );
+ ldifEntry.setDn( dn );
+
+ // Read the modification
+ int nbModifs = in.readInt();
+ ldifEntry.setChangeType( changeType );
+
+ for ( int i = 0; i < nbModifs; i++ )
+ {
+ Modification modification = ModificationSerializer.deserialize( schemaManager, in );
+
+ ldifEntry.addModificationItem( modification );
+ }
+
+ break;
+ }
+
+ // The controls
+ int nbControls = in.readInt();
+
+ if ( nbControls > 0 )
+ {
+ for ( int i = 0; i < nbControls; i++ )
+ {
+ LdifControl ldifControl = LdifControlSerializer.deserialize( in );
+
+ ldifEntry.addControl( ldifControl );
+ }
+ }
+
+ return ldifEntry;
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java Fri Mar 4 18:36:39 2011
@@ -301,7 +301,9 @@ public final class Dn implements Iterabl
Dn( SchemaManager schemaManager, String upName, String normName, Rdn... rdns )
{
this.schemaManager = schemaManager;
- normalized = schemaManager != null;
+
+ normalized = ( schemaManager != null ) || ( normName != null );
+
this.upName = upName;
this.normName = normName;
bytes = Strings.getBytesUtf8( upName );
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java?rev=1078090&r1=1078089&r2=1078090&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/BinaryValueAttributeTypeTest.java Fri Mar 4 18:36:39 2011
@@ -134,7 +134,7 @@ public class BinaryValueAttributeTypeTes
try
{
oOut = new ObjectOutputStream( out );
- value.serialize( oOut );
+ BinaryValue.serialize( value, oOut );
}
catch ( IOException ioe )
{
@@ -172,8 +172,7 @@ public class BinaryValueAttributeTypeTes
{
oIn = new ObjectInputStream( in );
- BinaryValue value = new BinaryValue( at );
- value.deserialize( oIn );
+ BinaryValue value = BinaryValue.deserialize( null, oIn );
return value;
}
Added: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializerTest.java?rev=1078090&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializerTest.java (added)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/entry/EntryAttributeSerializerTest.java Fri Mar 4 18:36:39 2011
@@ -0,0 +1,173 @@
+/*
+ * 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.shared.ldap.model.entry;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Test the EntryAttribute Serialization
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class EntryAttributeSerializerTest
+{
+ private static byte[] data1 = new byte[] {0x01, 0x02, 0x03, 0x04};
+ private static byte[] data2 = new byte[] {0x05, 0x06, 0x07, 0x08};
+ private static byte[] data3 = new byte[] {0x09, 0x0A, 0x0B, 0x0C};
+
+ @Test
+ public void testEntryAttributeNoStringValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "CN" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeOneStringValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "CN", "test" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeManyStringValuesSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "CN", "test1", "test2", "test3" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeNoBinaryValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "UserCertificate" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeOneBinaryValueSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "UserCertificate", data1 );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+
+
+ @Test
+ public void testEntryAttributeManyBinaryValuesSerialization() throws IOException
+ {
+ EntryAttribute attribute1 = new DefaultEntryAttribute( "UserCertificate", data1, data2, data3 );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream( baos );
+
+ EntryAttributeSerializer.serialize( attribute1, out );
+
+ ObjectInputStream in = null;
+
+ byte[] data = baos.toByteArray();
+ in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+ EntryAttribute attribute2 = EntryAttributeSerializer.deserialize( null, in );
+
+ assertEquals( attribute1, attribute2 );
+ }
+}