Package org.ghotibeaun.json.factory
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 Summary
Modifier and Type Method Description static void
applySetting(String name, String value)
Applies a setting.static void
applySetting(Setting setting, String value)
static <T> T
createFactoryClass(Setting setting)
org.ghotibeaun.json.factory.FactorySettings.FactoryClassCache
getCache()
static String
getCustomSetting(String name)
Return the custom settingstatic String
getCustomSetting(Setting setting)
static String
getDefaultSetting(String name)
Return the default settingstatic String
getDefaultSetting(Setting setting)
static Optional<Class<?>>
getFactoryClass(String key)
static Optional<Class<?>>
getFactoryClass(Setting setting)
static String
getSetting(String name)
Returns a setting valuestatic String
getSetting(String name, boolean useDefault)
Returns a setting value from either the default or custom settingsstatic String
getSetting(Setting setting)
static String
getSetting(Setting setting, boolean useDefault)
static boolean
getUseDefaultSettings()
Returns whether the default or custom settings are usedstatic void
setUseDefaultSettings(boolean use)
Global sets which configuration settings to use.Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Method Details
-
createFactoryClass
- Throws:
JSONFactoryException
-
getFactoryClass
-
getFactoryClass
-
getCache
public org.ghotibeaun.json.factory.FactorySettings.FactoryClassCache getCache() -
applySetting
Applies a setting. By default, this will configure change use from the default settings to your custom settings when you callgetSetting(String)
. If you wish to use the default again, you can override withgetSetting(String, boolean)
, and apply the setting flag totrue
. Alternatively, you can globally override to defaults by callingsetUseDefaultSettings(boolean)
and setting the flag totrue
.- Parameters:
name
- the setting key. These are defined as constantsvalue
- the setting value- Throws:
JSONFactoryException
-
applySetting
- Throws:
JSONFactoryException
-
getSetting
Returns a setting value- Parameters:
name
- the setting key- Returns:
- the setting value. The setting value will be determined based on whether
getUseDefaultSettings()
istrue
orfalse
. Iftrue
, then the out of the box settings and configuration will be used. Iffalse
, 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
-
getSetting
Returns a setting value from either the default or custom settings- Parameters:
name
- the setting keyuseDefault
- flag to indicate whether to use the default (true
) or custom (false
) settings- Returns:
- The setting value. If
useDefault
is set totrue
then the setting's value will be returned from the default (out of the box) settings. If the value isfalse
then the custom settings will be used. This will not change the "global" flag to use either the default or custom settings
-
getSetting
-
getDefaultSetting
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
-
getCustomSetting
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
-
setUseDefaultSettings
public static void setUseDefaultSettings(boolean use)Global sets which configuration settings to use.- Parameters:
use
- If set totrue
, then the default settings will be used; if set tofalse
, 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; iffalse
, the custom settings will be applied globally. This setting informs thegetSetting(String)
method.
-