|
From: <de...@us...> - 2003-08-07 08:46:38
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core
In directory sc8-pr-cvs1:/tmp/cvs-serv25753/modules/core/src/com/babeldoc/core
Modified Files:
BabeldocCommand.java
Log Message:
Implementing Holywood principle
Index: BabeldocCommand.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/BabeldocCommand.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** BabeldocCommand.java 5 Aug 2003 14:55:41 -0000 1.13
--- BabeldocCommand.java 7 Aug 2003 08:46:35 -0000 1.14
***************
*** 79,83 ****
import org.apache.commons.cli.ParseException;
-
/**
* <p>
--- 79,82 ----
***************
*** 91,282 ****
* @version 1.0
*/
! public class BabeldocCommand {
! /** Options */
! private Options options = new Options();
! /** The description of the command */
! private String desc;
! /** The name of the command */
! private String name;
! /** instance: is this verbose */
! private boolean verbose = false;
! /**
! * Had to lessen this from private access. This is because it is too strict
! * for all purposes.
! */
! protected BabeldocCommand() {
! }
! /**
! * construct the object. The arguments from the command line.
! *
! * @param name DOCUMENT ME!
! * @param desc DOCUMENT ME!
! * @param args the array of strings
! */
! protected BabeldocCommand(String name, String desc, String[] args) {
! this.name = name;
! this.desc = desc;
! setup();
! setupCommandLine(options);
! CommandLine commandLine = null;
! try {
! commandLine = new GnuParser().parse(options, args);
! } catch (ParseException e) {
! printUsage();
! return;
! }
! setupShutdownHook();
! execute(commandLine);
! }
! /**
! * Set the verbose flag
! *
! * @param verbose
! */
! public void setVerbose(boolean verbose) {
! this.verbose = verbose;
! }
! /**
! * get the verbose flag
! *
! * @return
! */
! public boolean isVerbose() {
! return verbose;
! }
! /**
! * execute the commandline. This must be overloaded to handle the command
! * line options
! *
! * @param commandLine the command line options that have been detectected
! */
! public void execute(CommandLine commandLine) {
! if (commandLine.hasOption('h')) {
! printUsage();
! } else if (commandLine.hasOption('v')) {
! setVerbose(true);
! }
! else if (commandLine.hasOption('d')) {
! printConfigInfo();
! }
! }
! /**
! * Stopping - execute all necessary shutdown processing.
! */
! public void finishUp() {
! }
! /**
! * print the usage instructions
! */
! public void printUsage() {
! System.out.println(name);
! System.out.println(desc);
! new HelpFormatter().printHelp(name, options);
! String version = ConfigService.getString("env/build", "babeldoc_version");
! System.out.println("\n" + com.babeldoc.core.I18n.get("001006", version));
! System.out.println(com.babeldoc.core.I18n.get("001007"));
! System.out.println(com.babeldoc.core.I18n.get("001008"));
! System.out.println(com.babeldoc.core.I18n.get("001009"));
! }
! /**
! * print configuration info
! */
! public void printConfigInfo() {
! // NOTE: copied from LightConfigService.mergePropertiesFileFromUserSearchPath
! // get all the 'config.properties' files that are/will be loaded
! URL[] urls = ResourceLoader.getMatchingUrlsInSearchPath("env/config.properties",
! EnvironmentLoader.getSearchPaths());
! // display the name and contents of each config file
! System.out.println("Showing configuration files and contents:");
! for (int i = urls.length - 1; i >= 0; --i) {
! URL url = urls[i];
! System.out.println(" === " + url + " ===");
! try {
! BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
! String line;
! do {
! line = reader.readLine();
! if (line != null) {
! System.out.println(line);
! }
! }
! while (line != null);
! } catch (IOException e) {
! LogService.getInstance().logError(e);
! }
! }
! }
! /**
! * setup the options on the command line.
! *
! * @param options the options to access
! */
! public void setupCommandLine(Options options) {
! options.addOption("v", "verbose", false, com.babeldoc.core.I18n.get("001002"));
! options.addOption("h", "help" , false, com.babeldoc.core.I18n.get("001003"));
! options.addOption("d", "debug" , false, "Write config info to stdout");
! }
! /**
! * Setup the shutdown hook.
! */
! public void setupShutdownHook() {
! /**
! * TODO: DOCUMENT ME!
! *
! * @author $author$
! * @version $Revision$
! */
! class ShutMeDownNicely extends Thread {
! BabeldocCommand command;
! /**
! * Creates a new ShutMeDownNicely object.
! *
! * @param command DOCUMENT ME!
! */
! ShutMeDownNicely(BabeldocCommand command) {
! super("shutdown");
! this.command = command;
! }
! /**
! * TODO: DOCUMENT ME!
! */
! public void run() {
! LogService.getInstance().logDebug(I18n.get("001001"));
! command.finishUp();
! }
! }
! Runtime.getRuntime().addShutdownHook(new ShutMeDownNicely(this));
! }
! /**
! * Setup
! */
! protected void setup() {
! com.babeldoc.core.EnvironmentLoader.loadEnvironment();
! }
}
--- 90,301 ----
* @version 1.0
*/
! public abstract class BabeldocCommand {
! /** Options */
! private Options options = new Options();
! /** The description of the command */
! private String desc;
! /** The name of the command */
! private String name;
! /** instance: is this verbose */
! private boolean verbose = false;
! /**
! * Had to lessen this from private access. This is because it is too strict
! * for all purposes.
! */
! protected BabeldocCommand() {
! }
! /**
! * construct the object. The arguments from the command line.
! *
! * @param name DOCUMENT ME!
! * @param desc DOCUMENT ME!
! * @param args the array of strings
! */
! protected BabeldocCommand(String name, String desc, String[] args) {
! this.name = name;
! this.desc = desc;
! setup();
! setupCommandLine(options);
! CommandLine commandLine = null;
! try {
! commandLine = new GnuParser().parse(options, args);
! } catch (ParseException e) {
! printUsage();
! return;
! }
! setupShutdownHook();
! executeCommand(commandLine);
! }
! /**
! * Set the verbose flag
! *
! * @param verbose
! */
! public void setVerbose(boolean verbose) {
! this.verbose = verbose;
! }
! /**
! * get the verbose flag
! *
! * @return
! */
! public boolean isVerbose() {
! return verbose;
! }
! /**
! * execute the commandline. This must be overloaded to handle the command
! * line options
! *
! * @param commandLine the command line options that have been detectected
! */
! public void executeCommand(CommandLine commandLine) {
! if (commandLine.hasOption('h')) {
! printUsage();
! } else if (commandLine.hasOption('v')) {
! setVerbose(true);
! } else if (commandLine.hasOption('d')) {
! printConfigInfo();
! } else {
! execute(commandLine);
! }
! }
!
!
! /**
! * @param commandLine
! */
! public abstract void execute(CommandLine commandLine);
! /**
! * Stopping - execute all necessary shutdown processing.
! */
! public void finishUp() {
! }
! /**
! * print the usage instructions
! */
! public void printUsage() {
! System.out.println(name);
! System.out.println(desc);
! new HelpFormatter().printHelp(name, options);
! String version =
! ConfigService.getString("env/build", "babeldoc_version");
! System.out.println(
! "\n" + com.babeldoc.core.I18n.get("001006", version));
! System.out.println(com.babeldoc.core.I18n.get("001007"));
! System.out.println(com.babeldoc.core.I18n.get("001008"));
! System.out.println(com.babeldoc.core.I18n.get("001009"));
! }
! /**
! * print configuration info
! */
! public void printConfigInfo() {
! // NOTE: copied from LightConfigService.mergePropertiesFileFromUserSearchPath
! // get all the 'config.properties' files that are/will be loaded
! URL[] urls =
! ResourceLoader.getMatchingUrlsInSearchPath(
! "env/config.properties",
! EnvironmentLoader.getSearchPaths());
! // display the name and contents of each config file
! System.out.println("Showing configuration files and contents:");
! for (int i = urls.length - 1; i >= 0; --i) {
! URL url = urls[i];
! System.out.println(" === " + url + " ===");
! try {
! BufferedReader reader =
! new BufferedReader(new InputStreamReader(url.openStream()));
! String line;
! do {
! line = reader.readLine();
! if (line != null) {
! System.out.println(line);
! }
! } while (line != null);
! } catch (IOException e) {
! LogService.getInstance().logError(e);
! }
! }
! }
! /**
! * setup the options on the command line.
! *
! * @param options the options to access
! */
! public void setupCommandLine(Options options) {
! options.addOption(
! "v",
! "verbose",
! false,
! com.babeldoc.core.I18n.get("001002"));
! options.addOption(
! "h",
! "help",
! false,
! com.babeldoc.core.I18n.get("001003"));
! options.addOption("d", "debug", false, "Write config info to stdout");
! }
! /**
! * Setup the shutdown hook.
! */
! public void setupShutdownHook() {
! /**
! * TODO: DOCUMENT ME!
! *
! * @author $author$
! * @version $Revision$
! */
! class ShutMeDownNicely extends Thread {
! BabeldocCommand command;
! /**
! * Creates a new ShutMeDownNicely object.
! *
! * @param command DOCUMENT ME!
! */
! ShutMeDownNicely(BabeldocCommand command) {
! super("shutdown");
! this.command = command;
! }
! /**
! * TODO: DOCUMENT ME!
! */
! public void run() {
! LogService.getInstance().logDebug(I18n.get("001001"));
! command.finishUp();
! }
! }
! Runtime.getRuntime().addShutdownHook(new ShutMeDownNicely(this));
! }
!
! /**
! * Setup
! */
! protected void setup() {
! com.babeldoc.core.EnvironmentLoader.loadEnvironment();
! }
}
|