Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/client/opers/JDAPSearchResponse.java

raw symbols SCIP
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.LDAPAttribute;
43 import org.ietf.ldap.ber.stream.BERElement;
44 import org.ietf.ldap.ber.stream.BEROctetString;
45 import org.ietf.ldap.ber.stream.BERSequence;
46 import org.ietf.ldap.ber.stream.BERTag;
47
48 /**
49 * This class implements the search response. This object
50 * is sent from the ldap server to the interface.
51 * <pre>
52 * entry [APPLICATION 4] SEQUENCE {
53 * objectName LDAPDN,
54 * attributes SEQUENCE OF SEQUENCE {
55 * AttributeType,
56 * SET OF AttributeValue
57 * }
58 * }
59 * </pre>
60 *
61 * Note that the following is the LDAPv3 definition:
62 * <pre>
63 * SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
64 * objectName LDAPDN,
65 * attributes PartialAttributeList
66 * }
67 * PartialAttributeList ::= SEQUENCE OF SEQUENCE {
68 * type AttributeDescription,
69 * vals SET OF AttributeValue
70 * }
71 * </pre>
72 *
73 * @version 1.0
74 */
75 public class JDAPSearchResponse implements JDAPProtocolOp {
76 /**
77 * Internal variables
78 */
79 protected String m_object_name = null;
80 protected BERElement m_element = null;
81 protected LDAPAttribute m_attributes[] = null;
82
83 /**
84 * Constructs search response.
85 * @param element ber element of search response
86 */
87 public JDAPSearchResponse(BERElement element) throws IOException {
88 m_element = element;
89
90 BERTag tag = (BERTag)element;
91 BERSequence seq = (BERSequence)tag.getValue();
92 BEROctetString name = (BEROctetString)seq.elementAt(0);
93 byte buf[] = null;
94 buf = name.getValue();
95 if (buf == null)
96 m_object_name = null;
97 else {
98 try{
99 m_object_name = new String(buf, "UTF8");
100 } catch(Throwable x)
101 {}
102 }
103 BERSequence attrs = (BERSequence)seq.elementAt(1);
104 if (attrs.size() > 0) {
105 m_attributes = new LDAPAttribute[attrs.size()];
106 for (int i = 0; i < attrs.size(); i++) {
107 m_attributes[i] = new LDAPAttribute(attrs.elementAt(i));
108 }
109 }
110 }
111
112 /**
113 * Retrieves ber representation of the result.
114 * @return ber representation
115 */
116 public BERElement getBERElement() {
117 return m_element;
118 }
119
120 /**
121 * Retrieves object name
122 * @return object name
123 */
124 public String getObjectName() {
125 return m_object_name;
126 }
127
128 /**
129 * Retrieves attributes
130 * @return attributes
131 */
132 public LDAPAttribute[] getAttributes() {
133 return m_attributes;
134 }
135
136 /**
137 * Retrieves the protocol operation type.
138 * @return protocol type
139 */
140 public int getType() {
141 return JDAPProtocolOp.SEARCH_RESPONSE;
142 }
143
144 /**
145 * Retrieve the string representation.
146 * @return string representation
147 */
148 public String toString() {
149 String s = "";
150 if (m_attributes != null) {
151 for (int i = 0; i < m_attributes.length; i++) {
152 if (i != 0)
153 s = s + ",";
154 s = s + m_attributes[i].toString();
155 }
156 }
157 return "SearchResponse {entry='" + m_object_name + "', attributes='" +
158 s + "'}";
159 }
160 }