Package com.oorian

Class OorianConfig

java.lang.Object
com.oorian.OorianConfig

public class OorianConfig extends Object
Provides typed access to application configuration properties loaded from oorian.properties, with optional environment profile overrides.

File Location:

Place oorian.properties in your application's WEB-INF/ directory. This is the standard Java web application convention for configuration files and keeps properties outside the classpath root, allowing changes without rebuilding.

Project TypeSource LocationDeploys To
NetBeans + Antweb/WEB-INF/oorian.propertiesWEB-INF/oorian.properties
Maven / Gradlesrc/main/webapp/WEB-INF/oorian.propertiesWEB-INF/oorian.properties

For backward compatibility, if no file is found in WEB-INF/, the framework falls back to loading from the classpath root (WEB-INF/classes/).

The configuration file is loaded automatically during application startup. If no oorian.properties file is found, a warning is logged and the application continues with an empty configuration. All getter methods return sensible defaults when a key is not present.

Environment Profiles:

After loading the base oorian.properties, the framework loads a profile-specific file (e.g., oorian-dev.properties) whose values override the base configuration. The active profile is resolved in this order:

  1. Programmatic: Application.setProfile(String) (must be called before
    invalid reference
    initialize()
    )
  2. System property: -Doorian.profile=dev
  3. Environment variable: OORIAN_PROFILE=dev
  4. Default: "prod"

Usage:


 // Static access from anywhere
 String dbUrl = OorianConfig.get().getString("db.url");

 // With default values
 int port = OorianConfig.get().getInt("server.port", 8080);
 boolean debug = OorianConfig.get().getBoolean("debug.enabled", false);

 // Check the active profile
 if (OorianConfig.get().isProfile("dev")) { ... }
 

Example oorian.properties:

 db.url=jdbc:mysql://localhost:3306/myapp
 db.pool.size=10
 debug.enabled=false
 

Example oorian-dev.properties (overrides):

 db.url=jdbc:h2:mem:devdb
 debug.enabled=true
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default profile used when no profile is specified.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty OorianConfig instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether a key exists in the configuration.
    get()
    Returns the singleton OorianConfig instance.
    Returns the name of the active configuration profile.
    boolean
    getBoolean(String key, boolean defaultValue)
    Returns the boolean value for the given key, or the default if not found.
    double
    getDouble(String key, double defaultValue)
    Returns the double value for the given key, or the default if not found or not a valid double.
    int
    getInt(String key, int defaultValue)
    Returns the integer value for the given key, or the default if not found or not a valid integer.
    long
    getLong(String key, long defaultValue)
    Returns the long value for the given key, or the default if not found or not a valid long.
    int
    Returns the number of configuration properties currently loaded.
    Returns the string value for the given key, or null if not found.
    getString(String key, String defaultValue)
    Returns the string value for the given key, or the default if not found.
    boolean
    Checks whether the active profile matches the given name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_PROFILE

      public static final String DEFAULT_PROFILE
      The default profile used when no profile is specified.
      See Also:
  • Constructor Details

    • OorianConfig

      public OorianConfig()
      Creates a new empty OorianConfig instance.
  • Method Details

    • get

      public static OorianConfig get()
      Returns the singleton OorianConfig instance.
      Returns:
      the configuration instance
    • getString

      public String getString(String key)
      Returns the string value for the given key, or null if not found.
      Parameters:
      key - the property key
      Returns:
      the property value, or null
    • getString

      public String getString(String key, String defaultValue)
      Returns the string value for the given key, or the default if not found.
      Parameters:
      key - the property key
      defaultValue - the default value to return if the key is not found
      Returns:
      the property value, or defaultValue
    • getInt

      public int getInt(String key, int defaultValue)
      Returns the integer value for the given key, or the default if not found or not a valid integer.
      Parameters:
      key - the property key
      defaultValue - the default value
      Returns:
      the integer property value, or defaultValue
    • getLong

      public long getLong(String key, long defaultValue)
      Returns the long value for the given key, or the default if not found or not a valid long.
      Parameters:
      key - the property key
      defaultValue - the default value
      Returns:
      the long property value, or defaultValue
    • getDouble

      public double getDouble(String key, double defaultValue)
      Returns the double value for the given key, or the default if not found or not a valid double.
      Parameters:
      key - the property key
      defaultValue - the default value
      Returns:
      the double property value, or defaultValue
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Returns the boolean value for the given key, or the default if not found.

      Values of "true", "yes", and "1" (case-insensitive) are considered true. All other values are considered false.

      Parameters:
      key - the property key
      defaultValue - the default value
      Returns:
      the boolean property value, or defaultValue
    • containsKey

      public boolean containsKey(String key)
      Checks whether a key exists in the configuration.
      Parameters:
      key - the property key
      Returns:
      true if the key exists, false otherwise
    • getPropertyCount

      public int getPropertyCount()
      Returns the number of configuration properties currently loaded.
      Returns:
      the number of properties
    • getActiveProfile

      public String getActiveProfile()
      Returns the name of the active configuration profile.
      Returns:
      the active profile name (e.g., "dev", "staging", "prod")
    • isProfile

      public boolean isProfile(String name)
      Checks whether the active profile matches the given name.

      The comparison is case-insensitive.

      Parameters:
      name - the profile name to check
      Returns:
      true if the active profile matches, false otherwise