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    /**
024     * Implementation of an AbandonRequest.
025     * 
026     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027     * @version $Rev: 764131 $
028     */
029    public class AbandonRequestImpl extends InternalAbstractRequest implements InternalAbandonRequest
030    {
031        static final long serialVersionUID = -4688193359792740969L;
032    
033        /** Sequence identifier of the outstanding request message to abandon */
034        private int abandonId;
035    
036    
037        /**
038         * Creates an AbandonRequest implementation for an outstanding request.
039         * 
040         * @param id
041         *            the sequence identifier of the AbandonRequest message.
042         */
043        public AbandonRequestImpl(final int id)
044        {
045            super( id, TYPE, false );
046        }
047    
048    
049        /**
050         * Gets the id of the request operation to terminate.
051         * 
052         * @return the id of the request message to abandon
053         */
054        public int getAbandoned()
055        {
056            return abandonId;
057        }
058    
059    
060        /**
061         * Sets the id of the request operation to terminate.
062         * 
063         * @param abandonId
064         *            the sequence id of the request message to abandon
065         */
066        public void setAbandoned( int abandonId )
067        {
068            this.abandonId = abandonId;
069        }
070    
071    
072        /**
073         * Checks for equality first by asking the super method which should compare
074         * all but the Abandoned request's Id. It then compares this to determine
075         * equality.
076         * 
077         * @param obj
078         *            the object to test for equality to this AbandonRequest
079         * @return true if the obj equals this request false otherwise
080         */
081        public boolean equals( Object obj )
082        {
083            if ( this == obj )
084            {
085                return true;
086            }
087    
088            if ( ( obj == null ) || !( obj instanceof InternalAbandonRequest ) )
089            {
090                return false;
091            }
092            
093            if ( !super.equals( obj ) )
094            {
095                return false;
096            }
097    
098            InternalAbandonRequest req = ( InternalAbandonRequest ) obj;
099            
100            if ( req.getAbandoned() != abandonId )
101            {
102                return false;
103            }
104    
105            return true;
106        }
107    
108        
109        /**
110         * @see Object#hashCode()
111         * @return the instance's hash code 
112         */
113        public int hashCode()
114        {
115            int hash = 37;
116            hash = hash*17 + abandonId;
117            hash = hash*17 + super.hashCode();
118            
119            return hash;
120        }
121    
122        
123        /**
124         * RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations
125         * cannot be abandoned.
126         */
127        public void abandon()
128        {
129            throw new UnsupportedOperationException(
130                "RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations cannot be abandoned. " );
131        }
132    }