[Japi-cvs] SF.net SVN: japi: [258] libs/argparser/trunk/src/net/sf/japi/io/args
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2006-12-14 23:09:12
|
Revision: 258
http://svn.sourceforge.net/japi/?rev=258&view=rev
Author: christianhujer
Date: 2006-12-14 15:09:06 -0800 (Thu, 14 Dec 2006)
Log Message:
-----------
Improvements on BasicCommand.
Modified Paths:
--------------
libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java
libs/argparser/trunk/src/net/sf/japi/io/args/Command.java
libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-14 23:05:41 UTC (rev 257)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-14 23:09:06 UTC (rev 258)
@@ -19,34 +19,37 @@
/** The ResourceBundle for locale-specific output. */
private final ResourceBundle resourceBundle = ResourceBundle.getBundle("net.sf.japi.io.args.messages");
- /** The maximum width of the option type field. */
- private final int maxOptionTypeWidth;
-
/**
* Whether to exit or not.
- * @see Command#isExiting()
+ * @see Command#isExiting()
*/
private boolean exiting;
/** Create a BasicCommand. */
protected BasicCommand() {
- int tmpMaxOptionTypeWidth = 0;
- for (final OptionType optionType : OptionType.values()) {
- tmpMaxOptionTypeWidth = Math.max(tmpMaxOptionTypeWidth, optionType.toString().length());
- }
- maxOptionTypeWidth = tmpMaxOptionTypeWidth;
}
/**
* Exit Option.
+ * Normally you wouldn't override this method.
+ * The default behaviour is to not exit.
+ * This prevents {@link System#exit(int)} from being invoked when BasicCommand resp. ArgParser is invoked from a running VM.
+ * If you invoke a command from a batch, setting the <code>exiting</code> property to <code>true</code> makes sense.
+ * This usually should always be determined by the user of a program, not the programmer.
* @param exiting <code>true</code> if {@link System#exit(int)} should be invoked, otherwise <code>false</code>.
+ * @see System#exit(int)
+ * @see #isExiting()
*/
@Option(value = {"exit"})
public void setExiting(@NotNull final Boolean exiting) {
this.exiting = exiting;
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ * @see System#exit(int)
+ * @see #setExiting(Boolean)
+ */
public Boolean isExiting() {
return exiting;
}
@@ -106,11 +109,50 @@
/**
* Get the ResourceBundle for the default locale.
- * If you override this method be sure to declare the bundle returned by the overridden method as parent of your bundle.
+ * If you override this method, the methods of BasicCommand will still use BasicCommand's own ResourceBundle as a backup.
+ * That means overriding this method will not break any default behaviour of BasicCommand.
* @return ResourceBundle for default locale.
*/
public ResourceBundle getBundle() {
return resourceBundle;
}
+ /**
+ * Get the help header.
+ * The default implementation returns a bundle String (see {@link #getBundle()}) for the key "helpHeader".
+ * The default String for "helpHeader" is the empty String.
+ * @return Help header.
+ */
+ public String getHelpHeader() {
+ return getString("helpHeader");
+ }
+
+ /**
+ * Get the help footer.
+ * The default implementation returns a bundle String (see {@link #getBundle()}) for the key "helpFooter".
+ * The default String for "helpFooter" is the empty String.
+ * @return Help footer.
+ */
+ public String getHelpFooter() {
+ return getString("helpFooter");
+ }
+
+ /**
+ * Returns a String from the ResourceBundles.
+ * This method first tries the subclass's ResourceBundle.
+ * If that fails, the String is returned from BasicCommand's own resource bundle.
+ * If that fails too, a MissingResourceException is thrown.
+ * If that fails, the String is returned from the subclass's ResourceBundle.
+ * @param key Name of the key to look up
+ * @return String from the ResourceBundles.
+ * @throws MissingResourceException In case all tries for retrieving a value for <var>key</var> failed.
+ */
+ private String getString(final String key) throws MissingResourceException {
+ try {
+ return getBundle().getString(key);
+ } catch (MissingResourceException e) {
+ return resourceBundle.getString(key);
+ }
+ }
+
} // class BasicCommand
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/Command.java
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-12-14 23:05:41 UTC (rev 257)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/Command.java 2006-12-14 23:09:06 UTC (rev 258)
@@ -27,7 +27,7 @@
/**
* Shell commands can implement this interface and make use of ArgParser.
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @see BasicCommand BasicCommand for a convenient implementation of this interface
+ * @see BasicCommand BasicCommand for a very convenient implementation of this interface
*/
public interface Command {
Modified: libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties
===================================================================
--- libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties 2006-12-14 23:05:41 UTC (rev 257)
+++ libs/argparser/trunk/src/net/sf/japi/io/args/messages.properties 2006-12-14 23:09:06 UTC (rev 258)
@@ -7,3 +7,5 @@
help=Display this help and exit.
setExiting=Quit Java VM with error code.
setNotExiting=Don't quit Java VM (default).
+helpHeader=
+helpFooter=
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|