01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.jndi.provider.ldap.mock;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
24: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
25: import org.apache.harmony.security.asn1.ASN1Integer;
26:
27: public class EncodableLdapResult implements ASN1Encodable {
28:
29: private int resultCode;
30:
31: private String machedDN;
32:
33: private String errorMessage;
34:
35: private String[] referrals;
36:
37: public EncodableLdapResult() {
38: this (0, "", "", null);
39: }
40:
41: public String getErrorMessage() {
42: return errorMessage;
43: }
44:
45: public String getMachedDN() {
46: return machedDN;
47: }
48:
49: public String[] getReferrals() {
50: return referrals;
51: }
52:
53: public int getResultCode() {
54: return resultCode;
55: }
56:
57: public EncodableLdapResult(int resultCode, String machedDN,
58: String errorMessage, String[] referrals) {
59: this .resultCode = resultCode;
60: if (machedDN == null) {
61: this .machedDN = "";
62: } else {
63: this .machedDN = machedDN;
64: }
65: if (errorMessage == null) {
66: this .errorMessage = "";
67: } else {
68: this .errorMessage = errorMessage;
69: }
70: this .referrals = referrals;
71: }
72:
73: public void encodeValues(Object[] values) {
74: values[0] = ASN1Integer.fromIntValue(resultCode);
75: values[1] = Utils.getBytes(machedDN);
76: values[2] = Utils.getBytes(errorMessage);
77: if (referrals != null) {
78: List<byte[]> refs = new ArrayList<byte[]>();
79: for (int i = 0; i < referrals.length; i++) {
80: refs.add(Utils.getBytes(referrals[i]));
81: }
82: values[3] = refs;
83: }
84: }
85:
86: }
|