Class AbstractCli

  • Direct Known Subclasses:
    AuthenticatorCli, LdapCli

    public abstract class AbstractCli
    extends java.lang.Object
    Abstract base class for all CLI handlers.
    Version:
    $Revision: 1330 $
    Author:
    Middleware Services
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.logging.Log logger
      Log.
      protected static java.lang.String OPT_DSMLV1
      Option for dsmlv1 output.
      protected static java.lang.String OPT_DSMLV2
      Option for dsmlv2 output.
      protected static java.lang.String OPT_HELP
      Option to print usage.
      protected static java.lang.String OPT_TRACE
      Option for ldap trace.
      protected static java.lang.String OPT_USE_PROPERTIES
      Option for loading ldap configuration from properties.
      protected org.apache.commons.cli.Options options
      Command line options.
      protected java.util.List<java.lang.String> opts
      List of command options.
      protected boolean outputDsmlv1
      Whether to output dsml version 1, the default is ldif.
      protected boolean outputDsmlv2
      Whether to output dsml version 2, the default is ldif.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractCli()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void dispatch​(org.apache.commons.cli.CommandLine line)
      Dispatch command line data to the handler that can perform the operation requested on the command line.
      protected java.util.Map<java.lang.String,​java.lang.String> getArgs()
      Returns the command line arguments for this cli.
      protected abstract java.lang.String getCommandName()
      Gets the name of the command for which this class provides a CLI interface.
      protected void initLdapProperties​(PropertyConfig config, org.apache.commons.cli.CommandLine line)
      Initialize the supplied config with command line options.
      protected abstract void initOptions()
      Initialize CLI options.
      protected void initOptions​(LdapConfigPropertyInvoker invoker)
      Initialize CLI options with the supplied invoker.
      void performAction​(java.lang.String[] args)
      Parses command line options and invokes the proper handler to perform the requested action, or the default action if no action is specified.
      protected void printExamples()
      Prints CLI usage examples.
      protected void printHelp()
      Prints CLI help text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OPT_HELP

        protected static final java.lang.String OPT_HELP
        Option to print usage.
        See Also:
        Constant Field Values
      • OPT_TRACE

        protected static final java.lang.String OPT_TRACE
        Option for ldap trace.
        See Also:
        Constant Field Values
      • OPT_USE_PROPERTIES

        protected static final java.lang.String OPT_USE_PROPERTIES
        Option for loading ldap configuration from properties.
        See Also:
        Constant Field Values
      • OPT_DSMLV1

        protected static final java.lang.String OPT_DSMLV1
        Option for dsmlv1 output.
        See Also:
        Constant Field Values
      • OPT_DSMLV2

        protected static final java.lang.String OPT_DSMLV2
        Option for dsmlv2 output.
        See Also:
        Constant Field Values
      • opts

        protected java.util.List<java.lang.String> opts
        List of command options.
      • logger

        protected final org.apache.commons.logging.Log logger
        Log.
      • options

        protected org.apache.commons.cli.Options options
        Command line options.
      • outputDsmlv1

        protected boolean outputDsmlv1
        Whether to output dsml version 1, the default is ldif.
      • outputDsmlv2

        protected boolean outputDsmlv2
        Whether to output dsml version 2, the default is ldif.
    • Constructor Detail

      • AbstractCli

        public AbstractCli()
        Default constructor.
    • Method Detail

      • performAction

        public final void performAction​(java.lang.String[] args)
        Parses command line options and invokes the proper handler to perform the requested action, or the default action if no action is specified.
        Parameters:
        args - Command line arguments.
      • initOptions

        protected abstract void initOptions()
        Initialize CLI options.
      • initOptions

        protected void initOptions​(LdapConfigPropertyInvoker invoker)
        Initialize CLI options with the supplied invoker.
        Parameters:
        invoker - PropertyInvoker
      • getCommandName

        protected abstract java.lang.String getCommandName()
        Gets the name of the command for which this class provides a CLI interface.
        Returns:
        Name of CLI command.
      • dispatch

        protected abstract void dispatch​(org.apache.commons.cli.CommandLine line)
                                  throws java.lang.Exception
        Dispatch command line data to the handler that can perform the operation requested on the command line.
        Parameters:
        line - Parsed command line arguments container.
        Throws:
        java.lang.Exception - On errors thrown by handler.
      • printHelp

        protected void printHelp()
        Prints CLI help text.
      • printExamples

        protected void printExamples()
        Prints CLI usage examples.
      • getArgs

        protected java.util.Map<java.lang.String,​java.lang.String> getArgs()
        Returns the command line arguments for this cli.
        Returns:
        map of arg name to description
      • initLdapProperties

        protected void initLdapProperties​(PropertyConfig config,
                                          org.apache.commons.cli.CommandLine line)
                                   throws java.lang.Exception
        Initialize the supplied config with command line options.
        Parameters:
        config - property config to configure
        line - Parsed command line arguments container.
        Throws:
        java.lang.Exception - On errors thrown by handler.