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 */
020package org.apache.directory.api.ldap.model.message;
021
022
023/**
024 * The base request message class.
025 * 
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 */
028public class AbstractRequest extends AbstractMessage implements Request
029{
030    static final long serialVersionUID = -4511116249089399040L;
031
032    /** Flag indicating whether or not this request returns a response. */
033    private final boolean hasResponse;
034
035
036    /**
037     * Subclasses must provide these parameters via a super constructor call.
038     * 
039     * @param id the sequential message identifier
040     * @param type the request type enum
041     * @param hasResponse flag indicating if this request generates a response
042     */
043    protected AbstractRequest( final int id, final MessageTypeEnum type, boolean hasResponse )
044    {
045        super( id, type );
046
047        this.hasResponse = hasResponse;
048    }
049
050
051    /**
052     * Indicator flag used to determine whether or not this type of request
053     * produces a reply.
054     * 
055     * @return true if any reply is generated, false if no response is generated
056     */
057    @Override
058    public boolean hasResponse()
059    {
060        return hasResponse;
061    }
062
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public boolean equals( Object obj )
069    {
070        if ( obj == this )
071        {
072            return true;
073        }
074
075        if ( ( obj == null ) || !( obj instanceof Request ) )
076        {
077            return false;
078        }
079
080        if ( hasResponse != ( ( Request ) obj ).hasResponse() )
081        {
082            return false;
083        }
084        return super.equals( obj );
085    }
086
087
088    /**
089     * @see Object#hashCode()
090     * @return the instance's hash code 
091     */
092    @Override
093    public int hashCode()
094    {
095        int hash = 37;
096        hash = hash * 17 + ( hasResponse ? 0 : 1 );
097        hash = hash * 17 + super.hashCode();
098
099        return hash;
100    }
101}