Nirvana Java Client: Deleting a Channel
This example demonstrates how to delete a Nirvana channel programmatically.
Usage
ndelchan <channel name> <Required Arguments> <channel name> - Channel name parameter for the channel to delete Note: -? provides help on environment variables
Application Source Code
See also:
/**
*
* ----------------------------------------------------------------------------------
*
* PCB Systems Limited License Version 1.1
* Copyright PCB Systems Limited. All rights reserved
*
* In the event that you should download or otherwise use this software
* ( the "Software" ) you hereby acknowledge and agree that:
*
* 1. The Software is the property of PCB Systems Limited: Title, Copyright and all
* other proprietary rights, interest and benefit in and to the Software is and
* shall be owned by PCB Systems Limited;
*
* 2. You will not make copies of the Software whatsoever other than, if you should
* so wish, a single copy for archival purposes only;
*
* 3. You will not modify, reverse assemble, decompile, reverse engineer or otherwise
* translate the Software;
*
* 4. You will not redistribute, copy, forward electronically or circulate the Software
* to any person for any purpose whatsoever without the prior written consent of
* PCB Systems Limited;
*
* 5. You will not charge for, market or provide any managed service or product that
* is based upon or includes the Software or any variant of it; and
*
* 6. You will not use the Software for any purpose apart from your own personal,
* noncommercial and lawful use;
*
* You hereby agree that the software is used by you on an "as is" basis, without
* warranty of any kind. PCB Systems Limited hereby expressly disclaim all warranties
* and conditions, either expressed or implied, including but not limited to any
* implied warranties or conditions or merchantability and fitness for a particular
* purpose.
*
* You agree that you are solely responsible for determining the appropriateness of
* using the Software and assume all risks associated with it including but not
* limited to the risks of program errors, damage to or loss of of data, programs or
* equipment and unavailability or interruption of operations.
*
* PCB Systems Limited will not be liable for any direct damages or for any, special,
* incidental or indirect damages or for any economic consequential damages ( including
* lost profits or savings ), or any damage howsoever arising.
*
* ----------------------------------------------------------------------------------
*/
package com.pcbsys.nirvana.apps;
import com.pcbsys.nirvana.client.*;
/**
* Deletes a nirvana channel
*/
public class deleteChannel extends nSampleApp {
private static deleteChannel mySelf=null;
/**
* This method demonstrates the Nirvana API calls necessary to delete
* a channel.
* It is called after all command line arguments have been received and
* validated
*
* @param realmDetails a String[] containing the possible RNAME values
* @param channelName the channel name to delete
*/
private void doit(String[] realmDetails, String channelName ) {
mySelf.constructSession(realmDetails);
//Deletes the specified channel
try{
//Create a channel attributes object
nChannelAttributes nca = new nChannelAttributes();
nca.setName( channelName );
//Delete the channel
mySession.deleteChannel( nca );
System.out.println("Deleting "+channelName);
}
//Handle errors
catch(nChannelNotFoundException cnfe){
try {
nChannelAttributes[] chanAts = mySession.getChannels(channelName);
//If the specified channel is actually a folder, ask if the user wishes to delete all channels in this folder.
if(chanAts.length!=0){
System.out.println(channelName+" is a folder, do you wish to delete all channels within this folder and it's subfolders? y/n");
char c =(char) System.in.read();
if(c=='y'){
for(nChannelAttributes x:chanAts){
System.out.println("Deleting "+x.getName());
mySession.deleteChannel(x);
}
}
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
catch (nSecurityException se) {
System.out.println("Unsufficient permissions for the requested operation.");
System.out.println("Please check the ACL settings on the server.");
se.printStackTrace();
System.exit(1);
}
catch (nSessionNotConnectedException snce) {
System.out.println("The session object used is not physically connected to the Nirvana realm.");
System.out.println("Please ensure the realm is up and check your RNAME value.");
snce.printStackTrace();
System.exit(1);
}
catch (nUnexpectedResponseException ure) {
System.out.println("The Nirvana REALM has returned an unexpected response.");
System.out.println("Please ensure the Nirvana REALM and client API used are compatible.");
ure.printStackTrace();
System.exit(1);
}
catch (nUnknownRemoteRealmException urre) {
System.out.println("The channel specified resided in a remote realm which could not be found.");
System.out.println("Please ensure the channel name specified is correct.");
urre.printStackTrace();
System.exit(1);
}
catch (nRequestTimedOutException rtoe) {
System.out.println("The requested operation has timed out waiting for a response from the REALM.");
System.out.println("If this is a very busy REALM ask your administrator to increase the client timeout values.");
rtoe.printStackTrace();
System.exit(1);
}
catch (nBaseClientException nbce) {
System.out.println("An error occured while creating the Channel Attributes object.");
nbce.printStackTrace();
System.exit(1);
}
//Close the session we opened
try{
nSessionFactory.close ( mySession );
}
catch(Exception ex){}
//Close any other sessions within this JVM so that we can exit
nSessionFactory.shutdown ( );
}
protected void processArgs(String[] args){
switch (args.length){
case 1:
if (args[0].equals("-?")) {
Usage();
UsageEnv();
}
System.getProperties().put("CHANNAME",args[0]);
break;
}
}
public static void main( String[] args ) {
//Create an instance for this class
mySelf = new deleteChannel();
//Process command line arguments
mySelf.processArgs(args);
//Process Environment Variables
nSampleApp.processEnvironmentVariables();
//Check the channel name specified
String channelName=null;
if ( System.getProperty( "CHANNAME" ) != null )
channelName= System.getProperty( "CHANNAME" ) ;
else{
Usage();
System.exit( 1 );
}
//Check the local realm details
String RNAME=null;
if ( System.getProperty( "RNAME" ) != null )
RNAME= System.getProperty( "RNAME" ) ;
else{
Usage();
System.exit( 1 );
}
//Process the local REALM RNAME details
String[] rproperties = new String[4];
rproperties=parseRealmProperties(RNAME);
//delete the channel specified
mySelf.doit(rproperties, channelName);
}
/**
* Prints the usage message for this class
*/
private static void Usage() {
System.out.println( "Usage ...\n" );
System.out.println("ndelchan <channel name> \n");
System.out.println(
"<Required Arguments> \n");
System.out.println(
"<channel name> - Channel name parameter for the channel to delete" );
System.out.println(
"\n\nNote: -? provides help on environment variables \n");
}
} // End of deleteChannel Class
EXAMPLE_SOURCE_END
