de.kruis.padoclet.util
Class AbstractOption

java.lang.Object
  extended by de.kruis.padoclet.util.AbstractOption
Direct Known Subclasses:
FilterDocletBase.Option, RefCheckDoclet.Option

public abstract class AbstractOption
extends java.lang.Object

Option handling for doclets. This class holds static methods and data about the options given to the doclet. Additionally instances of the class represent single options.


Field Summary
 java.lang.String defaultValue
          the default value for the option.
 java.lang.String description
          a description of the option.
 boolean isBoolean
          true, if the option has no value parameter.
 boolean isTag
          true, if the value of the option names a javadoc tag.
static java.lang.String LF
          Holds one line.separator character.
static java.lang.String LI
          Holds a line.separator and some spaces.
 java.lang.String name
          the name of the option without the namePrefix.
 java.lang.String namePrefix
          the common name namePrefix of this option
static java.lang.String TAG_DELIMITER
          Delimiters used to separate multiple alternative names for the same function.
 java.lang.String value
          the value of the option.
 
Constructor Summary
AbstractOption(java.lang.String name, java.lang.String namePrefix, java.lang.String description)
          Create a new option, that has no value (boolean option).
AbstractOption(java.lang.String name, java.lang.String namePrefix, java.lang.String defaultValue, boolean isTag, java.lang.String description)
          Create a new option, that has a value.
 
Method Summary
protected static AbstractOption get(java.lang.String name, java.util.Map<java.lang.String,AbstractOption> options)
          Get an option by name.
protected static java.lang.String getDescriptions(java.util.Map<java.lang.String,AbstractOption> options)
          Get a string made from the descriptions of all registered options.
protected static java.util.Set<java.lang.String> getTags(java.util.Map<java.lang.String,AbstractOption> options)
          Get all tags
private static AbstractOption getWithPrefix(java.lang.String prefixedName, java.util.Map<java.lang.String,AbstractOption> options)
          Get an option by its prefixed name.
protected static void initJavaBeanProperties(java.lang.Object bean, java.util.Map<java.lang.String,AbstractOption> options)
          Assign option values to matching bean properties.
protected static void initOptions(java.lang.String[][] options, java.util.Map<java.lang.String,AbstractOption> optionsMap)
          Initialize the option values.
 boolean isSet()
          Is a boolean option given?
protected static int optionLength(java.lang.String name, java.util.Map<java.lang.String,AbstractOption> options)
          Get the number of parameters this option takes.
protected static void register(AbstractOption option, java.util.Map<java.lang.String,AbstractOption> options)
          Register an option.
 java.lang.String toString()
           
 

Field Detail

TAG_DELIMITER

public static final java.lang.String TAG_DELIMITER
Delimiters used to separate multiple alternative names for the same function.

See Also:
Constant Field Values

LF

public static final java.lang.String LF
Holds one line.separator character.


LI

public static final java.lang.String LI
Holds a line.separator and some spaces. Used to format option descriptions.


name

public final java.lang.String name
the name of the option without the namePrefix.


namePrefix

public final java.lang.String namePrefix
the common name namePrefix of this option


value

public java.lang.String value
the value of the option. For boolean options the values "true" and "false" are used.


defaultValue

public final java.lang.String defaultValue
the default value for the option. This value is used, if the option is not given on the command line. For boolean options the values "true" and "false" are used.


isBoolean

public final boolean isBoolean
true, if the option has no value parameter. Otherwise, the option takes one parameter.


isTag

public final boolean isTag
true, if the value of the option names a javadoc tag. This information is used to add -tag tagname:X options to the command line of the formating doclet.


description

public final java.lang.String description
a description of the option. Used for the online help message.

Constructor Detail

AbstractOption

public AbstractOption(java.lang.String name,
                      java.lang.String namePrefix,
                      java.lang.String defaultValue,
                      boolean isTag,
                      java.lang.String description)
Create a new option, that has a value.

Parameters:
name - the name
namePrefix - the common namePrefix of the option name
defaultValue - the default value
isTag - set to true, if the value of the option names a tag.
description - the description of the option

AbstractOption

public AbstractOption(java.lang.String name,
                      java.lang.String namePrefix,
                      java.lang.String description)
Create a new option, that has no value (boolean option).

Parameters:
name - the name
namePrefix - the common namePrefix of the option name
description - the description of the option.
Method Detail

isSet

public boolean isSet()
Is a boolean option given?

Returns:
true, if a boolean option is set (to be exact, if the value of the option is "true". Otherwise returns false.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

register

protected static void register(AbstractOption option,
                               java.util.Map<java.lang.String,AbstractOption> options)
Register an option. This method is intended to be used from a static initializer. It let you define the set of possible option.

Parameters:
option - the option to register.
options - the options map

get

protected static AbstractOption get(java.lang.String name,
                                    java.util.Map<java.lang.String,AbstractOption> options)
Get an option by name.

Parameters:
name - the name of the option.
options - the options map
Returns:
the option object. Returns null, if no option with the given name was registered.

getDescriptions

protected static java.lang.String getDescriptions(java.util.Map<java.lang.String,AbstractOption> options)
Get a string made from the descriptions of all registered options.

Parameters:
options - the options map
Returns:
the compiled descriptions.

getTags

protected static java.util.Set<java.lang.String> getTags(java.util.Map<java.lang.String,AbstractOption> options)
Get all tags

Parameters:
options - the options map
Returns:
a set containing all tag names, that is the values of all options where the property isTag is set.

getWithPrefix

private static AbstractOption getWithPrefix(java.lang.String prefixedName,
                                            java.util.Map<java.lang.String,AbstractOption> options)
Get an option by its prefixed name.

Parameters:
prefixedName - the name of the option including the namePrefix.
options - the options map
Returns:
the option or null, if no matching option exists.

optionLength

protected static int optionLength(java.lang.String name,
                                  java.util.Map<java.lang.String,AbstractOption> options)
Get the number of parameters this option takes.

Parameters:
name - the name of the option.
options - the options map
Returns:
1, if the option takes no parameters, 2, if the option takes a parameter. If the option is unknown, return 0.

initOptions

protected static void initOptions(java.lang.String[][] options,
                                  java.util.Map<java.lang.String,AbstractOption> optionsMap)
Initialize the option values.

Parameters:
options - the options as provided by the javadoc core.
optionsMap - the options map
See Also:
Doclet.validOptions(java.lang.String[][], com.sun.javadoc.DocErrorReporter), RootDoc.options()

initJavaBeanProperties

protected static void initJavaBeanProperties(java.lang.Object bean,
                                             java.util.Map<java.lang.String,AbstractOption> options)
                                      throws java.lang.Throwable
Assign option values to matching bean properties. For each setable property of the Java bean, this method looks for an option with the same name. If such an option exists, the property is set to the value of the option. Currently only beans of the types String, boolen and int are supported.

Parameters:
bean - a java bean
options - the options map
Throws:
java.lang.Throwable