From dfbe880eb338a1d752ce790f689b5133761d7079 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 26 Sep 2013 07:35:55 +0000
Subject: [PATCH] OPENDJ-1116 Introduce abstraction for the changelog DB

---
 opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java b/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
index 20cfc5f..b27f8b8 100644
--- a/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
+++ b/opends/src/server/org/opends/server/replication/protocol/LDAPUpdateMsg.java
@@ -52,7 +52,7 @@
   /**
    * The DN on which the update was originally done.
    */
-  protected String dn;
+  protected DN dn;
 
   /**
    * The entryUUID of the entry that was updated.
@@ -84,7 +84,7 @@
    * @param dn The DN of the entry on which the change
    *           that caused the creation of this object happened
    */
-  public LDAPUpdateMsg(OperationContext ctx, String dn)
+  public LDAPUpdateMsg(OperationContext ctx, DN dn)
   {
     this.protocolVersion = ProtocolVersion.getCurrentVersion();
     this.csn = ctx.getCSN();
@@ -102,7 +102,7 @@
    * @param dn        The DN of the entry on which the change
    *                  that caused the creation of this object happened
    */
-  public LDAPUpdateMsg(CSN csn, String entryUUID, String dn)
+  public LDAPUpdateMsg(CSN csn, String entryUUID, DN dn)
   {
     this.protocolVersion = ProtocolVersion.getCurrentVersion();
     this.csn = csn;
@@ -146,7 +146,7 @@
    *
    * @return The DN on which the operations happened.
    */
-  public String getDn()
+  public DN getDN()
   {
     return dn;
   }
@@ -155,7 +155,7 @@
    * Set the DN.
    * @param dn The dn that must now be used for this message.
    */
-  public void setDn(String dn)
+  public void setDN(DN dn)
   {
     this.dn = dn;
   }
@@ -190,14 +190,14 @@
    * Create and Operation from the message using the provided DN.
    *
    * @param   conn connection to use when creating the message.
-   * @param   newDn the DN to use when creating the operation.
+   * @param   newDN the DN to use when creating the operation.
    * @return  the created Operation.
    * @throws  LDAPException In case of LDAP decoding exception.
    * @throws  ASN1Exception In case of ASN1 decoding exception.
    * @throws DataFormatException In case of bad msg format.
    */
   public abstract Operation createOperation(InternalClientConnection conn,
-      String newDn) throws LDAPException, ASN1Exception, DataFormatException;
+      DN newDN) throws LDAPException, ASN1Exception, DataFormatException;
 
 
   // ============
@@ -237,7 +237,7 @@
   public byte[] encodeHeader(byte type, int additionalLength, short version)
     throws UnsupportedEncodingException
   {
-    byte[] byteDn = dn.getBytes("UTF-8");
+    byte[] byteDn = dn.toString().getBytes("UTF-8");
     byte[] csnByte = getCSN().toString().getBytes("UTF-8");
     byte[] byteEntryuuid = getEntryUUID().getBytes("UTF-8");
 
@@ -297,7 +297,7 @@
   public byte[] encodeHeader_V1(byte type, int additionalLength)
     throws UnsupportedEncodingException
   {
-    byte[] byteDn = dn.getBytes("UTF-8");
+    byte[] byteDn = dn.toString().getBytes("UTF-8");
     byte[] csnByte = getCSN().toString().getBytes("UTF-8");
     byte[] byteEntryuuid = getEntryUUID().getBytes("UTF-8");
 
@@ -474,7 +474,7 @@
 
        // Read the dn
        length = getNextLength(encodedMsg, pos);
-       dn = new String(encodedMsg, pos, length, "UTF-8");
+       dn = DN.decode(new String(encodedMsg, pos, length, "UTF-8"));
        pos += length + 1;
 
        // Read the entryuuid
@@ -492,12 +492,18 @@
        safeDataLevel = encodedMsg[pos++];
 
        return pos;
-     } catch (UnsupportedEncodingException e)
+     }
+     catch (UnsupportedEncodingException e)
      {
        throw new DataFormatException("UTF-8 is not supported by this jvm.");
-     } catch (IllegalArgumentException e)
+     }
+     catch (IllegalArgumentException e)
      {
-       throw new DataFormatException(e.getMessage());
+       throw new DataFormatException(e.getLocalizedMessage());
+     }
+     catch (DirectoryException e)
+     {
+       throw new DataFormatException(e.getLocalizedMessage());
      }
   }
 
@@ -539,7 +545,7 @@
 
       // read the dn
       length = getNextLength(encodedMsg, pos);
-      dn = new String(encodedMsg, pos, length, "UTF-8");
+      dn = DN.decode(new String(encodedMsg, pos, length, "UTF-8"));
       pos += length + 1;
 
       // read the entryuuid
@@ -548,10 +554,15 @@
       pos += length + 1;
 
       return pos;
-    } catch (UnsupportedEncodingException e)
+    }
+    catch (UnsupportedEncodingException e)
     {
       throw new DataFormatException("UTF-8 is not supported by this jvm.");
     }
+    catch (DirectoryException e)
+    {
+      throw new DataFormatException(e.getLocalizedMessage());
+    }
   }
 
   /**

--
Gitblit v1.10.0