All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.directory.shared.ldap.model.message.ModifyDnRequestImpl Maven / Gradle / Ivy

/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *  
 */
package org.apache.directory.shared.ldap.model.message;


import org.apache.directory.shared.ldap.model.exception.MessageException;
import org.apache.directory.shared.ldap.model.name.Dn;
import org.apache.directory.shared.ldap.model.name.Rdn;


/**
 * ModifyDNRequest implementation.
 * 
 * @author Apache Directory Project
 */
public class ModifyDnRequestImpl extends AbstractAbandonableRequest implements ModifyDnRequest
{
    static final long serialVersionUID = 1233507339633051696L;

    /** PDU's modify Dn candidate entry distinguished name property */
    private Dn name;

    /** PDU's newrdn relative distinguished name property */
    private Rdn newRdn;

    /** PDU's newSuperior distinguished name property */
    private Dn newSuperior;

    /** PDU's deleteOldRdn flag */
    private boolean deleteOldRdn = false;

    /** The associated response */
    private ModifyDnResponse response;


    // -----------------------------------------------------------------------
    // Constructors
    // -----------------------------------------------------------------------
    /**
     * Creates a ModifyDnRequest implementing object used to perform a
     * dn change on an entry potentially resulting in an entry move.
     */
    public ModifyDnRequestImpl()
    {
        super( -1, TYPE );
    }


    // -----------------------------------------------------------------------
    // ModifyDnRequest Interface Method Implementations
    // -----------------------------------------------------------------------

    /**
     * {@inheritDoc}
     */
    public boolean getDeleteOldRdn()
    {
        return deleteOldRdn;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
    {
        this.deleteOldRdn = deleteOldRdn;

        return this;
    }


    /**
     * {@inheritDoc}
     */
    public boolean isMove()
    {
        return newSuperior != null;
    }


    /**
     * {@inheritDoc}
     */
    public Dn getName()
    {
        return name;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest setName( Dn name )
    {
        this.name = name;

        return this;
    }


    /**
     * {@inheritDoc}
     */
    public Rdn getNewRdn()
    {
        return newRdn;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest setNewRdn( Rdn newRdn )
    {
        this.newRdn = newRdn;

        return this;
    }


    /**
     * {@inheritDoc}
     */
    public Dn getNewSuperior()
    {
        return newSuperior;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest setNewSuperior( Dn newSuperior )
    {
        this.newSuperior = newSuperior;

        return this;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest setMessageId( int messageId )
    {
        super.setMessageId( messageId );

        return this;
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest addControl( Control control ) throws MessageException
    {
        return ( ModifyDnRequest ) super.addControl( control );
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest addAllControls( Control[] controls ) throws MessageException
    {
        return ( ModifyDnRequest ) super.addAllControls( controls );
    }


    /**
     * {@inheritDoc}
     */
    public ModifyDnRequest removeControl( Control control ) throws MessageException
    {
        return ( ModifyDnRequest ) super.removeControl( control );
    }


    // ------------------------------------------------------------------------
    // SingleReplyRequest Interface Method Implementations
    // ------------------------------------------------------------------------

    /**
     * Gets the protocol response message type for this request which produces
     * at least one response.
     * 
     * @return the message type of the response.
     */
    public MessageTypeEnum getResponseType()
    {
        return RESP_TYPE;
    }


    /**
     * The result containing response for this request.
     * 
     * @return the result containing response for this request
     */
    public ModifyDnResponse getResultResponse()
    {
        if ( response == null )
        {
            response = new ModifyDnResponseImpl( getMessageId() );
        }

        return response;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode()
    {
        int hash = 37;
        if ( name != null )
        {
            hash = hash * 17 + name.hashCode();
        }
        hash = hash * 17 + ( deleteOldRdn ? 0 : 1 );

        if ( newRdn != null )
        {
            hash = hash * 17 + newRdn.hashCode();
        }
        if ( newSuperior != null )
        {
            hash = hash * 17 + newSuperior.hashCode();
        }
        hash = hash * 17 + super.hashCode();

        return hash;
    }


    /**
     * Checks to see of an object equals this ModifyDnRequest stub. The equality
     * presumes all ModifyDnRequest specific properties are the same.
     * 
     * @param obj the object to compare with this stub
     * @return true if the obj is equal to this stub, false otherwise
     */
    public boolean equals( Object obj )
    {
        if ( obj == this )
        {
            return true;
        }

        if ( !super.equals( obj ) )
        {
            return false;
        }

        ModifyDnRequest req = ( ModifyDnRequest ) obj;

        if ( name != null && req.getName() == null )
        {
            return false;
        }

        if ( name == null && req.getName() != null )
        {
            return false;
        }

        if ( name != null && req.getName() != null && !name.equals( req.getName() ) )
        {
            return false;
        }

        if ( deleteOldRdn != req.getDeleteOldRdn() )
        {
            return false;
        }

        if ( newRdn != null && req.getNewRdn() == null )
        {
            return false;
        }

        if ( newRdn == null && req.getNewRdn() != null )
        {
            return false;
        }

        if ( newRdn != null && req.getNewRdn() != null && !newRdn.equals( req.getNewRdn() ) )
        {
            return false;
        }

        if ( newSuperior != null && req.getNewSuperior() == null )
        {
            return false;
        }

        if ( newSuperior == null && req.getNewSuperior() != null )
        {
            return false;
        }

        return ( ( newSuperior == null ) || ( req.getNewSuperior() == null ) || newSuperior.equals( req
            .getNewSuperior() ) );
    }


    /**
     * Get a String representation of a ModifyDNRequest
     * 
     * @return A ModifyDNRequest String
     */
    public String toString()
    {

        StringBuffer sb = new StringBuffer();

        sb.append( "    ModifyDN Response\n" );
        sb.append( "        Entry : '" ).append( name ).append( "'\n" );
        if ( newRdn != null )
        {
            sb.append( "        New Rdn : '" ).append( newRdn.toString() ).append( "'\n" );
        }
        sb.append( "        Delete old Rdn : " ).append( deleteOldRdn ).append( "\n" );

        if ( newSuperior != null )
        {
            sb.append( "        New superior : '" ).append( newSuperior.toString() ).append( "'\n" );
        }

        // The controls
        sb.append( super.toString() );

        return super.toString( sb.toString() );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy