001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.jndi.provider.ldap;
019:
020: import javax.naming.NamingException;
021: import javax.naming.ldap.ExtendedRequest;
022: import javax.naming.ldap.ExtendedResponse;
023:
024: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
025: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
026: import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
027: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
028:
029: public class ExtendedOp implements LdapOperation, ASN1Encodable,
030: ASN1Decodable {
031:
032: private ExtendedRequest request;
033:
034: private ExtendedResponse response;
035:
036: private LdapResult result;
037:
038: private Object[] responseValues;
039:
040: public ExtendedOp(ExtendedRequest request) {
041: this .request = request;
042: }
043:
044: public ASN1Encodable getRequest() {
045: return this ;
046: }
047:
048: public int getRequestId() {
049: return LdapASN1Constant.OP_EXTENDED_REQUEST;
050: }
051:
052: public ASN1Decodable getResponse() {
053: return this ;
054: }
055:
056: public int getResponseId() {
057: return LdapASN1Constant.OP_EXTENDED_RESPONSE;
058: }
059:
060: public ExtendedRequest getExtendedRequest() {
061: return request;
062: }
063:
064: public ExtendedResponse getExtendedResponse() {
065:
066: if (result != null && result.getResultCode() == 0
067: && responseValues != null) {
068: String id = null;
069: if (responseValues[4] != null) {
070: id = Utils.getString((byte[]) responseValues[4]);
071: }
072: byte[] value = (byte[]) responseValues[5];
073: int length = 0;
074: if (value != null) {
075: length = value.length;
076: }
077:
078: try {
079: response = request.createExtendedResponse(id, value, 0,
080: length);
081: } catch (NamingException e) {
082: // FIXME: how to deal with this exception
083: e.printStackTrace();
084: }
085: }
086: return response;
087: }
088:
089: public LdapResult getResult() {
090: return result;
091: }
092:
093: public void encodeValues(Object[] values) {
094: values[0] = Utils.getBytes(request.getID());
095: values[1] = request.getEncodedValue();
096: }
097:
098: public void decodeValues(Object[] values) {
099: result = new LdapResult();
100: result.decodeValues(values);
101: this.responseValues = values;
102: }
103: }
|