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.name.LdapDN;
025    
026    
027    /**
028     * Lockable SearchResponseEntry implementation
029     * 
030     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
031     * @version $Rev: 764131 $
032     */
033    public class SearchResponseEntryImpl extends InternalAbstractResponse implements InternalSearchResponseEntry
034    {
035        static final long serialVersionUID = -8357316233060886637L;
036    
037        /** Entry returned in response to search */
038        private Entry entry;
039    
040    
041        // ------------------------------------------------------------------------
042        // Constructors
043        // ------------------------------------------------------------------------
044    
045        /**
046         * Creates a SearchResponseEntry as a reply to an SearchRequest to
047         * indicate the end of a search operation.
048         * 
049         * @param id the session unique message id
050         */
051        public SearchResponseEntryImpl( final int id )
052        {
053            super( id, TYPE );
054        }
055    
056    
057        // ------------------------------------------------------------------------
058        // SearchResponseEntry Interface Method Implementations
059        // ------------------------------------------------------------------------
060    
061        /**
062         * Gets the entry
063         * 
064         * @return the entry
065         */
066        public Entry getEntry()
067        {
068            return entry;
069        }
070    
071    
072        /**
073         * Sets the entry.
074         * 
075         * @param entry the entry
076         */
077        public void setEntry( Entry entry )
078        {
079            this.entry = entry;
080        }
081    
082    
083        /**
084         * Gets the distinguished name of the entry object returned.
085         * 
086         * @return the Dn of the entry returned.
087         */
088        public LdapDN getObjectName()
089        {
090            return ( entry == null ? null : entry.getDn() );
091        }
092    
093    
094        /**
095         * Sets the distinguished name of the entry object returned.
096         * 
097         * @param objectName
098         *            the Dn of the entry returned.
099         */
100        public void setObjectName( LdapDN objectName )
101        {
102            if ( entry != null )
103            {
104                entry.setDn( objectName );
105            }
106        }
107    
108    
109        /**
110         * Checks for equality by comparing the objectName, and attributes
111         * properties of this Message after delegating to the super.equals() method.
112         * 
113         * @param obj
114         *            the object to test for equality with this message
115         * @return true if the obj is equal false otherwise
116         */
117        public boolean equals( Object obj )
118        {
119            if ( this == obj )
120            {
121                return true;
122            }
123    
124            if ( !super.equals( obj ) )
125            {
126                return false;
127            }
128    
129            if ( !( obj instanceof InternalSearchResponseEntry ) )
130            {
131                return false;
132            }
133            
134            InternalSearchResponseEntry resp = ( InternalSearchResponseEntry ) obj;
135    
136            return entry.equals( resp.getEntry() );
137        }
138    
139    
140        /**
141         * Return a string representation of a SearchResultEntry request
142         */
143        public String toString()
144        {
145            StringBuilder sb = new StringBuilder();
146    
147            sb.append( "    Search Result Entry\n" );
148    
149            if ( entry != null )
150            {
151                sb.append( entry );
152            }
153            else
154            {
155                sb.append( "            No entry\n" );
156            }
157    
158            return sb.toString();
159        }
160    }