001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.message;
021
022
023 import org.apache.directory.shared.ldap.entry.Entry;
024 import org.apache.directory.shared.ldap.message.internal.InternalAbstractResponse;
025 import org.apache.directory.shared.ldap.message.internal.InternalSearchResponseEntry;
026 import org.apache.directory.shared.ldap.name.DN;
027
028
029 /**
030 * Lockable SearchResponseEntry implementation
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 * @version $Rev: 918756 $
034 */
035 public class SearchResponseEntryImpl extends InternalAbstractResponse implements InternalSearchResponseEntry
036 {
037 static final long serialVersionUID = -8357316233060886637L;
038
039 /** Entry returned in response to search */
040 private Entry entry;
041
042
043 // ------------------------------------------------------------------------
044 // Constructors
045 // ------------------------------------------------------------------------
046
047 /**
048 * Creates a SearchResponseEntry as a reply to an SearchRequest to
049 * indicate the end of a search operation.
050 *
051 * @param id the session unique message id
052 */
053 public SearchResponseEntryImpl( final int id )
054 {
055 super( id, TYPE );
056 }
057
058
059 // ------------------------------------------------------------------------
060 // SearchResponseEntry Interface Method Implementations
061 // ------------------------------------------------------------------------
062
063 /**
064 * Gets the entry
065 *
066 * @return the entry
067 */
068 public Entry getEntry()
069 {
070 return entry;
071 }
072
073
074 /**
075 * Sets the entry.
076 *
077 * @param entry the entry
078 */
079 public void setEntry( Entry entry )
080 {
081 this.entry = entry;
082 }
083
084
085 /**
086 * Gets the distinguished name of the entry object returned.
087 *
088 * @return the Dn of the entry returned.
089 */
090 public DN getObjectName()
091 {
092 return ( entry == null ? null : entry.getDn() );
093 }
094
095
096 /**
097 * Sets the distinguished name of the entry object returned.
098 *
099 * @param objectName
100 * the Dn of the entry returned.
101 */
102 public void setObjectName( DN objectName )
103 {
104 if ( entry != null )
105 {
106 entry.setDn( objectName );
107 }
108 }
109
110
111 /**
112 * Checks for equality by comparing the objectName, and attributes
113 * properties of this Message after delegating to the super.equals() method.
114 *
115 * @param obj
116 * the object to test for equality with this message
117 * @return true if the obj is equal false otherwise
118 */
119 public boolean equals( Object obj )
120 {
121 if ( this == obj )
122 {
123 return true;
124 }
125
126 if ( !super.equals( obj ) )
127 {
128 return false;
129 }
130
131 if ( !( obj instanceof InternalSearchResponseEntry ) )
132 {
133 return false;
134 }
135
136 InternalSearchResponseEntry resp = ( InternalSearchResponseEntry ) obj;
137
138 return entry.equals( resp.getEntry() );
139 }
140
141
142 /**
143 * Return a string representation of a SearchResultEntry request
144 */
145 public String toString()
146 {
147 StringBuilder sb = new StringBuilder();
148
149 sb.append( " Search Result Entry\n" );
150
151 if ( entry != null )
152 {
153 sb.append( entry );
154 }
155 else
156 {
157 sb.append( " No entry\n" );
158 }
159
160 return sb.toString();
161 }
162 }