public abstract class ConfigurationObject
extends java.lang.Object
implements java.io.Serializable
setValues(JSONObject, boolean, boolean, boolean) saves fields with MODIFIER.
Use Secret for fields that contain secrets. getPropertyValue(String) decrypts secrets before
returning and setProperty(String, String) encrypts secrets before setting. toJSON() returns
PLACEHOLDER_SECRET instead of secrets and
setValues(JSONObject, boolean, boolean, boolean) ignores PLACEHOLDER_SECRET.
Use toRawJSON() fromRawJSON(JSONObject) to handle configuration data without processing values.| Modifier and Type | Field and Description |
|---|---|
protected static char |
ARRAY_DELIMITER |
protected boolean |
cloned |
protected org.apache.commons.configuration.Configuration |
configuration |
protected java.util.Map<java.lang.String,java.lang.String> |
DEFAULT_PROPERTY_VALUE_MAP |
static java.lang.String |
ERROR_MISSING_KEY |
protected boolean |
fromTenant |
protected static char |
KEY_DELIMITER |
protected static char |
LIST_ESC_CHAR |
protected static java.lang.String |
LIST_SEPARATOR |
protected static int |
MODIFIER |
static java.lang.String |
PLACEHOLDER_SECRET |
protected java.util.Properties |
properties |
protected boolean |
returnCopyFromCache |
| Constructor and Description |
|---|
ConfigurationObject(org.apache.commons.configuration.Configuration configuration,
java.lang.String idPrefix,
java.lang.String objectId)
Constructor method that it uses configuration type in the concrete subclass, idPrefix and objectID to form a
unique key to retrieve from DB in method load.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addIdNameToJSONModel(com.ibm.json.java.JSONObject model,
boolean readOnly)
Adds the ID and name fields to the JSON model.
|
void |
addValueToList(java.lang.String key,
java.lang.String value) |
java.lang.String |
arrayToString(java.util.List<java.lang.String> list)
Convert a list to a string.
|
java.lang.String |
arrayToString(java.lang.String[] array)
Convert an array object to a string.
|
java.lang.Object |
clone() |
java.lang.String |
covertEmptyStringtoNull(java.lang.String value)
Utility method to convert a string to null if it is empty.
|
protected com.ibm.json.java.JSONObject |
createJSONModelField(java.lang.Object value,
boolean readOnly,
boolean disabled)
Creates a field for a JSON model used to populate a stateful client-side model.
|
protected com.ibm.json.java.JSONObject |
createJSONModelToggleField(java.lang.Object value,
boolean readOnly,
boolean disabled,
boolean checked)
Creates a field with toggle capability for a JSON model used to populate a stateful client-side model.
|
protected com.ibm.json.java.JSONObject |
createJSONModelValidationField(java.lang.Object value,
boolean readOnly,
boolean disabled,
boolean required,
java.lang.String pattern)
Creates a field with validation for a JSON model used to populate a stateful client-side model.
|
void |
delete()
Remove this configuration object from the DB.
|
void |
dump(java.io.OutputStreamWriter osw)
Dumps the configuration to the specified output stream (used for logging and export)
|
void |
fromJSONModel(com.ibm.json.java.JSONObject jsonObj,
boolean forceUpdate,
boolean skipEncoding)
Reads a JSON model object and populates the configuration properties.
|
boolean |
getBooleanPropertyValue(java.lang.String key)
Return the value back from the properties as a boolean.
|
org.apache.commons.configuration.Configuration |
getConfigurationObject()
Return configuration object back.
|
protected java.lang.Class |
getDataType(java.lang.String key)
Returns the datatype of a configuration property.
|
java.lang.Object |
getDataTypeValue(java.lang.String field)
Returns the field's value as per the field's data type.
|
double |
getDoublePropertyValue(java.lang.String key)
Return the value back from the properties as a double.
|
java.lang.String |
getIdPrefix()
Return the application name used as ID prefix.
|
int |
getIntPropertyValue(java.lang.String key)
Return the value back from the properties as an int.
|
java.lang.String |
getKey()
Return the key value back by combined configuration type, ID prefix and ID.
|
java.util.Collection |
getList(java.lang.String type,
java.lang.String appName,
javax.servlet.http.HttpServletRequest request)
Abstract method that needs to be override in concrete class to a return a collection back by type.
|
long |
getLongPropertyValue(java.lang.String key)
Return the value back from the properties as a long.
|
<V extends ConfigurationObject> |
getMap(java.lang.Class<V> configClass,
java.lang.String idPrefix,
java.lang.String[] ids,
boolean... flags)
Return a map of configuration object identified by ids field back.
|
java.lang.String |
getName() |
java.lang.String |
getObjectId()
Return the object ID back.
|
java.lang.String |
getObjectIdAlias() |
abstract java.lang.String |
getObjectType()
Abstract method to return object type.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getPropertyNames()
Return a map of string of all the fields name in the class where field is a private static final string
|
java.lang.String |
getPropertyValue(java.lang.String key)
Return the value back from the properties.
|
int |
getPropertyValue(java.lang.String key,
int defaultValue) |
long |
getPropertyValue(java.lang.String key,
long defaultValue) |
java.lang.String |
getPropertyValue(java.lang.String key,
java.lang.String defaultValue) |
boolean |
hasProperties() |
boolean |
isEmpty()
Deprecated.
Use either hasProperties() or isNew() instead.
|
boolean |
isNew() |
void |
load()
Retrieves the latest version from the configuration store.
|
void |
performSyncedUpdate(SyncedUpdateHandlerInterface handler) |
protected java.lang.String |
propertiesToString(java.util.Properties properties)
Serialized properties object value to a string.
|
void |
removeValuesFromList(java.lang.String key,
java.util.List<java.lang.String> deleteValues)
Remove values from the properties object.
|
protected void |
removeValuesFromList(java.lang.String key,
java.util.List<java.lang.String> deleteValues,
java.util.Properties props) |
protected void |
resetNonTenantSettings() |
boolean |
returnCopyFromCache()
Return whether or not a copy of this configuration object should be returned from cache.
|
void |
save()
Saves the object back to the configuration store.
|
protected void |
setDefaultValue(java.lang.String propertyName,
java.lang.String defaultValue)
Set the default value if not found in the properties object
|
protected void |
setProperties(java.util.Properties properties) |
void |
setProperty(java.lang.String key,
java.lang.String value)
Store value into properties directly.
|
void |
setValues(com.ibm.json.java.JSONObject json) |
void |
setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate) |
void |
setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate,
boolean isJSONModel) |
void |
setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate,
boolean skipEncoding,
boolean isJSONModel)
Used by the configuration action for example addConfiguration to store value into properties object.
|
protected boolean |
skipThisPropertyWhenSaving(java.lang.String key)
Skip this property in saving if return value is true.
|
java.lang.String[] |
stringToArray(java.lang.String string)
Convert string value to an array object.
|
java.util.List |
stringToList(java.lang.String string)
Convert string value to a list object.
|
com.ibm.json.java.JSONObject |
toJSON()
Convert this configuration object to JSON object to be stream back to client.
|
com.ibm.json.java.JSONObject |
toJSON(boolean includeDependencies)
Convert this configuration object and its dependencies to JSON object to be stream back to client.
|
com.ibm.json.java.JSONObject |
toJSONModel()
Creates a new JSON model object, used to enable model binding in the user interface.
|
java.lang.String |
toString()
Override to return the object ID of this configuration back.
|
void |
validate() |
void |
validateObjectId() |
static <V extends ConfigurationObject> |
writeConfigurationToFile(java.io.OutputStreamWriter osw,
java.util.Collection<V> configList)
Write the configuration object out to the write object
|
public static final java.lang.String ERROR_MISSING_KEY
protected static final char ARRAY_DELIMITER
protected static final char KEY_DELIMITER
protected static final char LIST_ESC_CHAR
protected static final java.lang.String LIST_SEPARATOR
protected static final int MODIFIER
public static final java.lang.String PLACEHOLDER_SECRET
protected transient org.apache.commons.configuration.Configuration configuration
protected java.util.Properties properties
protected boolean cloned
protected boolean fromTenant
protected boolean returnCopyFromCache
protected java.util.Map<java.lang.String,java.lang.String> DEFAULT_PROPERTY_VALUE_MAP
public ConfigurationObject(org.apache.commons.configuration.Configuration configuration,
java.lang.String idPrefix,
java.lang.String objectId)
configuration - - A @{org.apache.commons.configuration.Configuration} object.idPrefix - - A string value of application name.objectId - - A string value of object ID.public void validateObjectId()
public org.apache.commons.configuration.Configuration getConfigurationObject()
public abstract java.lang.String getObjectType()
public java.lang.String getName()
public boolean returnCopyFromCache()
public java.lang.String getObjectId()
public java.lang.String getObjectIdAlias()
public java.lang.String getIdPrefix()
public java.lang.String getKey()
public java.util.Collection getList(java.lang.String type,
java.lang.String appName,
javax.servlet.http.HttpServletRequest request)
type - - A string value of object type.appName - - A string value of application name.request - - A HttpServletRequest object.protected void setProperties(java.util.Properties properties)
public void performSyncedUpdate(SyncedUpdateHandlerInterface handler)
public void load()
public void validate()
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic void save()
throws org.apache.commons.configuration.ConfigurationException
org.apache.commons.configuration.ConfigurationExceptionpublic void dump(java.io.OutputStreamWriter osw)
throws java.io.IOException
osw - - the output stream writer to be used for the config dump and it has to use "ISO-8859-1" encoding to
preserve localized labeljava.io.IOExceptionpublic static <V extends ConfigurationObject> void writeConfigurationToFile(java.io.OutputStreamWriter osw, java.util.Collection<V> configList) throws java.io.IOException, java.io.FileNotFoundException
osw - - OutputStreamWriter to be used for the config dump and it has to use "ISO-8859-1" encodingconfigList - - a collection of objects inherited from ConfigurationObject for example DesktopConfig.java.io.IOExceptionjava.io.FileNotFoundExceptionpublic void delete()
public boolean isEmpty()
public boolean isNew()
public boolean hasProperties()
public java.util.List stringToList(java.lang.String string)
string - - A value that needs to be parsed.public java.lang.String[] stringToArray(java.lang.String string)
string - - A value that needs to be parsed.public java.lang.String arrayToString(java.lang.String[] array)
array - - An array of stringpublic java.lang.String arrayToString(java.util.List<java.lang.String> list)
list - A string listprotected boolean skipThisPropertyWhenSaving(java.lang.String key)
key - - A string value of property name.protected java.lang.String propertiesToString(java.util.Properties properties)
properties - public java.lang.String covertEmptyStringtoNull(java.lang.String value)
value - - A string value that needs to be converted.public <V extends ConfigurationObject> java.util.Map<java.lang.String,V> getMap(java.lang.Class<V> configClass, java.lang.String idPrefix, java.lang.String[] ids, boolean... flags)
configClass - - A configuration class object.idPrefix - - A string value of ID prefix.ids - - A array of ID. All ID in this array expected to be the same type identify by the configClass
parameter.flags - - A optional flags to skip caching. Default is true.public java.lang.Object getDataTypeValue(java.lang.String field)
public com.ibm.json.java.JSONObject toJSON()
public com.ibm.json.java.JSONObject toJSON(boolean includeDependencies)
public com.ibm.json.java.JSONObject toJSONModel()
protected com.ibm.json.java.JSONObject createJSONModelField(java.lang.Object value,
boolean readOnly,
boolean disabled)
value - Value of the field being created.readOnly - Boolean indicating if the field is readOnly.disabled - Boolean indicating if the field is disabled.protected com.ibm.json.java.JSONObject createJSONModelValidationField(java.lang.Object value,
boolean readOnly,
boolean disabled,
boolean required,
java.lang.String pattern)
value - Value of the field being created.readOnly - Boolean indicating if the field is readOnly.disabled - Boolean indicating if the field is disabled.required - Boolean indicating if the field is required.pattern - String containing a pattern to apply to the field.protected com.ibm.json.java.JSONObject createJSONModelToggleField(java.lang.Object value,
boolean readOnly,
boolean disabled,
boolean checked)
value - Value of the field being created.readOnly - Boolean indicating if the field is readOnly.disabled - Boolean indicating if the field is disabled.checked - Boolean indicating if the field is checked.protected void addIdNameToJSONModel(com.ibm.json.java.JSONObject model,
boolean readOnly)
model - Model to update.protected java.lang.Class getDataType(java.lang.String key)
key - ths name of the propertypublic void setProperty(java.lang.String key,
java.lang.String value)
key - - A string value of property name.value - - A string value of valuepublic java.lang.String getPropertyValue(java.lang.String key)
key - - A string value of property name.public boolean getBooleanPropertyValue(java.lang.String key)
key - - A string value of property name.public int getIntPropertyValue(java.lang.String key)
key - - A string value of property name.public long getLongPropertyValue(java.lang.String key)
key - - A string value of property name.public double getDoublePropertyValue(java.lang.String key)
key - - A string value of property name.public java.lang.String getPropertyValue(java.lang.String key,
java.lang.String defaultValue)
public int getPropertyValue(java.lang.String key,
int defaultValue)
public long getPropertyValue(java.lang.String key,
long defaultValue)
protected java.util.Map<java.lang.String,java.lang.String> getPropertyNames()
public void setValues(com.ibm.json.java.JSONObject json)
json - public void setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate)
json - public void setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate,
boolean isJSONModel)
public void setValues(com.ibm.json.java.JSONObject json,
boolean forceUpdate,
boolean skipEncoding,
boolean isJSONModel)
json - - A JSON object.forceUpdate - - Set this value even there is no matching published property.skipEncoding - - If true, backslashes are not encodedpublic void fromJSONModel(com.ibm.json.java.JSONObject jsonObj,
boolean forceUpdate,
boolean skipEncoding)
jsonObj - public void removeValuesFromList(java.lang.String key,
java.util.List<java.lang.String> deleteValues)
key - - A string of property name that identified a list.deleteValues - - values need to be removed.protected void removeValuesFromList(java.lang.String key,
java.util.List<java.lang.String> deleteValues,
java.util.Properties props)
public void addValueToList(java.lang.String key,
java.lang.String value)
key - Key field name.value - Key.protected void setDefaultValue(java.lang.String propertyName,
java.lang.String defaultValue)
propertyName - - A string value of property name.defaultValue - - A string value of default value if not found.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedExceptionprotected void resetNonTenantSettings()
throws org.apache.commons.configuration.ConfigurationException
org.apache.commons.configuration.ConfigurationException