Class Project

java.lang.Object
org.metagene.genestrip.make.Project
Direct Known Subclasses:
GSProject

public abstract class Project extends Object
Base class for a project: a named holder of typed configuration parameters (each a ConfigKey whose value is validated against its ConfigParamInfo) plus free-form additional properties. Goals read their configuration through the project. Subclasses declare the supported configuration keys via getConfigKeys().
  • Field Details

    • PROJECT_NAME

      public static final String PROJECT_NAME
      Additional-property key under which the project name is stored.
      See Also:
  • Constructor Details

    • Project

      public Project(String name)
      Creates a project with the given name, which is also recorded as the "projectName" additional property.
      Parameters:
      name - the project name
  • Method Details

    • setAdditionalProperty

      public void setAdditionalProperty(String key, String value)
      Sets a free-form additional property.
      Parameters:
      key - the property key
      value - the property value
    • getAdditionalProperty

      public String getAdditionalProperty(String key)
      Returns the value of a free-form additional property.
      Parameters:
      key - the property key
      Returns:
      the property value, or null if unset
    • getAdditionalProperties

      public Properties getAdditionalProperties()
      Returns a copy of the free-form additional properties.
      Returns:
      a copy of the additional properties
    • getConfigAsProperties

      public Properties getConfigAsProperties()
      Returns the configured parameter values as properties keyed by config key name.
      Returns:
      the config parameters as properties
    • getAllAsProperties

      public Properties getAllAsProperties()
      Returns the config parameters and the additional properties combined into a single Properties.
      Returns:
      the config parameters and additional properties combined
    • getLogger

      protected org.apache.commons.logging.Log getLogger()
      Returns the logger of this project.
      Returns:
      the project logger
    • getConfigKeys

      protected abstract ConfigKey[] getConfigKeys()
      Returns all configuration keys supported by this project.
      Returns:
      the supported configuration keys
    • configKeyFromName

      protected ConfigKey configKeyFromName(String name)
      Returns the supported config key with the given name, or null if there is none.
      Parameters:
      name - the config key name to look up
      Returns:
      the matching config key, or null if there is none
    • getName

      public String getName()
      Returns the project name.
      Returns:
      the project name
    • configValue

      public Object configValue(ConfigKey key)
      Returns the configured value for the given key, or the key's default value if it is unset.
      Parameters:
      key - the config key
      Returns:
      the configured value, or the key's default value if unset
    • intConfigValue

      public int intConfigValue(ConfigKey key)
      Returns the value of the given key as an int.
      Parameters:
      key - the config key
      Returns:
      the value as an int
      Throws:
      IllegalStateException - if the value is not an int
    • longConfigValue

      public long longConfigValue(ConfigKey key)
      Returns the value of the given key as a long.
      Parameters:
      key - the config key
      Returns:
      the value as a long
      Throws:
      IllegalStateException - if the value is not a long
    • booleanConfigValue

      public boolean booleanConfigValue(ConfigKey key)
      Returns the value of the given key as a boolean.
      Parameters:
      key - the config key
      Returns:
      the value as a boolean
      Throws:
      IllegalStateException - if the value is not a boolean
    • doubleConfigValue

      public double doubleConfigValue(ConfigKey key)
      Returns the value of the given key as a double.
      Parameters:
      key - the config key
      Returns:
      the value as a double
      Throws:
      IllegalStateException - if the value is not a double
    • stringConfigValue

      public String stringConfigValue(ConfigKey key)
      Returns the value of the given key as a String.
      Parameters:
      key - the config key
      Returns:
      the value as a String
      Throws:
      IllegalStateException - if the value is not a String
    • initConfigParams

      protected void initConfigParams(Properties... propsArray)
      Initializes all supported config parameters from the given property sources.
      Parameters:
      propsArray - the property sources, in decreasing priority
    • initConfigParam

      protected void initConfigParam(ConfigKey key, Properties... propsArray)
      Initializes a single config parameter from the first property source that supplies a value the key accepts, falling back to the key's default value.
      Parameters:
      key - the config key to initialize
      propsArray - the property sources, in decreasing priority
      Throws:
      IllegalStateException - if even the default value is illegal
    • initConfigParam

      public boolean initConfigParam(ConfigKey key, Object value)
      Sets the value of the given config parameter if it is within the key's allowed range.
      Parameters:
      key - the config key to set
      value - the value to store
      Returns:
      whether the value was accepted and stored
    • isStrictConfigCheck

      protected boolean isStrictConfigCheck()
      Whether an unknown configuration key, or a value its key cannot take, ends the run instead of being reported and dropped. false here; a subclass that has a setting for it says so by overriding.
      Returns:
      whether an unknown key or an invalid or out-of-range value is an error rather than a warning
    • checkConfigProperties

      protected void checkConfigProperties(Properties properties, GoalKey forGoal)
      Reports entries of the given properties that reference an unknown key, a key that is not valid for the given goal, or an invalid or out-of-range value.

      Reports and carries on, the key keeping its default -- unless isStrictConfigCheck() says otherwise, in which case an unknown key, an invalid value and a value out of range each end the run. Carrying on is not free: a database was once built for two and a half hours with refseq.updateScope=allButExcluded in its configuration and ALL in effect, because the running version did not yet know that value. The result looked plausible and answered a different question than the one asked. An unknown key -- a typo, or a key a later version dropped -- is the same kind of mistake: it has no effect, and the effect it was meant to have is missing from the result. Strict checking is for runs long enough that one wants to hear about that at the start rather than at the end.

      A key that belongs to another goal stays a warning either way, and it has to: one configuration file serves every goal of a project, and each goal checks the whole file, so a key meant for another goal is the normal case rather than an error. What counts as known is getConfigKeys(), so a module adds its keys to the check by overriding that, as FTProject does with the ft. keys.

      Parameters:
      properties - the properties to check
      forGoal - the goal the properties are checked against
      Throws:
      IllegalArgumentException - if a key is unknown or a value is invalid or out of range, and strict checking is on
    • logParamMap

      public void logParamMap()
      Logs the effective configuration parameter map at info level, ordered by parameter name.

      The map itself is a HashMap, so its own iteration order is the hash order of the config keys: neither their declaration order nor anything a reader can search in. Sorting by name makes two runs comparable line by line.