//Warning: This code has been marked up for HTML

/**************************************************************************
*  Novell Software Developer Kit
*
*  Copyright (C) 2002-2003 Novell, Inc. All Rights Reserved.
*
*  THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
*  USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT
*  ACCOMPANYING THE SOFTWARE DEVELOPER KIT (SDK) THAT CONTAINS THIS WORK.
*  PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A
*  ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
*  PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
*  DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S
*  PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S
*  CUSTOMERS WITH RESPECT TO THIS CODE.
*
* $name:           AbortPartitionOperation.java
* $description:    AbortPartitionOperation.java is used to stop a running
*                  naming context operation invoked by previously submitted
*                  naming context request.
******************************************************************************/
import java.util.Hashtable;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import com.novell.service.ndssdk.jndi.ldap.ext.AbortPartitionOperationRequest;
import com.novell.service.ndssdk.jndi.ldap.ext.ReplicationConstants;


public class AbortPartitionOperation {
    public static void main(String[] args){

        if ( args.length != 4 ) {
            usage();
        }

        String hostURL       = args[0];
        String loginDN       = args[1];
        String passWord      = args[2];
        String partitionDN   = args[3];

        try {
           // Create a Hashtable object.

            Hashtable env = new Hashtable( 5, 0.75f );
            env.put(Context.INITIAL_CONTEXT_FACTORY,
                            "com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.PROVIDER_URL, hostURL);
            env.put(Context.SECURITY_AUTHENTICATION, "simple" );
            env.put(Context.SECURITY_PRINCIPAL, loginDN );
            env.put(Context.SECURITY_CREDENTIALS, passWord );

           // Construct a LdapContext object.

            LdapContext ctx = new InitialLdapContext( env, null );

           // create extended operation request object. the flag used

           // for this request is: LDAP_ENSURE_SERVERS_UP = 1.

            AbortPartitionOperationRequest  reqs =
                        new AbortPartitionOperationRequest( partitionDN,
                            ReplicationConstants.LDAP_ENSURE_SERVERS_UP );
           // call extended operation to abort the currently running

           // partition operation.

            ctx.extendedOperation(reqs);

            System.out.println("AbortPartition operation succeeded.");
        }
        catch ( NamingException e ) {
            System.err.println("AbortPartition operation failed.");
            e.printStackTrace();
        }
        finally {
            System.exit(0);
        }
    }

    public static void usage() {
        System.err.println("\n Usage  : java AbortPartitionOperation "
                        + "<host URL> <login dn> <password>"
                        + "                   <partition dn>\n");
        System.err.println(" Example: java AbortPartitionOperation ldap://Acme"
            + ".com:389 cn=admin,o=Acme\n          secret ou=sales,o=Acme");
        System.exit(1);
    }
}