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    import org.apache.directory.shared.ldap.message.internal.InternalAbstractResponse;
023    import org.apache.directory.shared.ldap.message.internal.InternalReferral;
024    import org.apache.directory.shared.ldap.message.internal.InternalSearchResponseReference;
025    
026    
027    /**
028     * SearchResponseReference implementation
029     * 
030     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
031     * @version $Revision: 905344 $
032     */
033    public class SearchResponseReferenceImpl extends InternalAbstractResponse implements InternalSearchResponseReference
034    {
035        static final long serialVersionUID = 7423807019951309810L;
036    
037        /** Referral holding the reference urls */
038        private InternalReferral referral;
039    
040    
041        // ------------------------------------------------------------------------
042        // Constructors
043        // ------------------------------------------------------------------------
044    
045        /**
046         * Creates a Lockable SearchResponseReference as a reply to an SearchRequest
047         * to indicate the end of a search operation.
048         * 
049         * @param id
050         *            the session unique message id
051         */
052        public SearchResponseReferenceImpl(final int id)
053        {
054            super( id, TYPE );
055        }
056    
057    
058        // ------------------------------------------------------------------------
059        // SearchResponseReference Interface Method Implementations
060        // ------------------------------------------------------------------------
061    
062        /**
063         * Gets the sequence of LdapUrls as a Referral instance.
064         * 
065         * @return the sequence of LdapUrls
066         */
067        public InternalReferral getReferral()
068        {
069            return this.referral;
070        }
071    
072    
073        /**
074         * Sets the sequence of LdapUrls as a Referral instance.
075         * 
076         * @param referral
077         *            the sequence of LdapUrls
078         */
079        public void setReferral( InternalReferral referral )
080        {
081            this.referral = referral;
082        }
083    
084    
085        /**
086         * Checks to see if an object is equal to this SearchResponseReference stub.
087         * 
088         * @param obj
089         *            the object to compare to this response stub
090         * @return true if the objects are equivalent false otherwise
091         */
092        public boolean equals( Object obj )
093        {
094            if ( obj == this )
095            {
096                return true;
097            }
098    
099            if ( !super.equals( obj ) )
100            {
101                return false;
102            }
103    
104            InternalSearchResponseReference resp = ( InternalSearchResponseReference ) obj;
105    
106            if ( this.referral != null && resp.getReferral() == null )
107            {
108                return false;
109            }
110    
111            if ( this.referral == null && resp.getReferral() != null )
112            {
113                return false;
114            }
115    
116            if ( this.referral != null && resp.getReferral() != null )
117            {
118                if ( !this.referral.equals( resp.getReferral() ) )
119                {
120                    return false;
121                }
122            }
123    
124            return true;
125        }
126    }