001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.replication.protocol; 028 029 import static org.opends.server.replication.protocol.OperationContext.*; 030 031 import java.io.UnsupportedEncodingException; 032 import java.util.zip.DataFormatException; 033 034 import org.opends.server.core.DeleteOperationBasis; 035 import org.opends.server.protocols.asn1.ASN1OctetString; 036 import org.opends.server.protocols.internal.InternalClientConnection; 037 import org.opends.server.replication.common.ChangeNumber; 038 import org.opends.server.types.AbstractOperation; 039 import org.opends.server.types.operation.PostOperationDeleteOperation; 040 041 /** 042 * Object used when sending delete information to replication servers. 043 */ 044 public class DeleteMsg extends UpdateMessage 045 { 046 private static final long serialVersionUID = -4905520652801395185L; 047 048 /** 049 * Creates a new delete message. 050 * 051 * @param operation the Operation from which the message must be created. 052 */ 053 public DeleteMsg(PostOperationDeleteOperation operation) 054 { 055 super((OperationContext) operation.getAttachment(SYNCHROCONTEXT), 056 operation.getRawEntryDN().stringValue()); 057 } 058 059 /** 060 * Creates a new delete message. 061 * 062 * @param dn The dn with which the message must be created. 063 * @param changeNumber The change number with which the message must be 064 * created. 065 * @param uid The unique id with which the message must be created. 066 */ 067 public DeleteMsg(String dn, ChangeNumber changeNumber, String uid) 068 { 069 super(new DeleteContext(changeNumber, uid), dn); 070 } 071 072 /** 073 * Creates a new Add message from a byte[]. 074 * 075 * @param in The byte[] from which the operation must be read. 076 * @throws DataFormatException The input byte[] is not a valid AddMsg 077 * @throws UnsupportedEncodingException If UTF8 is not supported by the jvm 078 */ 079 public DeleteMsg(byte[] in) throws DataFormatException, 080 UnsupportedEncodingException 081 { 082 super(in); 083 decodeHeader(MSG_TYPE_DELETE_REQUEST, in); 084 } 085 086 087 /** 088 * {@inheritDoc} 089 */ 090 @Override 091 public AbstractOperation createOperation( 092 InternalClientConnection connection, String newDn) 093 { 094 DeleteOperationBasis del = new DeleteOperationBasis(connection, 095 InternalClientConnection.nextOperationID(), 096 InternalClientConnection.nextMessageID(), null, 097 new ASN1OctetString(newDn)); 098 DeleteContext ctx = new DeleteContext(getChangeNumber(), getUniqueId()); 099 del.setAttachment(SYNCHROCONTEXT, ctx); 100 return del; 101 } 102 103 /** 104 * Get the byte array representation of this Message. 105 * 106 * @return The byte array representation of this Message. 107 * 108 * @throws UnsupportedEncodingException When the encoding of the message 109 * failed because the UTF-8 encoding is not supported. 110 */ 111 @Override 112 public byte[] getBytes() throws UnsupportedEncodingException 113 { 114 return encodeHeader(MSG_TYPE_DELETE_REQUEST, 0); 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 @Override 121 public String toString() 122 { 123 return ("DEL " + getDn() + " " + getChangeNumber()); 124 } 125 }