001 /*
002 * Copyright 2009-2014 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2009-2014 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.ldap.sdk.migrate.ldapjdk;
022
023
024
025 import java.io.Serializable;
026
027 import com.unboundid.asn1.ASN1OctetString;
028 import com.unboundid.ldap.sdk.ExtendedRequest;
029 import com.unboundid.util.NotExtensible;
030 import com.unboundid.util.NotMutable;
031 import com.unboundid.util.ThreadSafety;
032 import com.unboundid.util.ThreadSafetyLevel;
033
034
035
036 /**
037 * This class provides a data structure that represents an LDAP extended
038 * request.
039 * <BR><BR>
040 * This class is primarily intended to be used in the process of updating
041 * applications which use the Netscape Directory SDK for Java to switch to or
042 * coexist with the UnboundID LDAP SDK for Java. For applications not written
043 * using the Netscape Directory SDK for Java, the {@link ExtendedRequest} class
044 * should be used instead.
045 */
046 @NotExtensible()
047 @NotMutable()
048 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
049 public class LDAPExtendedOperation
050 implements Serializable
051 {
052 /**
053 * The serial version UID for this serializable class.
054 */
055 private static final long serialVersionUID = 9207085503424216431L;
056
057
058
059 // The value for this extended operation, if available.
060 private final byte[] value;
061
062 // The OID for this extended operation.
063 private final String oid;
064
065
066
067 /**
068 * Creates a new LDAP extended operation with the provided OID and value.
069 *
070 * @param id The OID for this extended request.
071 * @param vals The encoded value for this extended request, or {@code null}
072 * if there is none.
073 */
074 public LDAPExtendedOperation(final String id, final byte[] vals)
075 {
076 oid = id;
077 value = vals;
078 }
079
080
081
082 /**
083 * Creates a new LDAP extended operation from the provided extended request.
084 *
085 * @param extendedRequest The extended request to use to create this LDAP
086 * extended operation.
087 */
088 public LDAPExtendedOperation(final ExtendedRequest extendedRequest)
089 {
090 oid = extendedRequest.getOID();
091
092 final ASN1OctetString v = extendedRequest.getValue();
093 if (v == null)
094 {
095 value = null;
096 }
097 else
098 {
099 value = v.getValue();
100 }
101 }
102
103
104
105 /**
106 * Retrieves the OID for this LDAP extended operation.
107 *
108 * @return The OID for this LDaP extended operation.
109 */
110 public String getID()
111 {
112 return oid;
113 }
114
115
116
117 /**
118 * Retrieves the encoded value for this LDAP extended operation, if
119 * available.
120 *
121 * @return The encoded value for this LDAP extended operation, or
122 * {@code null} if there is none.
123 */
124 public byte[] getValue()
125 {
126 return value;
127 }
128
129
130
131 /**
132 * Converts this LDAP extended operation to an {@link ExtendedRequest}.
133 *
134 * @return The {@code ExtendedRequest} object that is the equivalent of this
135 * LDAP extended response.
136 */
137 public final ExtendedRequest toExtendedRequest()
138 {
139 if (value == null)
140 {
141 return new ExtendedRequest(oid);
142 }
143 else
144 {
145 return new ExtendedRequest(oid, new ASN1OctetString(value));
146 }
147 }
148
149
150
151 /**
152 * Retrieves a string representation of this extended operation.
153 *
154 * @return A string representation of this extended operation.
155 */
156 @Override()
157 public String toString()
158 {
159 final StringBuilder buffer = new StringBuilder();
160
161 buffer.append("LDAPExtendedOperation(id=");
162 buffer.append(oid);
163
164 if (value != null)
165 {
166 buffer.append(", value=byte[");
167 buffer.append(value.length);
168 buffer.append(']');
169 }
170
171 buffer.append(')');
172
173 return buffer.toString();
174 }
175 }