Class FactorySettings

java.lang.Object
java.util.Dictionary<K,​V>
java.util.Hashtable<Object,​Object>
java.util.Properties
org.ghotibeaun.json.factory.FactorySettings
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,​Object>

public class FactorySettings
extends Properties
Holds all the various factories' settings for instantiation of various JSON objects. All keys defined have default settings, which can be overridden with the appropriate implementation for that interface. For example, if you created a different implementation for the JSONFactory, before you invoked the factory, you call the applySetting(String, String) method using the #JSON_FACTORY key with the classname of your new implementation
 FactorySettings.applySetting(FactorySettings.JSON_FACTORY, "com.example.MyJsonFactory");
 
By default, this will change the settings from the default settings to your modified configuration. However, if you wanted to go back to the default settings, you can set the setUseDefaultSettings(boolean) to true
Author:
Jim Earley (xml.jim@gmail.com)
See Also:
Serialized Form
  • Method Details

    • createFactoryClass

      public static <T> T createFactoryClass​(Setting setting) throws JSONFactoryException
      Throws:
      JSONFactoryException
    • getFactoryClass

      public static Optional<Class<?>> getFactoryClass​(String key)
    • getFactoryClass

      public static Optional<Class<?>> getFactoryClass​(Setting setting)
    • getCache

      public org.ghotibeaun.json.factory.FactorySettings.FactoryClassCache getCache()
    • applySetting

      public static void applySetting​(String name, String value) throws JSONFactoryException
      Applies a setting. By default, this will configure change use from the default settings to your custom settings when you call getSetting(String). If you wish to use the default again, you can override with getSetting(String, boolean), and apply the setting flag to true. Alternatively, you can globally override to defaults by calling setUseDefaultSettings(boolean) and setting the flag to true.
      Parameters:
      name - the setting key. These are defined as constants
      value - the setting value
      Throws:
      JSONFactoryException
    • applySetting

      public static void applySetting​(Setting setting, String value) throws JSONFactoryException
      Throws:
      JSONFactoryException
    • getSetting

      public static String getSetting​(String name)
      Returns a setting value
      Parameters:
      name - the setting key
      Returns:
      the setting value. The setting value will be determined based on whether getUseDefaultSettings() is true or false. If true, then the out of the box settings and configuration will be used. If false, then the modified settings value will be used. Note that if you haven't changed that particular setting, then the default and custom settings will be the same, until changed.
    • getSetting

      public static String getSetting​(Setting setting)
    • getSetting

      public static String getSetting​(String name, boolean useDefault)
      Returns a setting value from either the default or custom settings
      Parameters:
      name - the setting key
      useDefault - flag to indicate whether to use the default (true) or custom (false) settings
      Returns:
      The setting value. If useDefault is set to true then the setting's value will be returned from the default (out of the box) settings. If the value is false then the custom settings will be used. This will not change the "global" flag to use either the default or custom settings
    • getSetting

      public static String getSetting​(Setting setting, boolean useDefault)
    • getDefaultSetting

      public static String getDefaultSetting​(String name)
      Return the default setting
      Parameters:
      name - the Setting key
      Returns:
      the default setting for this key. It's the equivalent of getSetting([settingkey], true). This will not change the "global" flag to use either the default or custom settings
    • getDefaultSetting

      public static String getDefaultSetting​(Setting setting)
    • getCustomSetting

      public static String getCustomSetting​(String name)
      Return the custom setting
      Parameters:
      name - the Setting key
      Returns:
      the custom setting for this key. It's the equivalent of getSetting([settingkey], false). This will not change the "global" flag to use either the default or custom settings
    • getCustomSetting

      public static String getCustomSetting​(Setting setting)
    • setUseDefaultSettings

      public static void setUseDefaultSettings​(boolean use)
      Global sets which configuration settings to use.
      Parameters:
      use - If set to true, then the default settings will be used; if set to false, then the custom settings will be applied
    • getUseDefaultSettings

      public static boolean getUseDefaultSettings()
      Returns whether the default or custom settings are used
      Returns:
      true if the Default (out of the box) settings are used globally; if false, the custom settings will be applied globally. This setting informs the getSetting(String) method.