Command Pattern implementation for processing command-line arguments passed to a Java Application.

See:
          Description

Packages
com.nevelex.app.args Re-usable Command Pattern implementation for processing command-line arguments passed to a Java Application.

 

Command Pattern implementation for processing command-line arguments passed to a Java Application.

Table of Contents

Overview

The Nevelex Arguments package provides the framework for doing command-line argument processing within a Java Application


Top

Design Overview

The Nevelex Arguments is based on the Command Pattern described in the Design Pattern: Elements of Reusable Object-Oriented Software book. The GoF Command Pattern is shown in the following figure.

UML GoF Command Pattern
Figure 1: The GoF Command Pattern.

Figure 2 details the current implementation of this package. It is up to the you, the application developer, to

  1. create concrete instances of the ArgumentCommand interface.
  2. register all concrete ArgumentCommand implementations with the ArgumentProcessor using the registerArgumentCommand method.
  3. create the Receiver and ConcreteCommand interactions as shown in Figure 1. This API does not define this interaction because it depends on each application implementation.
  4. initiate the Invoker (i.e. ArgumentProcessor) to process all the command-line arguments using the processArguments (or processArguments) method.

Nevelex Arguments UML Class Diagram
Figure 2: The Nevelex Arguments UML Class Diagram.


Top

ArgumentConsumer Interface

The ArgumentConsumer should be used when command-line arguments are required for the application to function. It provides the contract for initializing and validating the application's processing of the arguments. More specifically, initArgumentState is called at the start of processing and checkArgumentState is called at the completion of processing.


Top

Example Code

Example code is availabe in the com.nevelex.app.args.test package. The example/test code should be run as follows (assumes the JAR files are in the current directory):
java -cp NevArgs.jar:NevArgs-example.jar com.nevelex.app.args.test.ArgTest --help


Top