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 javax.naming.directory;
019:
020: import javax.naming.Binding;
021:
022: import org.apache.harmony.jndi.internal.nls.Messages;
023:
024: /**
025: * <code>SearchResult</code> returned from a search on a directory context and
026: * is provided by a <code>NamingEnumeration</code>.
027: * <p>
028: * This class is not thread-safe.
029: * </p>
030: */
031: public class SearchResult extends Binding {
032:
033: /*
034: * This constant is used during deserialization to check the version which
035: * created the serialized object.
036: */
037: private static final long serialVersionUID = 0x80e805ecc9ed1c5cL;
038:
039: /**
040: * The attributes that were matched for this object.
041: *
042: * @serial
043: */
044: private Attributes attrs;
045:
046: /**
047: * Creates a new instance of <code>SearchResult</code> with name
048: * <code>s</code>, bound object <code>o</code> and an
049: * <code>attributes</code>
050: *
051: * @param s
052: * the name of this result. <code>s</code> should be relative
053: * to the target context for the search that produces this
054: * result.
055: * @param o
056: * bound object of this result. The class of <code>o</code> is
057: * the value that will be returned by
058: * <code>Binding.getClassName()</code> for this search result,
059: * except where <code>setClassName()</code> is used to set a
060: * different value. If <code>o</code> is null,
061: * <code>getClassName()</code> will return null.
062: * @param attributes
063: * The <code>attributes</code> should not be null. If there are
064: * no attributes for this search result, this parameter should be
065: * an empty collection.
066: */
067: public SearchResult(String s, Object o, Attributes attributes) {
068: this (s, null, o, attributes, true);
069: }
070:
071: /**
072: * Creates a new instance of <code>SearchResult</code> with name
073: * <code>s</code>, bound object <code>o</code>, an
074: * <code>attributes</code> and a boolean <code>flag</code>
075: *
076: * @param s
077: * the name of this result. A true value of <code>flag</code>
078: * means <code>s</code> is relative to the target context of
079: * the search that produces this result. A false value of
080: * <code>flag</code> means that <code>s</code> is a URL
081: * string.
082: * @param o
083: * bound object of this result. The class of <code>o</code> is
084: * the value that will be returned by
085: * <code>Binding.getClassName()</code> for this search result,
086: * except where <code>setClassName()</code> is used to set a
087: * different value. If <code>o</code> is null,
088: * <code>getClassName()</code> will return null.
089: * @param attributes
090: * The <code>attributes</code> should not be null. If there are
091: * no attributes for this search result, this parameter should be
092: * an empty collection.
093: * @param flag
094: * A true value of <code>flag</code> means <code>s</code> is
095: * relative to the target context of the search that produces
096: * this result. A false value of <code>flag</code> means that
097: * <code>s</code> is a URL string.
098: *
099: */
100: public SearchResult(String s, Object o, Attributes attributes,
101: boolean flag) {
102: this (s, null, o, attributes, flag);
103: }
104:
105: /**
106: * Creates a new instance of <code>SearchResult</code> with name
107: * <code>s</code>, class name <code>s1</code> bound object
108: * <code>o</code> and an <code>attributes</code>
109: *
110: * @param s
111: * the name of this result. <code>s</code> should be relative
112: * to the target context for the search that produces this
113: * result.
114: * @param s1
115: * If <code>s1</code> is not null, it specifies the name of the
116: * class of the bound object <code>o</code>. Passing a null
117: * value for <code>s1</code> will not stop
118: * <code>Binding.getClassName()</code> returning the name of
119: * the class of <code>o</code>.
120: * @param o
121: * bound object of this result. The class of <code>o</code> is
122: * the value that will be returned by
123: * <code>Binding.getClassName()</code> for this search result,
124: * except where <code>setClassName()</code> is used to set a
125: * different value. If <code>o</code> is null,
126: * <code>getClassName()</code> will return null.
127: * @param attributes
128: * The <code>attributes</code> should not be null. If there are
129: * no attributes for this search result, this parameter should be
130: * an empty collection.
131: */
132: public SearchResult(String s, String s1, Object o,
133: Attributes attributes) {
134: this (s, s1, o, attributes, true);
135: }
136:
137: /**
138: * Creates a new instance of <code>SearchResult</code> with name
139: * <code>s</code>, class name <code>s1</code> bound object
140: * <code>o</code> , an <code>attributes</code> and a boolean
141: * <code>flag</code>
142: *
143: * @param s
144: * the name of this result. A true value of <code>flag</code>
145: * means <code>s</code> is relative to the target context of
146: * the search that produces this result. A false value of
147: * <code>flag</code> means that <code>s</code> is a URL
148: * string.
149: * @param s1
150: * If <code>s1</code> is not null, it specifies the name of the
151: * class of the bound object <code>o</code>. Passing a null
152: * value for <code>s1</code> will not stop
153: * <code>Binding.getClassName()</code> returning the name of
154: * the class of <code>o</code>.
155: * @param o
156: * bound object of this result. The class of <code>o</code> is
157: * the value that will be returned by
158: * <code>Binding.getClassName()</code> for this search result,
159: * except where <code>setClassName()</code> is used to set a
160: * different value. If <code>o</code> is null,
161: * <code>getClassName()</code> will return null.
162: * @param attributes
163: * The <code>attributes</code> should not be null. If there are
164: * no attributes for this search result, this parameter should be
165: * an empty collection.
166: * @param flag
167: * A true value of <code>flag</code> means <code>s</code> is
168: * relative to the target context of the search that produces
169: * this result. A false value of <code>flag</code> means that
170: * <code>s</code> is a URL string.
171: */
172: public SearchResult(String s, String s1, Object o,
173: Attributes attributes, boolean flag) {
174: super (s, s1, o, flag);
175:
176: if (attributes == null) {
177: // jndi.8B=attrs must not be null
178: throw new IllegalArgumentException(Messages
179: .getString("jndi.8B")); //$NON-NLS-1$
180: }
181: this .attrs = attributes;
182: }
183:
184: /**
185: * Gets attributes of this search result
186: *
187: * @return an attributes. It should not be null.
188: */
189: public Attributes getAttributes() {
190: return attrs;
191: }
192:
193: /**
194: * Sets attributes of this search result
195: *
196: * @param attributes
197: * an attributes. It should not be null.
198: */
199: public void setAttributes(Attributes attributes) {
200: if (attributes == null) {
201: // jndi.8B=attrs must not be null
202: throw new IllegalArgumentException(Messages
203: .getString("jndi.8B")); //$NON-NLS-1$
204: }
205: this .attrs = attributes;
206: }
207:
208: /**
209: * Return a concatenation of the <code>toString()</code> value for the
210: * binding, and the <code>toString()</code> values for the attributes,
211: * joined by colons.
212: *
213: * @return string representation of this search result
214: */
215: @Override
216: public String toString() {
217: return new StringBuffer(super .toString()).append(":") //$NON-NLS-1$
218: .append(attrs.toString()).toString();
219: }
220:
221: }
|