You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/07/28 13:50:43 UTC
svn commit: r426483 [1/5] - in /directory/trunks/apacheds/server-tools/src:
main/java/org/apache/directory/server/tools/
main/java/org/apache/directory/server/tools/commands/
main/java/org/apache/directory/server/tools/commands/diagnosticcmd/
main/java...
Author: elecharny
Date: Fri Jul 28 04:50:40 2006
New Revision: 426483
URL: http://svn.apache.org/viewvc?rev=426483&view=rev
Log:
applying Pierre-Arnaud Marcelot patch DIRSERVER_679
Added:
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseToolCommand.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommandListener.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/dumpcmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/dumpcmd/DumpCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/dumpcmd/DumpCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/dumpcmd/DumpCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/dumpcmd/DumpCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/exportcmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/importcmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/importcmd/ImportCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/importcmd/ImportCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/importcmd/ImportCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/importcmd/ImportCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/storedprocedurecmd/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/storedprocedurecmd/StoredProcedureCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/storedprocedurecmd/StoredProcedureCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/storedprocedurecmd/StoredProcedureCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/storedprocedurecmd/StoredProcedureExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/execution/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/execution/BaseToolCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/execution/ToolCommandExecutor.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/execution/ToolCommandExecutorSkeleton.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/execution/ToolCommandExecutorStub.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/ExceptionListener.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysErrListener.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/listeners/SysOutListener.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/BaseToolCommandGui.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandCL.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/request/ToolCommandGui.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ListenerParameter.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/Parameter.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/util/ToolCommandException.java
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/AbstractTestCase.java
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/exportcmd/ExportCommandTest.java
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/gracefulshutdowncmd/GracefulShutdownCommandTest.java
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/importcmd/
directory/trunks/apacheds/server-tools/src/test/java/org/apache/directory/server/tools/commands/importcmd/ImportCommandTest.java
directory/trunks/apacheds/server-tools/src/test/resources/
directory/trunks/apacheds/server-tools/src/test/resources/org/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/exportcmd/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/exportcmd/10_entries.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/RFC2849Sample1.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/RFC2849Sample2.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/RFC2849Sample3.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/RFC2849Sample3VariousSpacing.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/import_10_entries.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/import_1_entry.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/import_1_entry_on_error.ldif
directory/trunks/apacheds/server-tools/src/test/resources/org/apache/directory/server/tools/commands/importcmd/import_2_entries_error_and_ok.ldif
Modified:
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java
Modified: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java?rev=426483&r1=426482&r2=426483&view=diff
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java (original)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ApachedsTools.java Fri Jul 28 04:50:40 2006
@@ -16,14 +16,17 @@
*/
package org.apache.directory.server.tools;
+
import java.io.IOException;
-import java.net.URL;
import java.util.Properties;
import org.apache.commons.cli.CommandLine;
-import org.apache.directory.server.configuration.ServerStartupConfiguration;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.apache.directory.server.tools.execution.BaseToolCommandExecutor;
+import org.apache.directory.server.tools.listeners.ExceptionListener;
+import org.apache.directory.server.tools.listeners.SysErrListener;
+import org.apache.directory.server.tools.listeners.SysOutListener;
+import org.apache.directory.server.tools.request.BaseToolCommandCL;
+import org.apache.directory.server.tools.util.ListenerParameter;
/**
@@ -34,10 +37,23 @@
*/
public class ApachedsTools
{
- public static void main( String[] args ) throws Exception
+ public static void main( String[] args )
{
- BaseCommand tools = getInstance();
-
+ ToolCommandListener outputListener = new SysOutListener();
+ ToolCommandListener errorListener = new SysErrListener();
+ ToolCommandListener exceptionListener = new ExceptionListener();
+
+ BaseCommand tools = null;
+ try
+ {
+ tools = getInstance();
+ }
+ catch ( Exception e )
+ {
+ System.err.println( "An error has occurred. Apache DS Tools must quit." + "\nError: " + e.getMessage() );
+ System.exit( 1 );
+ }
+
if ( !BaseCommand.hasBannerOption( args ) )
{
tools.printBanner();
@@ -71,7 +87,7 @@
System.exit( 0 );
}
- ToolCommand cmd = ( ToolCommand ) tools.getCommands().get( command );
+ BaseToolCommandCL cmd = ( BaseToolCommandCL ) tools.getCommands().get( command );
if ( cmd == null )
{
System.err.println( "Unknown command: " + args[0] );
@@ -91,29 +107,30 @@
cmd.setDebugEnabled( cmdline.hasOption( 'd' ) );
cmd.setVerboseEnabled( cmdline.hasOption( 'v' ) );
cmd.setVersion( tools.getProductVersion() );
- if ( cmdline.getOptionValue( 'i' ) != null )
- {
- cmd.setLayout( cmdline.getOptionValue( 'i' ) );
- if ( !cmd.isQuietEnabled() )
- {
- System.out.println( "loading settings from: " + cmd.getLayout().getConfigurationFile() );
- }
- ApplicationContext factory = null;
- URL configUrl = cmd.getLayout().getConfigurationFile().toURL();
- factory = new FileSystemXmlApplicationContext( configUrl.toString() );
- cmd.setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );
- }
- else if ( cmdline.hasOption( 'c' ) )
+
+ if ( cmdline.hasOption( 'c' ) && ( cmdline.getOptionValue( 'i' ) == null ) )
{
System.err.println( "forced configuration load (-c) requires the -i option" );
System.exit( 1 );
}
- cmd.execute( cmdline );
+ try
+ {
+ cmd.execute( cmdline, new ListenerParameter[]
+ { new ListenerParameter( BaseToolCommandExecutor.OUTPUTLISTENER_PARAMETER, outputListener ),
+ new ListenerParameter( BaseToolCommandExecutor.ERRORLISTENER_PARAMETER, errorListener ),
+ new ListenerParameter( BaseToolCommandExecutor.EXCEPTIONLISTENER_PARAMETER, exceptionListener ) } );
+ }
+ catch ( Exception e )
+ {
+ System.err.println( "An error has occurred. Apache DS Tools must quit." + "\nError: " + e.getMessage() );
+ System.exit( 1 );
+ }
}
- public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException, ClassNotFoundException
+ public static BaseCommand getInstance() throws InstantiationException, IllegalAccessException,
+ ClassNotFoundException
{
Properties props = new Properties();
try
@@ -131,7 +148,7 @@
String productCommand = props.getProperty( "product.command", "apacheds-tools" );
String productBanner = props.getProperty( "product.banner", BaseCommand.BANNER );
String productClass = props.getProperty( "product.class", "org.apache.directory.server.tools.BaseCommand" );
-
+
BaseCommand baseCommand = ( BaseCommand ) Class.forName( productClass ).newInstance();
baseCommand.setProductBanner( productBanner );
baseCommand.setProductDisplayName( productDisplayName );
Modified: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=426483&r1=426482&r2=426483&view=diff
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java (original)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java Fri Jul 28 04:50:40 2006
@@ -16,6 +16,7 @@
*/
package org.apache.directory.server.tools;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -33,6 +34,15 @@
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.cli.UnrecognizedOptionException;
+import org.apache.directory.server.tools.commands.diagnosticcmd.DiagnosticCommandCL;
+import org.apache.directory.server.tools.commands.disconnectnotificationcmd.DisconnectNotificationCommandCL;
+import org.apache.directory.server.tools.commands.dumpcmd.DumpCommandCL;
+import org.apache.directory.server.tools.commands.exportcmd.ExportCommandCL;
+import org.apache.directory.server.tools.commands.gracefulshutdowncmd.GracefulShutdownCommandCL;
+import org.apache.directory.server.tools.commands.importcmd.ImportCommandCL;
+import org.apache.directory.server.tools.commands.storedprocedurecmd.StoredProcedureCommandCL;
+import org.apache.directory.server.tools.request.BaseToolCommandCL;
+
/**
* The primary command base class.
@@ -58,32 +68,42 @@
private String productBanner;
+
public BaseCommand()
{
init();
}
+
protected void init()
{
- ToolCommand command;
+ BaseToolCommandCL command;
- command = new DiagnosticCommand();
+ command = new DiagnosticCommandCL();
commands.put( command.getName(), command );
commandsOrdered.add( command.getName() );
- command = new DumpCommand();
+ command = new DumpCommandCL();
commands.put( command.getName(), command );
commandsOrdered.add( command.getName() );
- command = new GracefulShutdownCommand();
+ command = new GracefulShutdownCommandCL();
commands.put( command.getName(), command );
commandsOrdered.add( command.getName() );
- command = new ImportCommand();
+ command = new ImportCommandCL();
commands.put( command.getName(), command );
commandsOrdered.add( command.getName() );
- command = new DisconnectNotificationCommand();
+ command = new DisconnectNotificationCommandCL();
+ commands.put( command.getName(), command );
+ commandsOrdered.add( command.getName() );
+
+ command = new ExportCommandCL();
+ commands.put( command.getName(), command );
+ commandsOrdered.add( command.getName() );
+
+ command = new StoredProcedureCommandCL();
commands.put( command.getName(), command );
commandsOrdered.add( command.getName() );
@@ -103,6 +123,7 @@
getGlobal().addOption( op );
}
+
public static boolean hasBannerOption( String[] args )
{
for ( int ii = 0; ii < args.length; ii++ )
@@ -115,6 +136,7 @@
return false;
}
+
public CommandLine getCommandLine( String command, String[] args )
{
Options all = allOptions( command );
@@ -124,30 +146,31 @@
{
cmdline = parser.parse( all, args );
}
- catch (AlreadySelectedException ase)
+ catch ( AlreadySelectedException ase )
{
System.err.println( "Command line parsing failed for " + command + ". Reason: already selected "
- + ase.getMessage() );
+ + ase.getMessage() );
System.exit( 1 );
}
- catch (MissingArgumentException mae)
+ catch ( MissingArgumentException mae )
{
System.err.println( "Command line parsing failed for " + command + ". Reason: missing argument "
- + mae.getMessage() );
+ + mae.getMessage() );
System.exit( 1 );
}
- catch (MissingOptionException moe)
+ catch ( MissingOptionException moe )
{
- System.err.println( "Command line parsing failed for " + command + ". Reason: missing option " + moe.getMessage() );
+ System.err.println( "Command line parsing failed for " + command + ". Reason: missing option "
+ + moe.getMessage() );
System.exit( 1 );
}
- catch (UnrecognizedOptionException uoe)
+ catch ( UnrecognizedOptionException uoe )
{
System.err.println( "Command line parsing failed for " + command + ". Reason: unrecognized option"
- + uoe.getMessage() );
+ + uoe.getMessage() );
System.exit( 1 );
}
- catch (ParseException pe)
+ catch ( ParseException pe )
{
System.err.println( "Command line parsing failed for " + command + ". Reason: " + pe.getClass() );
System.exit( 1 );
@@ -156,6 +179,7 @@
return cmdline;
}
+
public Options allOptions( String command )
{
if ( command.equals( "help" ) )
@@ -164,20 +188,21 @@
}
Options all = new Options();
- ToolCommand cmd = (ToolCommand) getCommands().get( command );
+ BaseToolCommandCL cmd = ( BaseToolCommandCL ) getCommands().get( command );
for ( Iterator ii = getGlobal().getOptions().iterator(); ii.hasNext(); )
{
- all.addOption( (Option) ii.next() );
+ all.addOption( ( Option ) ii.next() );
}
for ( Iterator ii = cmd.getOptions().getOptions().iterator(); ii.hasNext(); )
{
- all.addOption( (Option) ii.next() );
+ all.addOption( ( Option ) ii.next() );
}
return all;
}
+
public static void dumpArgs( String msg, String[] args )
{
if ( args.length == 0 )
@@ -197,6 +222,7 @@
System.out.println( buf );
}
+
public void helpOnCommand( String command )
{
if ( command.equals( "help" ) )
@@ -207,7 +233,7 @@
if ( getCommands().containsKey( command ) )
{
- ToolCommand cmd = (ToolCommand) getCommands().get( command );
+ BaseToolCommandCL cmd = ( BaseToolCommandCL ) getCommands().get( command );
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( getProductCommand() + " " + cmd + " [options]", cmd.getOptions() );
}
@@ -218,11 +244,12 @@
}
}
+
public void printUsage()
{
HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( getProductCommand() + " <command> [options]", "\nGlobal options:", getGlobal(), "\nType \""
- + getProductCommand() + " help <command>\" for help on a command." );
+ formatter.printHelp( getProductCommand() + " <command> [options]", "\nGlobal options:", getGlobal(),
+ "\nType \"" + getProductCommand() + " help <command>\" for help on a command." );
System.out.println( "\nAvailable commands:" );
Iterator it = commandsOrdered.iterator();
@@ -238,81 +265,96 @@
}
static final String BANNER = " _ _ ____ ____ _____ _ \n"
- + " / \\ _ __ __ _ ___| |__ ___| _ \\/ ___| |_ _|__ ___ | |___ \n"
- + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\ | |/ _ \\ / _ \\| / __| \n"
- + " / ___ \\| |_) | (_| | (__| | | | __/ |_| |___) | | | (_) | (_) | \\__ \\ \n"
- + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/ |_|\\___/ \\___/|_|___/ \n"
- + " |_| \n";
+ + " / \\ _ __ __ _ ___| |__ ___| _ \\/ ___| |_ _|__ ___ | |___ \n"
+ + " / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\ | |/ _ \\ / _ \\| / __| \n"
+ + " / ___ \\| |_) | (_| | (__| | | | __/ |_| |___) | | | (_) | (_) | \\__ \\ \n"
+ + " /_/ \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/ |_|\\___/ \\___/|_|___/ \n"
+ + " |_| \n";
+
public void printBanner()
{
System.out.println( getProductBanner() );
}
+
public void setProductCommand( String productCommand )
{
this.productCommand = productCommand;
}
+
public String getProductCommand()
{
return productCommand;
}
+
public void setProductVersion( String productVersion )
{
this.productVersion = productVersion;
}
+
public String getProductVersion()
{
return productVersion;
}
+
public void setProductDisplayName( String productDisplayName )
{
this.productDisplayName = productDisplayName;
}
+
public String getProductDisplayName()
{
return productDisplayName;
}
+
public void setProductUrl( String productUrl )
{
this.productUrl = productUrl;
}
+
public String getProductUrl()
{
return productUrl;
}
+
public void setProductBanner( String productBanner )
{
this.productBanner = productBanner;
}
+
public String getProductBanner()
{
return productBanner;
}
+
public void setCommands( Map commands )
{
this.commands = commands;
}
+
public Map getCommands()
{
return commands;
}
+
public void setGlobal( Options global )
{
this.global = global;
}
+
public Options getGlobal()
{
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseToolCommand.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseToolCommand.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseToolCommand.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseToolCommand.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools;
+
+
+import java.io.Serializable;
+
+
+/**
+ * This abstract class defines a ToolCommand, it must be extended by every type of command
+ */
+public abstract class BaseToolCommand implements ToolCommand
+{
+ private final String name;
+ protected int port;
+ protected String host;
+ protected String password;
+ protected String user;
+ protected String auth;
+ private boolean debugEnabled = false;
+ private boolean verboseEnabled = false;
+ private boolean quietEnabled = false;
+ private String version;
+
+ // The listeners
+ protected ToolCommandListener outputListener;
+ protected ToolCommandListener errorListener;
+ protected ToolCommandListener exceptionListener;
+
+
+ public BaseToolCommand( String name )
+ {
+ this.name = name;
+ }
+
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+
+ public String toString()
+ {
+ return getName();
+ }
+
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+
+ public void setDebugEnabled( boolean debugEnabled )
+ {
+ this.debugEnabled = debugEnabled;
+ }
+
+
+ public boolean isDebugEnabled()
+ {
+ return debugEnabled;
+ }
+
+
+ public void setVerboseEnabled( boolean verboseEnabled )
+ {
+ this.verboseEnabled = verboseEnabled;
+ }
+
+
+ public boolean isVerboseEnabled()
+ {
+ return verboseEnabled;
+ }
+
+
+ public void setQuietEnabled( boolean quietEnabled )
+ {
+ this.quietEnabled = quietEnabled;
+ }
+
+
+ public boolean isQuietEnabled()
+ {
+ return quietEnabled;
+ }
+
+
+ /**
+ * Notifies the Output Listener
+ * @param o
+ */
+ protected void notifyOutputListener( Serializable o )
+ {
+ if ( this.outputListener != null )
+ {
+ this.outputListener.notify( o );
+ }
+ }
+
+
+ /**
+ * Notifies the Error Listener
+ * @param o
+ */
+ protected void notifyErrorListener( Serializable o )
+ {
+ if ( this.errorListener != null )
+ {
+ this.errorListener.notify( o );
+ }
+ }
+
+
+ /**
+ * Notifies the Exception Listener
+ * @param o
+ */
+ protected void notifyExceptionListener( Serializable o )
+ {
+ if ( this.exceptionListener != null )
+ {
+ this.exceptionListener.notify( o );
+ }
+ }
+
+}
Modified: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java?rev=426483&r1=426482&r2=426483&view=diff
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java (original)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommand.java Fri Jul 28 04:50:40 2006
@@ -17,135 +17,15 @@
package org.apache.directory.server.tools;
-import java.io.File;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Options;
-import org.apache.directory.daemon.InstallationLayout;
-import org.apache.directory.server.configuration.ServerStartupConfiguration;
-
-
/**
- * Simple base class for tool commands.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
+ * Interface that must be extended by every type of command.
*/
-public abstract class ToolCommand
+public interface ToolCommand
{
- private final String name;
- private boolean debugEnabled = false;
- private boolean verboseEnabled = false;
- private boolean quietEnabled = false;
- private String version;
- private InstallationLayout layout;
- private ServerStartupConfiguration configuration;
-
-
- protected ToolCommand(String name)
- {
- this.name = name;
- }
-
-
- public abstract void execute( CommandLine cmd ) throws Exception;
-
-
- public abstract Options getOptions();
-
-
- public String getName()
- {
- return this.name;
- }
-
-
- public void setLayout( File installationDirectory )
- {
- this.layout = new InstallationLayout( installationDirectory );
- }
-
-
- public void setLayout( String installationPath )
- {
- this.layout = new InstallationLayout( installationPath );
- }
-
-
- public void setLayout( InstallationLayout layout )
- {
- this.layout = layout;
- }
-
-
- public InstallationLayout getLayout()
- {
- return layout;
- }
-
-
- public void setConfiguration( ServerStartupConfiguration configuration )
- {
- this.configuration = configuration;
- }
-
-
- public ServerStartupConfiguration getConfiguration()
- {
- return configuration;
- }
-
-
- public void setVersion( String version )
- {
- this.version = version;
- }
-
-
- public String getVersion()
- {
- return version;
- }
-
-
- public String toString()
- {
- return getName();
- }
-
-
- public void setDebugEnabled( boolean debugEnabled )
- {
- this.debugEnabled = debugEnabled;
- }
-
-
- public boolean isDebugEnabled()
- {
- return debugEnabled;
- }
-
-
- public void setVerboseEnabled( boolean verboseEnabled )
- {
- this.verboseEnabled = verboseEnabled;
- }
-
-
- public boolean isVerboseEnabled()
- {
- return verboseEnabled;
- }
-
-
- public void setQuietEnabled( boolean quietEnabled )
- {
- this.quietEnabled = quietEnabled;
- }
-
-
- public boolean isQuietEnabled()
- {
- return quietEnabled;
- }
+ // Default values
+ public final static int DEFAULT_PORT = 10389;
+ public final static String DEFAULT_HOST = "localhost";
+ public final static String DEFAULT_PASSWORD = "secret";
+ public final static String DEFAULT_USER = "uid=admin,ou=system";
+ public final static String DEFAULT_AUTH = "simple";
}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommandListener.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommandListener.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommandListener.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ToolCommandListener.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools;
+
+
+import java.io.Serializable;
+
+
+/**
+ * This interface must be implemented by every Command Listener
+ *
+ */
+public interface ToolCommandListener
+{
+ /**
+ * Notifies the listener, passing it a Serializable object
+ * @param o an object
+ */
+ public void notify( Serializable o );
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandCL.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandCL.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandCL.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandCL.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.diagnosticcmd;
+
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.directory.daemon.AvailablePortFinder;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.request.BaseToolCommandCL;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * A command to send an extened request which launches a diagnostic UI
+ * on the server's console. This may not work unless the display is set
+ * and access is granted to the display (via xhost +). This is especially
+ * the case when running the server in daemon mode. Usually when running
+ * the server in debug mode is when you want the diagnostics turned on.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 379013 $
+ */
+public class DiagnosticCommandCL extends BaseToolCommandCL
+{
+
+ public DiagnosticCommandCL()
+ {
+ super( "diagnostic" );
+ }
+
+
+ public void processOptions( CommandLine cmd )
+ {
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "Processing options for launching diagnostic UI ..." );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out and error check the port value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'p' ) ) // - user provided port w/ -p takes precedence
+ {
+ String val = cmd.getOptionValue( 'p' );
+ try
+ {
+ port = Integer.parseInt( val );
+ }
+ catch ( NumberFormatException e )
+ {
+ System.err.println( "port value of '" + val + "' is not a number" );
+ System.exit( 1 );
+ }
+
+ if ( port > AvailablePortFinder.MAX_PORT_NUMBER )
+ {
+ System.err.println( "port value of '" + val + "' is larger than max port number: "
+ + AvailablePortFinder.MAX_PORT_NUMBER );
+ System.exit( 1 );
+ }
+ else if ( port < AvailablePortFinder.MIN_PORT_NUMBER )
+ {
+ System.err.println( "port value of '" + val + "' is smaller than the minimum port number: "
+ + AvailablePortFinder.MIN_PORT_NUMBER );
+ System.exit( 1 );
+ }
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "port overriden by -p option: " + port );
+ }
+
+ parameters.add( new Parameter( DiagnosticCommandExecutor.PORT_PARAMETER, new Integer( port ) ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the host value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'h' ) )
+ {
+ host = cmd.getOptionValue( 'h' );
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "host overriden by -h option: " + host );
+ }
+
+ parameters.add( new Parameter( DiagnosticCommandExecutor.HOST_PARAMETER, host ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the password value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'w' ) )
+ {
+ password = cmd.getOptionValue( 'w' );
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "password overriden by -w option: " + password );
+ }
+
+ parameters.add( new Parameter( DiagnosticCommandExecutor.PASSWORD_PARAMETER, password ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the 'install-path'
+ // and verify if the -i option is present when the -c option is used
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'i' ) )
+ {
+ parameters
+ .add( new Parameter( DiagnosticCommandExecutor.INSTALLPATH_PARAMETER, cmd.getOptionValue( 'i' ) ) );
+ }
+ else if ( cmd.hasOption( 'c' ) )
+ {
+ System.err.println( "forced configuration load (-c) requires the -i option" );
+ System.exit( 1 );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the 'configuration' flag
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'c' ) )
+ {
+ parameters.add( new Parameter( DiagnosticCommandExecutor.CONFIGURATION_PARAMETER, new Boolean( true ) ) );
+ }
+
+ // -------------------------------------------------------------------
+ // Transform other options into params
+ // -------------------------------------------------------------------
+ parameters.add( new Parameter( DiagnosticCommandExecutor.DEBUG_PARAMETER, new Boolean( isDebugEnabled() ) ) );
+ parameters.add( new Parameter( DiagnosticCommandExecutor.QUIET_PARAMETER, new Boolean( isQuietEnabled() ) ) );
+ parameters
+ .add( new Parameter( DiagnosticCommandExecutor.VERBOSE_PARAMETER, new Boolean( isVerboseEnabled() ) ) );
+ }
+
+
+ public Options getOptions()
+ {
+ Options opts = new Options();
+ Option op = new Option( "h", "host", true, "server host: defaults to localhost" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "p", "port", true, "server port: defaults to 10389 or server.xml specified port" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "w", "password", true, "the apacheds administrator's password: defaults to secret" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "i", "install-path", true, "path to apacheds installation directory" );
+ op.setRequired( false );
+ opts.addOption( op );
+ return opts;
+ }
+
+
+ public ToolCommandExecutorStub getStub()
+ {
+ return new DiagnosticCommandExecutorStub();
+ }
+
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutor.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutor.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutor.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutor.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,266 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.diagnosticcmd;
+
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.configuration.ServerStartupConfiguration;
+import org.apache.directory.server.tools.ToolCommandListener;
+import org.apache.directory.server.tools.execution.BaseToolCommandExecutor;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+import org.apache.directory.shared.ldap.message.extended.LaunchDiagnosticUiRequest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+
+/**
+ * This is the Executor Class of the Diagnostic Command.
+ *
+ * The command can be called using the 'execute' method.
+ */
+public class DiagnosticCommandExecutor extends BaseToolCommandExecutor
+{
+ public DiagnosticCommandExecutor()
+ {
+ super( "diagnostic" );
+ }
+
+
+ /**
+ * Executes the command.
+ * <p>
+ * Use the following Parameters and ListenerParameters to call the command.
+ * <p>
+ * Parameters : <ul>
+ * <li>"HOST_PARAMETER" with a value of type 'String', representing server host</li>
+ * <li>"PORT_PARAMETER" with a value of type 'Integer', representing server port</li>
+ * <li>"PASSWORD_PARAMETER" with a value of type 'String', representing server admin password</li>
+ * <li>"DEBUG_PARAMETER" with a value of type 'Boolean', true to enable debug</li>
+ * <li>"QUIET_PARAMETER" with a value of type 'Boolean', true to enable quiet</li>
+ * <li>"VERBOSE_PARAMETER" with a value of type 'Boolean', true to enable verbose</li>
+ * <li>"INSTALLPATH_PARAMETER" with a value of type 'String', representing the path to installation
+ * directory</li>
+ * </ul>
+ * <br />
+ * ListenersParameters : <ul>
+ * <li>"OUTPUTLISTENER_PARAMETER", a listener that will receive all output messages. It returns
+ * messages as a String.</li>
+ * <li>"ERRORLISTENER_PARAMETER", a listener that will receive all error messages. It returns messages
+ * as a String.</li>
+ * <li>"EXCEPTIONLISTENER_PARAMETER", a listener that will receive all exception(s) raised. It returns
+ * Exceptions.</li>
+ * </ul>
+ * <b>Note:</b> "HOST_PARAMETER", "PORT_PARAMETER" and "PASSWORD_PARAMETER" are required.
+ */
+ public void execute( Parameter[] params, ListenerParameter[] listeners )
+ {
+ processParameters( params );
+ processListeners( listeners );
+
+ try
+ {
+ execute();
+ }
+ catch ( Exception e )
+ {
+ notifyExceptionListener( e );
+ }
+ }
+
+
+ private void execute() throws Exception
+ {
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "Parameters for LaunchDiagnosticUI extended request:" );
+ notifyOutputListener( "port = " + port );
+ notifyOutputListener( "host = " + host );
+ notifyOutputListener( "password = " + password );
+ }
+
+ Hashtable env = new Hashtable();
+ env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+ env.put( "java.naming.provider.url", "ldap://" + host + ":" + port );
+ env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+ env.put( "java.naming.security.credentials", password );
+ env.put( "java.naming.security.authentication", "simple" );
+
+ LdapContext ctx = new InitialLdapContext( env, null );
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "Connection to the server established.\n" + "Sending extended request ... " );
+ }
+ ctx.extendedOperation( new LaunchDiagnosticUiRequest( 3 ) );
+ ctx.close();
+ }
+
+
+ private void processParameters( Parameter[] params )
+ {
+ Map parameters = new HashMap();
+ for ( int i = 0; i < params.length; i++ )
+ {
+ Parameter parameter = params[i];
+ parameters.put( parameter.getName(), parameter.getValue() );
+ }
+
+ // Quiet param
+ Boolean quietParam = ( Boolean ) parameters.get( QUIET_PARAMETER );
+ if ( quietParam != null )
+ {
+ setQuietEnabled( quietParam.booleanValue() );
+ }
+
+ // Debug param
+ Boolean debugParam = ( Boolean ) parameters.get( DEBUG_PARAMETER );
+ if ( debugParam != null )
+ {
+ setDebugEnabled( debugParam.booleanValue() );
+ }
+
+ // Verbose param
+ Boolean verboseParam = ( Boolean ) parameters.get( VERBOSE_PARAMETER );
+ if ( verboseParam != null )
+ {
+ setVerboseEnabled( verboseParam.booleanValue() );
+ }
+
+ // Install-path param
+ String installPathParam = ( String ) parameters.get( INSTALLPATH_PARAMETER );
+ if ( installPathParam != null )
+ {
+ try
+ {
+ setLayout( installPathParam );
+ if ( !isQuietEnabled() )
+ {
+ notifyOutputListener( "loading settings from: " + getLayout().getConfigurationFile() );
+ }
+ ApplicationContext factory = null;
+ URL configUrl;
+
+ configUrl = getLayout().getConfigurationFile().toURL();
+ factory = new FileSystemXmlApplicationContext( configUrl.toString() );
+ setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );
+ }
+ catch ( MalformedURLException e )
+ {
+ notifyErrorListener( e.getMessage() );
+ notifyExceptionListener( e );
+ }
+ }
+
+ // Host param
+ String hostParam = ( String ) parameters.get( HOST_PARAMETER );
+ if ( hostParam != null )
+ {
+ host = hostParam;
+ }
+ else
+ {
+ host = DEFAULT_HOST;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "host set to default: " + host );
+ }
+ }
+
+ // Port param
+ Integer portParam = ( Integer ) parameters.get( PORT_PARAMETER );
+ if ( portParam != null )
+ {
+ port = portParam.intValue();
+ }
+ else if ( getConfiguration() != null )
+ {
+ port = getConfiguration().getLdapPort();
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "port overriden by server.xml configuration: " + port );
+ }
+ }
+ else
+ {
+ port = DEFAULT_PORT;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "port set to default: " + port );
+ }
+ }
+
+ // Password param
+ String passwordParam = ( String ) parameters.get( PASSWORD_PARAMETER );
+ if ( passwordParam != null )
+ {
+ password = passwordParam;
+ }
+ else
+ {
+ password = DEFAULT_PASSWORD;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "password set to default: " + password );
+ }
+ }
+ }
+
+
+ private void processListeners( ListenerParameter[] listeners )
+ {
+ Map parameters = new HashMap();
+ for ( int i = 0; i < listeners.length; i++ )
+ {
+ ListenerParameter parameter = listeners[i];
+ parameters.put( parameter.getName(), parameter.getListener() );
+ }
+
+ // OutputListener param
+ ToolCommandListener outputListener = ( ToolCommandListener ) parameters.get( OUTPUTLISTENER_PARAMETER );
+ if ( outputListener != null )
+ {
+ this.outputListener = outputListener;
+ }
+
+ // ErrorListener param
+ ToolCommandListener errorListener = ( ToolCommandListener ) parameters.get( ERRORLISTENER_PARAMETER );
+ if ( errorListener != null )
+ {
+ this.errorListener = errorListener;
+ }
+
+ // ExceptionListener param
+ ToolCommandListener exceptionListener = ( ToolCommandListener ) parameters.get( EXCEPTIONLISTENER_PARAMETER );
+ if ( exceptionListener != null )
+ {
+ this.exceptionListener = exceptionListener;
+ }
+ }
+
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorSkeleton.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorSkeleton.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorSkeleton.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorSkeleton.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.diagnosticcmd;
+
+
+import org.apache.directory.server.tools.execution.BaseToolCommandExecutor;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorSkeleton;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+public class DiagnosticCommandExecutorSkeleton implements ToolCommandExecutorSkeleton
+{
+
+ public void execute( Parameter[] params, ListenerParameter[] listeners )
+ {
+ BaseToolCommandExecutor executor = new DiagnosticCommandExecutor();
+
+ executor.execute( params, listeners );
+ }
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorStub.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorStub.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorStub.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/diagnosticcmd/DiagnosticCommandExecutorStub.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.diagnosticcmd;
+
+
+import org.apache.directory.server.tools.execution.ToolCommandExecutorSkeleton;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+public class DiagnosticCommandExecutorStub implements ToolCommandExecutorStub
+{
+
+ public void execute( Parameter[] params, ListenerParameter[] listeners ) throws Exception
+ {
+ ToolCommandExecutorSkeleton skelelton = new DiagnosticCommandExecutorSkeleton();
+
+ skelelton.execute( params, listeners );
+ }
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandCL.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandCL.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandCL.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandCL.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.disconnectnotificationcmd;
+
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.directory.daemon.AvailablePortFinder;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.request.BaseToolCommandCL;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+/**
+ * Responds to unsolicited notifications by launching an external process. Also
+ * reconnects to the server an launches another process to notify that the server
+ * is back up.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 379013 $
+ */
+public class DisconnectNotificationCommandCL extends BaseToolCommandCL
+{
+ private String bindDN = "uid=admin,ou=system";
+
+
+ public DisconnectNotificationCommandCL()
+ {
+ super( "notifications" );
+ }
+
+
+ public void processOptions( CommandLine cmd )
+ {
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "Processing options for launching diagnostic UI ..." );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out and error check the port value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'p' ) ) // - user provided port w/ -p takes precedence
+ {
+ String val = cmd.getOptionValue( 'p' );
+ try
+ {
+ port = Integer.parseInt( val );
+ }
+ catch ( NumberFormatException e )
+ {
+ System.err.println( "port value of '" + val + "' is not a number" );
+ System.exit( 1 );
+ }
+
+ if ( port > AvailablePortFinder.MAX_PORT_NUMBER )
+ {
+ System.err.println( "port value of '" + val + "' is larger than max port number: "
+ + AvailablePortFinder.MAX_PORT_NUMBER );
+ System.exit( 1 );
+ }
+ else if ( port < AvailablePortFinder.MIN_PORT_NUMBER )
+ {
+ System.err.println( "port value of '" + val + "' is smaller than the minimum port number: "
+ + AvailablePortFinder.MIN_PORT_NUMBER );
+ System.exit( 1 );
+ }
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "port overriden by -p option: " + port );
+ }
+
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.PORT_PARAMETER, new Integer( port ) ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the host value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'h' ) )
+ {
+ host = cmd.getOptionValue( 'h' );
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "host overriden by -h option: " + host );
+ }
+
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.HOST_PARAMETER, host ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the password value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'w' ) )
+ {
+ password = cmd.getOptionValue( 'w' );
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "password overriden by -w option: " + password );
+ }
+
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.PASSWORD_PARAMETER, password ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the binddn value
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'u' ) )
+ {
+ bindDN = cmd.getOptionValue( 'u' );
+
+ if ( isDebugEnabled() )
+ {
+ System.out.println( "binddn overriden by -u option: " + bindDN );
+ }
+
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.BINDDN_PARAMETER, bindDN ) );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the 'install-path'
+ // and verify if the -i option is present when the -c option is used
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'i' ) )
+ {
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.INSTALLPATH_PARAMETER, cmd
+ .getOptionValue( 'i' ) ) );
+ }
+ else if ( cmd.hasOption( 'c' ) )
+ {
+ System.err.println( "forced configuration load (-c) requires the -i option" );
+ System.exit( 1 );
+ }
+
+ // -------------------------------------------------------------------
+ // figure out the 'configuration' flag
+ // -------------------------------------------------------------------
+ if ( cmd.hasOption( 'c' ) )
+ {
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.CONFIGURATION_PARAMETER, new Boolean(
+ true ) ) );
+ }
+
+ // -------------------------------------------------------------------
+ // Transform other options into params
+ // -------------------------------------------------------------------
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.DEBUG_PARAMETER, new Boolean(
+ isDebugEnabled() ) ) );
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.QUIET_PARAMETER, new Boolean(
+ isQuietEnabled() ) ) );
+ parameters.add( new Parameter( DisconnectNotificationCommandExecutor.VERBOSE_PARAMETER, new Boolean(
+ isVerboseEnabled() ) ) );
+ }
+
+
+ public Options getOptions()
+ {
+ Options opts = new Options();
+ Option op = new Option( "h", "host", true, "server host: defaults to localhost" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "p", "port", true, "server port: defaults to 10389 or server.xml specified port" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "w", "password", true, "the apacheds administrator's password: defaults to secret" );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "u", "binddn", true, "an apacheds user's dn: defaults to " + bindDN );
+ op.setRequired( false );
+ opts.addOption( op );
+ op = new Option( "i", "install-path", true, "path to apacheds installation directory" );
+ op.setRequired( false );
+ opts.addOption( op );
+ return opts;
+ }
+
+
+ public ToolCommandExecutorStub getStub()
+ {
+ return new DisconnectNotificationCommandExecutorStub();
+ }
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutor.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutor.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutor.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutor.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,383 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.disconnectnotificationcmd;
+
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.UnsolicitedNotification;
+import javax.naming.ldap.UnsolicitedNotificationEvent;
+import javax.naming.ldap.UnsolicitedNotificationListener;
+
+import org.apache.directory.server.configuration.ServerStartupConfiguration;
+import org.apache.directory.server.tools.ToolCommandListener;
+import org.apache.directory.server.tools.execution.BaseToolCommandExecutor;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+import org.apache.directory.shared.ldap.message.extended.GracefulDisconnect;
+import org.apache.directory.shared.ldap.message.extended.NoticeOfDisconnect;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+
+/**
+ * This is the Executor Class of the Disconnect Notification Command.
+ *
+ * The command can be called using the 'execute' method.
+ */
+public class DisconnectNotificationCommandExecutor extends BaseToolCommandExecutor implements
+ UnsolicitedNotificationListener
+{
+ // Additional Parameter
+ public static final String BINDDN_PARAMETER = "bindDN";
+
+ private String bindDN;
+ public final static String DEFAULT_BINDDN = "uid=admin,ou=system";
+ UnsolicitedNotification notification;
+ boolean canceled = false;
+
+
+ public DisconnectNotificationCommandExecutor()
+ {
+ super( "notifications" );
+ }
+
+
+ /**
+ * Executes the command.
+ * <p>
+ * Use the following Parameters and ListenerParameters to call the command.
+ * <p>
+ * Parameters : <ul>
+ * <li>"HOST_PARAMETER" with a value of type 'String', representing server host</li>
+ * <li>"PORT_PARAMETER" with a value of type 'Integer', representing server port</li>
+ * <li>"BINDDN_PARAMETER" with a value of type 'String', representing an apacheds user's dn</li>
+ * <li>"PASSWORD_PARAMETER" with a value of type 'String', representing user password</li>
+ * <li>"DEBUG_PARAMETER" with a value of type 'Boolean', true to enable debug</li>
+ * <li>"QUIET_PARAMETER" with a value of type 'Boolean', true to enable quiet</li>
+ * <li>"VERBOSE_PARAMETER" with a value of type 'Boolean', true to enable verbose</li>
+ * <li>"INSTALLPATH_PARAMETER" with a value of type 'String', representing the path to installation
+ * directory</li>
+ * <li>"CONFIGURATION_PARAMETER" with a value of type "Boolean"</li>
+ * </ul>
+ * <br />
+ * ListenersParameters : <ul>
+ * <li>"OUTPUTLISTENER_PARAMETER", a listener that will receive all output messages. It returns
+ * messages as a String.</li>
+ * <li>"ERRORLISTENER_PARAMETER", a listener that will receive all error messages. It returns messages
+ * as a String.</li>
+ * <li>"EXCEPTIONLISTENER_PARAMETER", a listener that will receive all exception(s) raised. It returns
+ * Exceptions.</li>
+ * </ul>
+ * <b>Note:</b> "HOST_PARAMETER", "PORT_PARAMETER", "BINDDN_PARAMETER" and "PASSWORD_PARAMETER" are required.
+ */
+ public void execute( Parameter[] params, ListenerParameter[] listeners )
+ {
+ processParameters( params );
+ processListeners( listeners );
+
+ try
+ {
+ execute();
+ }
+ catch ( Exception e )
+ {
+ notifyExceptionListener( e );
+ }
+ }
+
+
+ private void execute() throws Exception
+ {
+ Hashtable env = new Hashtable();
+ env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+ env.put( "java.naming.provider.url", "ldap://" + host + ":" + port );
+ env.put( "java.naming.security.principal", bindDN );
+ env.put( "java.naming.security.credentials", password );
+ env.put( "java.naming.security.authentication", "simple" );
+
+ LdapContext ctx = new InitialLdapContext( env, null );
+ ctx = ctx.newInstance( null );
+ UnsolicitedNotificationListener listener = new DisconnectNotificationCommandExecutor();
+ ( ( EventContext ) ctx ).addNamingListener( "", SearchControls.SUBTREE_SCOPE, listener );
+
+ notifyOutputListener( "Listening for notifications." );
+ notifyOutputListener( "Press any key to terminate." );
+ System.in.read();
+ ctx.close();
+ notifyOutputListener( "Process terminated!!!" );
+ }
+
+
+ private void processParameters( Parameter[] params )
+ {
+ Map parameters = new HashMap();
+ for ( int i = 0; i < params.length; i++ )
+ {
+ Parameter parameter = params[i];
+ parameters.put( parameter.getName(), parameter.getValue() );
+ }
+
+ // Quiet param
+ Boolean quietParam = ( Boolean ) parameters.get( QUIET_PARAMETER );
+ if ( quietParam != null )
+ {
+ setQuietEnabled( quietParam.booleanValue() );
+ }
+
+ // Debug param
+ Boolean debugParam = ( Boolean ) parameters.get( DEBUG_PARAMETER );
+ if ( debugParam != null )
+ {
+ setDebugEnabled( debugParam.booleanValue() );
+ }
+
+ // Verbose param
+ Boolean verboseParam = ( Boolean ) parameters.get( VERBOSE_PARAMETER );
+ if ( verboseParam != null )
+ {
+ setVerboseEnabled( verboseParam.booleanValue() );
+ }
+
+ // Install-path param
+ String installPathParam = ( String ) parameters.get( INSTALLPATH_PARAMETER );
+ if ( installPathParam != null )
+ {
+ try
+ {
+ setLayout( installPathParam );
+ if ( !isQuietEnabled() )
+ {
+ notifyOutputListener( "loading settings from: " + getLayout().getConfigurationFile() );
+ }
+ ApplicationContext factory = null;
+ URL configUrl;
+
+ configUrl = getLayout().getConfigurationFile().toURL();
+ factory = new FileSystemXmlApplicationContext( configUrl.toString() );
+ setConfiguration( ( ServerStartupConfiguration ) factory.getBean( "configuration" ) );
+ }
+ catch ( MalformedURLException e )
+ {
+ notifyErrorListener( e.getMessage() );
+ notifyExceptionListener( e );
+ }
+ }
+
+ // Host param
+ String hostParam = ( String ) parameters.get( HOST_PARAMETER );
+ if ( hostParam != null )
+ {
+ host = hostParam;
+ }
+ else
+ {
+ host = DEFAULT_HOST;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "host set to default: " + host );
+ }
+ }
+
+ // Port param
+ Integer portParam = ( Integer ) parameters.get( PORT_PARAMETER );
+ if ( portParam != null )
+ {
+ port = portParam.intValue();
+ }
+ else if ( getConfiguration() != null )
+ {
+ port = getConfiguration().getLdapPort();
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "port overriden by server.xml configuration: " + port );
+ }
+ }
+ else
+ {
+ port = DEFAULT_PORT;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "port set to default: " + port );
+ }
+ }
+
+ // Password param
+ String passwordParam = ( String ) parameters.get( PASSWORD_PARAMETER );
+ if ( passwordParam != null )
+ {
+ password = passwordParam;
+ }
+ else
+ {
+ password = DEFAULT_PASSWORD;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "password set to default: " + password );
+ }
+ }
+
+ // BindDn param
+ String bindDNParam = ( String ) parameters.get( BINDDN_PARAMETER );
+ if ( bindDNParam != null )
+ {
+ bindDN = bindDNParam;
+ }
+ else
+ {
+ bindDN = DEFAULT_BINDDN;
+
+ if ( isDebugEnabled() )
+ {
+ notifyOutputListener( "binddn set to default: " + bindDN );
+ }
+ }
+ }
+
+
+ private void processListeners( ListenerParameter[] listeners )
+ {
+ Map parameters = new HashMap();
+ for ( int i = 0; i < listeners.length; i++ )
+ {
+ ListenerParameter parameter = listeners[i];
+ parameters.put( parameter.getName(), parameter.getListener() );
+ }
+
+ // OutputListener param
+ ToolCommandListener outputListener = ( ToolCommandListener ) parameters.get( OUTPUTLISTENER_PARAMETER );
+ if ( outputListener != null )
+ {
+ this.outputListener = outputListener;
+ }
+
+ // ErrorListener param
+ ToolCommandListener errorListener = ( ToolCommandListener ) parameters.get( ERRORLISTENER_PARAMETER );
+ if ( errorListener != null )
+ {
+ this.errorListener = errorListener;
+ }
+
+ // ExceptionListener param
+ ToolCommandListener exceptionListener = ( ToolCommandListener ) parameters.get( EXCEPTIONLISTENER_PARAMETER );
+ if ( exceptionListener != null )
+ {
+ this.exceptionListener = exceptionListener;
+ }
+ }
+
+
+ public void notificationReceived( UnsolicitedNotificationEvent evt )
+ {
+ notification = evt.getNotification();
+
+ if ( notification.getID().equals( NoticeOfDisconnect.EXTENSION_OID ) )
+ {
+ notifyOutputListener( "\nRecieved NoticeOfDisconnect: " + NoticeOfDisconnect.EXTENSION_OID );
+ notifyOutputListener( "Expect to loose this connection without further information." );
+ canceled = true;
+ }
+ else if ( notification.getID().equals( GracefulDisconnect.EXTENSION_OID ) )
+ {
+ notifyOutputListener( "Recieved GracefulDisconnect: " + GracefulDisconnect.EXTENSION_OID );
+ GracefulDisconnect gd = null;
+ try {
+ gd = new GracefulDisconnect( notification.getEncodedValue() );
+ } catch (NamingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ notifyOutputListener( "LDAP server will shutdown in " + gd.getDelay() + " seconds." );
+ notifyOutputListener( "LDAP server will be back online in " + gd.getTimeOffline() + " minutes." );
+
+ if ( gd.getDelay() > 0 )
+ {
+ Thread t = new Thread( new Counter( gd.getDelay() ) );
+ t.start();
+ }
+ }
+ else
+ {
+ notifyOutputListener( "Unknown event recieved with OID: " + evt.getNotification().getID() );
+ }
+ }
+
+
+ public void namingExceptionThrown( NamingExceptionEvent evt )
+ {
+ canceled = true;
+ notifyOutputListener( "Got an excption event: " + evt.getException().getMessage() );
+ notifyOutputListener( "Process shutting down abruptly." );
+ notifyExceptionListener( evt );
+ }
+
+ class Counter implements Runnable
+ {
+ int delay;
+
+
+ Counter( int delay )
+ {
+ this.delay = delay;
+ }
+
+
+ public void run()
+ {
+ notifyOutputListener( "Starting countdown until server shutdown:" );
+ notifyOutputListener( "[" );
+ long delayMillis = delay * 1000 - 1000; // 1000 is for setup costs
+ long startTime = System.currentTimeMillis();
+ while ( System.currentTimeMillis() - startTime < delayMillis && !canceled )
+ {
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch ( InterruptedException e )
+ {
+ }
+ notifyOutputListener( "." );
+ }
+
+ if ( canceled )
+ {
+ notifyOutputListener( " -- countdown canceled -- " );
+ }
+ else
+ {
+ notifyOutputListener( "]" );
+ notifyOutputListener( "Client shutting down gracefully." );
+ return;
+ }
+ }
+ }
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorSkeleton.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorSkeleton.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorSkeleton.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorSkeleton.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.disconnectnotificationcmd;
+
+
+import org.apache.directory.server.tools.execution.ToolCommandExecutor;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorSkeleton;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+public class DisconnectNotificationCommandExecutorSkeleton implements ToolCommandExecutorSkeleton
+{
+
+ public void execute( Parameter[] params, ListenerParameter[] listeners )
+ {
+ ToolCommandExecutor executor = new DisconnectNotificationCommandExecutor();
+
+ executor.execute( params, listeners );
+ }
+
+}
Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorStub.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorStub.java?rev=426483&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorStub.java (added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/commands/disconnectnotificationcmd/DisconnectNotificationCommandExecutorStub.java Fri Jul 28 04:50:40 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.server.tools.commands.disconnectnotificationcmd;
+
+
+import org.apache.directory.server.tools.execution.ToolCommandExecutorSkeleton;
+import org.apache.directory.server.tools.execution.ToolCommandExecutorStub;
+import org.apache.directory.server.tools.util.ListenerParameter;
+import org.apache.directory.server.tools.util.Parameter;
+
+
+public class DisconnectNotificationCommandExecutorStub implements ToolCommandExecutorStub
+{
+
+ public void execute( Parameter[] params, ListenerParameter[] listeners ) throws Exception
+ {
+ ToolCommandExecutorSkeleton skeleton = new DisconnectNotificationCommandExecutorSkeleton();
+
+ skeleton.execute( params, listeners );
+ }
+
+}