Package edu.wisc.game.util

## Class MainConfig

- java.lang.Object
- - edu.wisc.game.util.MainConfig

-     public class MainConfig
      extends Object

  A MainConfig is a structure storing the content of a configuration file. (It can also be modified with the doPut() method, though). Typically, an application uses only one such file -- the master config file of the Game Server running on this host. It can be used by the site administrator to override some defaults. The master config file is located outside of the WAR file, so that adjustments can be made without rebuilding the WAR file.

  In particular, the main config file (usually located in /opt/w2020/w2020.conf) may override the user name and password for accessing the MySQL database password specified in META-INF/persistence.xml (packaged into the WAR file). Thus changing the database password, or asking the server to work with a different database, can be accommodated without having to rebuild the WAR file.

  The MainConfig object is used in sql.Main

  In some applications there are multiple instances of MainConfig. E.g. MergeDatasets uses the config file for the merge data set as the main config file, and additionally has an instance of MainConfig describing the data set being merged into the merge data set.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `MainConfig​(String _path)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `File` | `doGetFile​(String name, String defVal)` | Looks up the path in this config file, adjusts it if necessary (when on a DoIT shared hosting host), and converts it to a File object
    `String` | `doGetGuiClientUrl​(boolean dev)` |
    `int` | `doGetInt​(String name, int defVal)` |
    `String` | `doGetString​(String name, String defVal)` |
    `void` | `doPut​(String name, String value)` | Modifies a table, overriding the value read from the config file
    `static File` | `getFile​(String name, String defVal)` | Looks up the path in the main config file of the app, adjusts it if necessary (when on a DoIT shared hosting host), and converts it to a File object
    `static String` | `getGuiClientUrl​(boolean dev)` | The URL string for the Rule Game GUI Client.
    `static int` | `getInt​(String name, int defVal)` |
    `static MainConfig` | `getMainConfig()` | Gets the default instance.
    `static String` | `getString​(String name, String defVal)` |
    `static void` | `put​(String name, String value)` | If any setPath() is used, put() can only be done after setPath()
    `static void` | `setPath​(String _path)` | Sets the location of this app's main config file, and causes the app to read it in, if it has not been read yet.
    `String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MainConfig

          public MainConfig​(String _path)

      Parameters:
        `_path` - The location of the master config file (or an alternative config file) from which this structure will be initialized

  - ### Method Detail

    - #### getMainConfig

          public static MainConfig getMainConfig()

      Gets the default instance.

    - #### setPath

          public static void setPath​(String _path)

      Sets the location of this app's main config file, and causes the app to read it in, if it has not been read yet. This method is used by analysis tools who work with different databases than the default one. It is also used by the Captive Server, with null argument, to disable the attempts to look for the master config file (which CGS users likely won't have).
      Parameters:
        `_path` - The location of the main config file to be used in this application, or null to indicate that we don't use a config file in this app.

    - #### getString

          public static String getString​(String name,
                                         String defVal)

    - #### doGetString

          public String doGetString​(String name,
                                    String defVal)

    - #### getInt

          public static int getInt​(String name,
                                   int defVal)

    - #### doGetInt

          public int doGetInt​(String name,
                              int defVal)

    - #### getFile

          public static File getFile​(String name,
                                     String defVal)

      Looks up the path in the main config file of the app, adjusts it if necessary (when on a DoIT shared hosting host), and converts it to a File object

    - #### doGetFile

          public File doGetFile​(String name,
                                String defVal)

      Looks up the path in this config file, adjusts it if necessary (when on a DoIT shared hosting host), and converts it to a File object

    - #### getGuiClientUrl

          public static String getGuiClientUrl​(boolean dev)

      The URL string for the Rule Game GUI Client.
      Parameters:
        `dev` - True for the dev version, false for prod
      Returns:
        The URL string, or the default (a URL on same server and port)

    - #### doGetGuiClientUrl

          public String doGetGuiClientUrl​(boolean dev)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### doPut

          public void doPut​(String name,
                            String value)

      Modifies a table, overriding the value read from the config file

    - #### put

          public static void put​(String name,
                                 String value)

      If any setPath() is used, put() can only be done after setPath()