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