| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * ***** BEGIN LICENSE BLOCK ***** |
| 4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * The Original Code is mozilla.org code. |
| 17 | * |
| 18 | * The Initial Developer of the Original Code is |
| 19 | * Netscape Communications Corporation. |
| 20 | * Portions created by the Initial Developer are Copyright (C) 1999 |
| 21 | * the Initial Developer. All Rights Reserved. |
| 22 | * |
| 23 | * Contributor(s): |
| 24 | * |
| 25 | * Alternatively, the contents of this file may be used under the terms of |
| 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 29 | * of those above. If you wish to allow use of your version of this file only |
| 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 31 | * use your version of this file under the terms of the MPL, indicate your |
| 32 | * decision by deleting the provisions above and replace them with the notice |
| 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 34 | * the provisions above, a recipient may use your version of this file under |
| 35 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 36 | * |
| 37 | * ***** END LICENSE BLOCK ***** */ |
| 38 | package org.ietf.ldap.client.opers; |
| 39 | |
| 40 | import org.ietf.ldap.ber.stream.BERBoolean; |
| 41 | import org.ietf.ldap.ber.stream.BERElement; |
| 42 | import org.ietf.ldap.ber.stream.BEROctetString; |
| 43 | import org.ietf.ldap.ber.stream.BERSequence; |
| 44 | import org.ietf.ldap.ber.stream.BERTag; |
| 45 | |
| 46 | /** |
| 47 | * This class implements the modify rdn request. This |
| 48 | * object is sent to the ldap server. |
| 49 | * <pre> |
| 50 | * ModifyRDNRequest ::= [APPLICATION 12] SEQUENCE { |
| 51 | * entry LDAPDN, |
| 52 | * newrdn RelativeLDAPDN, |
| 53 | * deleteoldrdn BOOLEAN |
| 54 | * } |
| 55 | * </pre> |
| 56 | * |
| 57 | * Note that LDAPv3 rename this object to JDAPModifyDNRequest |
| 58 | * and has the following defintion: |
| 59 | * <pre> |
| 60 | * ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { |
| 61 | * entry LDAPDN, |
| 62 | * newrdn RelativeLDAPDN, |
| 63 | * deleteoldrdn BOOLEAN, |
| 64 | * newSuperior [0] LDAPDN OPTIONAL |
| 65 | * } |
| 66 | * </pre> |
| 67 | * |
| 68 | * @version 1.0 |
| 69 | */ |
| 70 | public class JDAPModifyRDNRequest extends JDAPBaseDNRequest |
| 71 | implements JDAPProtocolOp { |
| 72 | /** |
| 73 | * Internal variables |
| 74 | */ |
| 75 | protected String m_old_dn = null; |
| 76 | protected String m_new_rdn = null; |
| 77 | protected boolean m_delete_old_dn; |
| 78 | protected String m_new_superior; |
| 79 | |
| 80 | /** |
| 81 | * Constructs modify RDN request. |
| 82 | * @param old_dn old distinguished name |
| 83 | * @param new_dn new distinguished name |
| 84 | * @param delete_old_dn delete the old distinguished name |
| 85 | */ |
| 86 | public JDAPModifyRDNRequest(String old_dn, String new_rdn, |
| 87 | boolean delete_old_dn) { |
| 88 | m_old_dn = old_dn; |
| 89 | m_new_rdn = new_rdn; |
| 90 | m_delete_old_dn = delete_old_dn; |
| 91 | m_new_superior = null; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Constructs modify DN request. |
| 96 | * @param old_dn old distinguished name |
| 97 | * @param new_dn new distinguished name |
| 98 | * @param delete_old_dn delete the old distinguished name |
| 99 | * @param new_superior parent dn |
| 100 | */ |
| 101 | public JDAPModifyRDNRequest(String old_dn, String new_rdn, |
| 102 | boolean delete_old_dn, String new_superior) { |
| 103 | m_old_dn = old_dn; |
| 104 | m_new_rdn = new_rdn; |
| 105 | m_delete_old_dn = delete_old_dn; |
| 106 | m_new_superior = new_superior; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Retrieves the protocol operation type. |
| 111 | * @return protocol type |
| 112 | */ |
| 113 | public int getType() { |
| 114 | return JDAPProtocolOp.MODIFY_RDN_REQUEST; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Sets the base dn. |
| 119 | * @param basedn base dn |
| 120 | */ |
| 121 | public void setBaseDN(String basedn) { |
| 122 | m_old_dn = basedn; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Gets the base dn component. |
| 127 | * @return base dn |
| 128 | */ |
| 129 | public String getBaseDN() { |
| 130 | return m_old_dn; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Gets the ber representation of the request. |
| 135 | * @return ber representation |
| 136 | */ |
| 137 | public BERElement getBERElement() { |
| 138 | BERSequence seq = new BERSequence(); |
| 139 | seq.addElement(new BEROctetString(m_old_dn)); |
| 140 | seq.addElement(new BEROctetString(m_new_rdn)); |
| 141 | seq.addElement(new BERBoolean(m_delete_old_dn)); |
| 142 | /* LDAPv3 new parent dn feature support */ |
| 143 | if (m_new_superior != null) |
| 144 | seq.addElement(new BERTag(BERTag.CONTEXT|0, |
| 145 | new BEROctetString (m_new_superior), true)); |
| 146 | BERTag element = new BERTag(BERTag.APPLICATION|BERTag.CONSTRUCTED|12, |
| 147 | seq, true); |
| 148 | return element; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Gets the string representation of the request. |
| 153 | * @return string representation |
| 154 | */ |
| 155 | public String toString() { |
| 156 | return "ModifyRDNRequest {entry=" + m_old_dn + ", newrdn=" + |
| 157 | m_new_rdn + ", deleteoldrdn=" + m_delete_old_dn + "}"; |
| 158 | } |
| 159 | } |