Class OptionManager

    • Field Detail

      • m_Properties

        protected static Properties m_Properties
        the properties in use.
      • m_DefaultVariablesInstance

        protected static Variables m_DefaultVariablesInstance
        default instance (gets replaced at runtime).
      • m_BlacklistedClasses

        protected static Set<String> m_BlacklistedClasses
        the blacklisted classes.
      • m_CommandlineIndex

        protected Map<String,​Integer> m_CommandlineIndex
        the commandline flag <-> index relationship.
      • m_PropertyIndex

        protected Map<String,​Integer> m_PropertyIndex
        the (bean) property <-> index relationship.
      • m_NoVariablesProperties

        protected Set<String> m_NoVariablesProperties
        the properties that cannot have variables attached.
      • m_ThrowExceptions

        protected boolean m_ThrowExceptions
        whether to throw exceptions or just ignore errors.
      • m_Variables

        protected transient Variables m_Variables
        the Variables instance to use for resolving variables.
      • m_Quiet

        protected boolean m_Quiet
        whether to suppress error messages.
    • Constructor Detail

      • OptionManager

        public OptionManager​(OptionHandler owner)
        Initializes the manager.
        Parameters:
        owner - the owner of this manager
    • Method Detail

      • getOwner

        public OptionHandler getOwner()
        Returns the owning OptionHandler.
        Returns:
        the owner
      • getVariables

        public Variables getVariables()
        Returns the variables instance in use.
        Returns:
        the instance in use
      • setThrowExceptions

        public void setThrowExceptions​(boolean value)
        Sets whether to throw exceptions or simply ignore errors (recursively).
        Parameters:
        value - if true then exceptions are thrown on errors
      • getThrowExceptions

        public boolean getThrowExceptions()
        Returns whether to throw exceptions on errors or to ignore them.
        Returns:
        true if exceptions are thrown in case of errors
      • setQuiet

        public void setQuiet​(boolean value)
        Sets whether to suppress error messages.
        Parameters:
        value - true if to suppress error messages
      • isQuiet

        public boolean isQuiet()
        Returns whether to suppress error messages.
        Returns:
        true if to suppress error messages
      • handleError

        protected void handleError​(Throwable t)
        Handles the given throwable/exception. Either throws the exception or
        Parameters:
        t - the error to throw/print
        See Also:
        getThrowExceptions()
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  boolean outputDefValue)
        Determines the appropriate concrete option class, sets it up and returns it. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        outputDefValue - if true then the default value will be listed in the Javadoc
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  boolean outputDefValue,
                                  UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        outputDefValue - if true then the default value will be listed in the Javadoc
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     boolean outputDefValue)
        Determines the appropriate concrete option class, sets it up and returns it.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        outputDefValue - if true then the default value will be listed in the Javadoc
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     boolean outputDefValue,
                                     UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        outputDefValue - if true then the default value will be listed in the Javadoc
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  Number lower,
                                  Number upper)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  Number lower,
                                  Number upper,
                                  UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     Number lower,
                                     Number upper)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     Number lower,
                                     Number upper,
                                     UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. This call will always output the default value.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  boolean outputDefValue,
                                  Number lower,
                                  Number upper)
        Determines the appropriate concrete option class, sets it up and returns it. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        outputDefValue - if true then the default value will be listed in the Javadoc
        Returns:
        the generated option object
      • add

        public AbstractOption add​(String commandline,
                                  String property,
                                  Object defValue,
                                  boolean outputDefValue,
                                  Number lower,
                                  Number upper,
                                  UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it. Adds the option at the end.
        Parameters:
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        outputDefValue - if true then the default value will be listed in the Javadoc
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     boolean outputDefValue,
                                     Number lower,
                                     Number upper)
        Determines the appropriate concrete option class, sets it up and returns it.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        outputDefValue - if true then the default value will be listed in the Javadoc
        Returns:
        the generated option object
      • insert

        public AbstractOption insert​(int index,
                                     String commandline,
                                     String property,
                                     Object defValue,
                                     boolean outputDefValue,
                                     Number lower,
                                     Number upper,
                                     UserMode minUserMode)
        Determines the appropriate concrete option class, sets it up and returns it.
        Parameters:
        index - the position for the option, use -1 to add at the end
        commandline - the commandline string (without the leading dash "-")
        property - the Java Beans property name
        defValue - the default value
        lower - the lower bound
        upper - the upper bound
        outputDefValue - if true then the default value will be listed in the Javadoc
        minUserMode - the minimum user mode before showing this option
        Returns:
        the generated option object
      • disableVariables

        public void disableVariables​(String property)
        Disables variable support for this bean property.
        Parameters:
        property - the property to disable
      • enabledVariables

        public void enabledVariables​(String property)
        Enables variable support for this bean property again.
        Parameters:
        property - the property to enable
      • allowsVariables

        public boolean allowsVariables​(String property)
        Checks whether this property allows variables.
        Parameters:
        property - the bean property to check
        Returns:
        true if variables allowed
      • getOptionsList

        public List<AbstractOption> getOptionsList()
        Returns the list of options.
        Returns:
        the options
      • findOption

        protected AbstractOption findOption​(String flagOrProperty,
                                            boolean flag)
        Returns the option for the commandline flag/property.
        Parameters:
        flagOrProperty - the commandline flag/property string
        flag - if true then "flagOrProperty" is interpreted as flag instead of property
        Returns:
        the option or null if not found
      • findByFlag

        public AbstractOption findByFlag​(String flag)
        Tries to locate the corresponding option for the given commandline string (without the leading dash).
        Parameters:
        flag - the commandline to look for (no leading dash)
        Returns:
        the option or null if not found
        See Also:
        AbstractOption.getCommandline()
      • findByProperty

        public AbstractOption findByProperty​(String property)
        Tries to locate the corresponding option for the given property name.
        Parameters:
        property - the property name to look for
        Returns:
        the option or null if not found
      • findByClass

        public AbstractOption findByClass​(Class cls)
        Tries to locate the corresponding option for the given class.
        Parameters:
        cls - the class to look for
        Returns:
        the option or null if not found
        See Also:
        AbstractOption.getReadMethod()
      • removeByFlag

        public AbstractOption removeByFlag​(String flag)
        Removes the corresponding option associated with the given commandline string (without the leading dash).
        Parameters:
        flag - the commandline to look for (no leading dash)
        Returns:
        the option or null if not found
        See Also:
        AbstractOption.getCommandline()
      • removeByProperty

        public AbstractOption removeByProperty​(String property)
        Removes the corresponding option associated with the given property name.
        Parameters:
        property - the property name to look for
        Returns:
        the option or null if not found
      • removeOption

        protected AbstractOption removeOption​(String flagOrProperty,
                                              boolean flag)
        Removes the option associated with the commandline flag/property.
        Parameters:
        flagOrProperty - the commandline flag/property string
        flag - if true then "flagOrProperty" is interpreted as flag instead of property
        Returns:
        the option or null if not found
      • setVariableForProperty

        public AbstractArgumentOption setVariableForProperty​(String property,
                                                             String variable)
        Sets the variable in the option handler for the given property.
        Parameters:
        property - the property to set the variable for
        variable - the variable name, null removes the variable
        Returns:
        the option that the variable was set for, null if property not found
      • getVariableForProperty

        public String getVariableForProperty​(String property)
        Returns the variable that is attached to a property.
        Parameters:
        property - the property to check for a variable
        Returns:
        null if no variable attached, otherwise the variable name
      • hasVariableForProperty

        public boolean hasVariableForProperty​(String property)
        Returns whether there is a variable attached to the property.
        Parameters:
        property - the property to check for a variable
        Returns:
        true if variable attached
      • ensureVariableForPropertyExists

        public String ensureVariableForPropertyExists​(String property)
        If a variable is attached to the variable, it checks whether the variable really exists in the context. If that shouldn't be the case, an error message gets returned, otherwise null. If no variable is attached, then null is being returned as well.
        Parameters:
        property - the property to check for a variable
        Returns:
        null if no variable attached or variable exists, otherwise error message
      • isDefaultValueByFlag

        public boolean isDefaultValueByFlag​(String flag)
        Checks whether the current value associated with the flag is the default value.
        Parameters:
        flag - the commandline to look for (no leading dash)
        Returns:
        true if option located, has an argument and is the default value
      • isDefaultValueByProperty

        public boolean isDefaultValueByProperty​(String property)
        Checks whether the current value associated with the property is the default value.
        Parameters:
        property - the property name to look for
        Returns:
        true if option located, has an argument and is the default value
      • setDefaults

        public void setDefaults()
        Sets the default values.
      • updateVariablesInstance

        public void updateVariablesInstance​(Variables variables)
        Updates the Variables instance recursively on all options.
        Parameters:
        variables - the variables instance to use
      • updateVariableValues

        public String updateVariableValues()
        Updates the variables, i.e., in case an option uses a variable and this variable's value has changed, the updated value will be set.
        Returns:
        null if all variables were successfully updated
      • updateVariableValues

        public String updateVariableValues​(boolean forceUpdate)
        Updates the variables, i.e., in case an option uses a variable and this variable's value has changed (or update is enforced), the updated value will be set.
        Parameters:
        forceUpdate - whether to force the update
        Returns:
        null if all variables were successfully updated
      • updateVariableValues

        public String updateVariableValues​(boolean forceUpdate,
                                           Logger log)
        Updates the variables, i.e., in case an option uses a variable and this variable's value has changed (or update is enforced), the updated value will be set.
        Parameters:
        forceUpdate - whether to force the update
        log - optional logger for logging traversal, can be null
        Returns:
        null if all variables were successfully updated
      • registerVariables

        public void registerVariables()
        Registers all the variables recursively.
      • deregisterVariables

        public void deregisterVariables()
        Deregisters all the variables recursively.
      • updateVariablePrefix

        public void updateVariablePrefix​(String prefix,
                                         boolean add)
        Adds or removes the specified prefix from all variables.
        Parameters:
        prefix - the prefix for the variables
        add - whether to add or remove the prefixes
      • traverse

        public void traverse​(OptionTraverser traverser)
        Traverses all the options and lets the various options get handled by the supplied object.
        Parameters:
        traverser - the object to handled the traversed options
      • traverse

        public void traverse​(OptionTraverser traverser,
                             boolean nonAdams)
        Traverses all the options and lets the various options get handled by the supplied object.
        Parameters:
        traverser - the object to handled the traversed options
        nonAdams - whether to traverse non-ADAMS objects as well
      • traverse

        protected void traverse​(OptionTraverser traverser,
                                OptionTraversalPath path,
                                boolean nonAdams)
        Traverses all the options and lets the various options get handled by the supplied object.
        Parameters:
        traverser - the object to handle the traversed options
        path - the path so far
        nonAdams - whether to traverse non-ADAMS objects as well
      • traverse

        protected void traverse​(OptionTraverser traverser,
                                OptionTraversalPath path,
                                Object obj)
        Traverses a non-ADAMS OptionHandler.
        Parameters:
        traverser - the object to handle the traversed options
        path - the path so far
        obj - the non-ADAMS object to traverse
      • size

        public int size()
        Returns the number of managed options.
        Returns:
        the number of options
      • isValid

        public boolean isValid​(String property,
                               Number n)
        Checks whether the numeric value is valid (within the bounds, if any).
        Parameters:
        property - the property to check
        n - the number to check
        Returns:
        true if valid
      • cleanUp

        public void cleanUp()
        Cleans up the options vector.
        Specified by:
        cleanUp in interface CleanUpHandler
      • getProperties

        protected static Properties getProperties()
        Returns the properties file with the custom editors.
        Returns:
        the props file
      • isBlacklistedClass

        protected static boolean isBlacklistedClass​(Object obj)
        Checks whether the object's class is blacklisted.
        Parameters:
        obj - the object to check
        Returns:
        true if blacklisted
      • isBlacklistedClass

        protected static boolean isBlacklistedClass​(Class cls)
        Checks whether the class is blacklisted.
        Parameters:
        cls - the class to check
        Returns:
        true if blacklisted
      • isBlacklistedClass

        protected static boolean isBlacklistedClass​(String cls)
        Checks whether the class is blacklisted.
        Parameters:
        cls - the class to check
        Returns:
        true if blacklisted