| 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 java.io.IOException; |
| 41 | |
| 42 | import org.ietf.ldap.ber.stream.BERElement; |
| 43 | import org.ietf.ldap.ber.stream.BEROctetString; |
| 44 | import org.ietf.ldap.ber.stream.BERSequence; |
| 45 | import org.ietf.ldap.ber.stream.BERTag; |
| 46 | |
| 47 | /** |
| 48 | * This class implements the extended response. This object |
| 49 | * is sent from the ldap server to the interface and is |
| 50 | * a v3 response. |
| 51 | * <P>See RFC 1777. |
| 52 | * |
| 53 | * <pre> |
| 54 | * ExtendedResponse :: [APPLICATION 23] SEQUENCE { |
| 55 | * COMPONENTS OF LDAPResult, |
| 56 | * responseName [10] LDAPOID OPTIONAL, |
| 57 | * response [11] OCTET STRING OPTIONAL |
| 58 | * } |
| 59 | * </pre> |
| 60 | * |
| 61 | * @version 1.0 |
| 62 | */ |
| 63 | public class JDAPExtendedResponse extends JDAPResult |
| 64 | implements JDAPProtocolOp { |
| 65 | |
| 66 | /** |
| 67 | * Internal variables |
| 68 | */ |
| 69 | protected String m_oid = null; |
| 70 | protected byte[] m_value = null; |
| 71 | |
| 72 | /** |
| 73 | * Constructs extended response. |
| 74 | * @param element ber element of add response |
| 75 | */ |
| 76 | public JDAPExtendedResponse(BERElement element) throws IOException { |
| 77 | super(((BERTag)element).getValue()); |
| 78 | BERSequence seq = (BERSequence)((BERTag)element).getValue(); |
| 79 | for (int i = 0; i < seq.size(); i++) { |
| 80 | try { |
| 81 | BERElement el = seq.elementAt(i); |
| 82 | if (el.getType() != BERElement.TAG) |
| 83 | continue; |
| 84 | BERTag t = (BERTag)el; |
| 85 | switch (t.getTag()&0x0f) { |
| 86 | case 10: |
| 87 | BEROctetString oid = (BEROctetString)t.getValue(); |
| 88 | try{ |
| 89 | m_oid = new String(oid.getValue(), "UTF8"); |
| 90 | } catch(Throwable x) |
| 91 | {} |
| 92 | break; |
| 93 | case 11: |
| 94 | BEROctetString value = (BEROctetString)t.getValue(); |
| 95 | m_value = value.getValue(); |
| 96 | break; |
| 97 | } |
| 98 | } catch (ClassCastException e) { |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Retrieves the protocol operation type. |
| 105 | * @return protocol type |
| 106 | */ |
| 107 | public int getType() { |
| 108 | return JDAPProtocolOp.EXTENDED_RESPONSE; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Retrieves the results of the extended operation. |
| 113 | * @return extended operation results as byte array |
| 114 | */ |
| 115 | public byte[] getValue() { |
| 116 | return m_value; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Retrieves the oid of the extended operation. |
| 121 | * @return extended operation oid. |
| 122 | */ |
| 123 | public String getID() { |
| 124 | return m_oid; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Retrieve the string representation. |
| 129 | * @return string representation |
| 130 | */ |
| 131 | public String toString() { |
| 132 | return "ExtendedResponse " + super.getParamString(); |
| 133 | } |
| 134 | } |