Class AbstractConfigurationElement
- java.lang.Object
-
- com.microstrategy.utils.config.AbstractConfigurationElement
-
- All Implemented Interfaces:
ConfigurationElement
,ConfigurationFile
,java.lang.Cloneable
- Direct Known Subclasses:
AbstractConfigurationElementList
,AbstractElementList
,AbstractStyleCatalogElement
,ActualParameterInfo
,AddonInfo
,AdminServer
,AggregatingTaskFactoryConfig
,ApplicationParameters
,AppschemaDisabledSourceInfo
,AreaLayerInfo
,ArgumentInfo
,BaseMapInfo
,BeanFactory.BeanFactoryInfo
,BeanFactory.BeanMappingInfo
,BeanFactory.BeanPackageInfo
,BeanInfo
,BlockConfig
,BlockLibraryConfig
,BrowserSettingDefinition
,ClientSideLayout
,ConnectionInfo
,ContentType
,ContextMenuInfo
,ControllerInfo
,CustomThreshold
,CustomThresholdBand
,CustomThresholdsInfo
,DBIDInfo
,DBInfo
,DBParamValInfo
,DBPreferenceInfo
,DBPreferenceItem
,DBPropertiesInfo
,DBTypeInfo
,DBVersionInfo
,DBVLDBProperty
,Domain
,DropZone
,DropZonesResolution
,ErrorInfo
,ErrorInfo.ErrorMessage
,ErrorInfo.ErrorTitle
,ESRICloudAppInfo
,ESRICloudAppKeyInfo
,ESRICloudAppsInfo
,ESRIJSAPIUrlInfo
,ESRIOnPremiseAttributeInfo
,ESRIOnPremiseMapLayerUrlInfo
,ESRIOnPremiseQueryFieldInfo
,ESRIProxyURL
,ESRIWebMapInfo
,EventArgumentInfo
,EventHandlerInfo
,EventHandlerInfo
,EventInfo
,EventMap
,EventMap.EventMapArgument
,ExportFormat
,ExportPlaintextDelimiter
,FlagInfo
,FolderLink
,FolderMapping
,GeoRoleInfo
,GeoShapeInfo
,GoogleChannel
,GoogleConfigurationInfo
,GoogleMapKeyInfo
,GraphFormatInfoHelper.Attribute
,GraphFormatInfoHelper.Exception
,GraphFormatInfoHelper.GraphAttribute
,GraphFormatInfoHelper.GraphFormatInfo
,GraphFormatInfoHelper.GraphMajorType
,GraphFormatInfoHelper.GraphMinorType
,GraphFormatInfoHelper.GraphObject
,GraphFormatInfoHelper.IncludeType
,IncludeBlock
,IncludeDir
,JavaScriptInfo
,Macro
,MapBoxConfigurationInfo
,MapBoxTokenInfo
,MapStyle
,MapStyleJson
,MessageInfoImpl
,MessagesManager
,MicrostrategyAttributeInfo
,MultiMapConfigurationInfo
,PageInfo
,PageManager
,PaperSizes
,ParameterInfo
,ParameterInfo.Description
,Properties
,Property
,PropertyValue
,ResourceFeedConfig
,RibbonInfo
,SectionInfo
,ShapeConfigurationInfo
,ShapeFileMap
,ShapeKeyInfo
,Shortcut
,ShortcutArgument
,ShortcutEvent
,StaticSession
,SysFolderBlackListHelper.SystemFolderNode
,TaskFactoryInfo
,TaskFactoryParam
,TaskInfo
,TaskParameterMetadataImpl
,TemplateInfo
,Transition
,UpdateFilterInfo
,Visualization
,VisualizationGallery
,VisualizationTemplate
,VisualizationTemplateId
,WebBeanInfo
,WebBeanProperty
,WebBeanStyle
,WebGuiComponent
,WebLoginProviderInfo
,WhiteListCommandHelper.WhiteListCommand
,WhiteListCommandHelper.WhiteListCommandInfo
,Widget
,WidgetProp
public abstract class AbstractConfigurationElement extends java.lang.Object implements ConfigurationElement, ConfigurationFile, java.lang.Cloneable
The AbstractConfigurationElement is the abstract class that represent a
ConfigurationElement
, that is, a class that can be configured using an external file. It supports reading the definition from an XML file. It also supports loading the definition from multiple configuration sources (i.e., supports customizations).In its constructor, a subclass registers what are the valid children it may have through 2 methods:
registerElement(String nodeName, Class class)
: used for those nodes that can appear only once.registerElementList(String nodeName, Class class)
: used for those that can appear multiple times as part of a list.
By default, if the attribute was not present in the xml configuration getAttribute() returns null. If the subclass requires that an attribute has a default value other than null, it can be done by extending the
initDefaultAttributes()
method and setting the attribute value there.Subclasses also need to implement the
getKeyAttribute
method to indicate the attribute that can uniquely identify this element within a list. If the Element is not intended to be used in a list, or if it uses more than one attribute as key this method should simply return null, and if necessary implement thegetKey():Object
method.The
AbstractConfigurationElement
also implements theConfigurationFile
interface used to load, reload, save and applyCustomizations, therefore all subclasses can be saved independently in a configuration file.- Since:
- MicroStrategy Web 9.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractConfigurationElement.FilteredList
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
ATT_CONFIG_SRC
protected static java.lang.String
ATT_DELETED
protected static java.lang.String
ATT_POSITION
protected static java.lang.String
ATT_PROTOTYPE
static java.lang.String
ATT_USE_DEFAULT
Defines the "use-default" attribute.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConfigurationElement()
Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
addFileSource(java.lang.String filePath, java.lang.String appPath, long lastLoaded)
Adds a reference to a file from a config-source.void
applyCustomization(CustomizationInfo c)
Applies the corresponding customizations.void
applyCustomizations()
Loops through all theCustomizationInfo
in theCustomizations
class and apply the corresponding customizations.void
cleanUpDeletedElements()
This method when called will delete all the child elements that are marked as deleted.java.lang.Object
clone()
void
delete(java.lang.Object key)
AbstractConfigurationElement
deltas()
AbstractConfigurationElement
deltas(AbstractConfigurationElement other)
Returns a partial instance of this object that contains the attributes and elements required to make this object equals to theother
paramter.protected boolean
equalAtts(AbstractConfigurationElement other)
Returnstrue
if the list of active attributes of the given AbstractConfigurationElement is equal to this list of active attributes of this AbstractConfigurationElement.protected boolean
equalElements(AbstractConfigurationElement other)
Returnstrue
if the list of all child elements of the given AbstractConfigurationElement is equal to this list of all child-elements of this AbstractConfigurationElement.protected boolean
equalNodeValues(AbstractConfigurationElement other)
Returnstrue
if the node value of both configuration elements is the same.boolean
equals(java.lang.Object object)
boolean
equalsIncludingDeletedElements(java.lang.Object object)
protected void
exportAttributesToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the list of attributes of thisConfigurationElement
into the given node.protected void
exportElementsToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the list of child-elements of thisConfigurationElement
into the given node.protected void
exportNodeValueToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the node value associated with the given source key into the given node.ConfigurationValue
getAttribute(java.lang.String name)
Returns the value associated with the given attribute.HashList
getAttributes()
Returns the list of all attributes available to this ConfigurationElement.protected boolean
getBoolAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as boolean (true/false).protected java.lang.Object
getChildKey(org.w3c.dom.Node node)
Returns the key that uniquely identifies the child element associated with the givenNode
.java.lang.String
getConfigSrc()
Returns the value of the config-src attribute.protected java.lang.String
getDTDFileName()
Returns the name of a DTD file that will be added as SystemID to the XML resulting from serializing the contents of this ConfigurationElement into a file;null
by default.ConfigurationElement
getElement(java.lang.Object key)
Returns theConfigurationElement
instance associated with the given nodeName.protected ConfigurationElement
getElement(java.lang.Object key, boolean includeDeleted)
HashList
getElements()
Returns the list of all child-elements available to this ConfigurationElement.FileLoader
getFileLoader()
Returns the file loader instance used by this ConfigurationElement to load files from the file system.protected int
getIntAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as integer.protected int
getIntAttribute(java.lang.String name, int defaultValue)
Helper method, returns the value of the given attribute as integer.java.lang.Object
getKey()
Default implementation forgetKey()
.protected abstract java.lang.String
getKeyAttribute()
This method must return the attribute that uniquely identifies this element among its siblings; if no single attribute can be used, return null and override thegetKey
andsetKey
methods.int
getLineNumber()
Returns the line number (if known) of the element in the XML file.protected AbstractConfigurationElement.FilteredList
getList(java.lang.String nodeName)
Returns anImplicitList
with all the elements associated with the givennodeName
.java.lang.Object
getNextKey()
Returns an object that can be used as key for a list of child-elements that doesn't have a key by itself.java.lang.String
getNodeName()
Returns the node-name for this element.java.lang.String
getNodeValue()
Returns the node value for this element.protected java.lang.String
getNodeValue(ConfigurationSource source)
Returns the node value for this element in the given sourceKey.protected AbstractConfigurationElement
getOrCreateElement(java.lang.String nodeName, java.lang.Object key)
Returns the current child instance; if null but the child is registered, it creates a new instance for it.AbstractConfigurationElement
getParent()
Gets the parent for this configuration element.int
getPosition()
Returns the expected position of this element.protected AbstractConfigurationElement
getPrototype()
Returns the current prototype of this instance.protected java.lang.Class
getRegisteredClass(java.lang.String nodeName)
Returns theClass
associated with the givennodeName
.java.lang.String
getSelfInitPath()
Returns the path to the file where this configuration element was originally loaded from.protected ConfigurationSource
getSource(java.lang.String key)
Gets theElementSource
for the given key.java.lang.String
getStrAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as a string.boolean
getUseDefault()
Returns the use-default value.protected ParserParameters
getXMLParserParameters(java.lang.String fileName)
Returns an instance ofParserParameters
used by the XML parser.protected SerializerParameters
getXMLSerializerParameters()
Returns an instance ofSerializerParameters
used by the XML serializer in thetoXML(org.w3c.dom.Document)
By default it returnsnull
.int
hashCode()
protected int
hashCodeAtts()
Returns the hashcode for attributes.protected int
hashCodeElements()
Returns the hashcode for attributes.protected int
hashCodeNodeValues()
Returns the hashcode for attributes.protected boolean
hasRegisteredClass(java.lang.String nodeName)
Returnstrue
is there is a child registered for the givennodeName
.protected void
initAttributesFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)
Initializes the list of attributes from givenNode
protected void
initDefaultAttributes()
This method can be overridden to set default values for attributes.protected void
initElementFromXML(org.w3c.dom.Node child, java.lang.String sourceKey, CustomizationInfo c)
Initializes a single child-element from the givenNode
protected void
initElementsFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)
Initializes the list of child-elements from givenNode
protected void
initFromFile(java.lang.String filePath, CustomizationInfo c)
Initializes this configuration element by loading the contents of the givenfilePath
using the correspondingCustomizationInfo
.void
initFromResource(java.lang.String resourceName)
Initializes this configuration element by loading the contents a resource that exists in the class path.void
initFromXML(org.w3c.dom.Node root)
Initialize the attributes and child elements from the values in the givenNode
protected void
initFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)
Initialize the attributes and child elements from the values in the givenNode
protected void
initNodeValueFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)
Initializes the list of child-elements from givenNode
protected void
initPrototype(java.lang.String protoName)
Inits the prototype object of this element.boolean
isActive()
boolean
isCustomized()
boolean
isDeleted()
Returnstrue
is this element has been mark as deleted.boolean
isDirty()
Returnstrue
is this element or one of its children has been modified programatically after being loaded.protected boolean
isInSource(java.lang.String sourceKey)
Returnstrue
if the element already contains anElementSource
for the given key.protected boolean
isKeyAttribute(java.lang.String name)
Returnstrue
is the name is that of the key attribute.void
load(java.lang.String fileName)
Loads the file with the given name and initializes thisConfigurationElement
with its content.protected void
mergeChanges(java.lang.String srcKey)
Removes deltas and applies them to the given source.protected AbstractConfigurationElement
newChildInstance(java.lang.String nodeName, java.lang.Class childClass)
Creates a new instance of a child element for the given class.protected ConfigurationSource
newSource(java.lang.String srcKey, CustomizationInfo c)
Create a newElementSource
and adds to the list of sources of this element.AbstractConfigurationElement
original()
Returns a new instance of this object, populated only with the out of the box values of Microstrategy Web, that is, only default values or those that came from the load method.ConfigurationElement
populate(ConfigurationElement other)
This method takes another configuration element and populates this element with the other's attributes and child-elements.protected void
printAttributes(java.lang.StringBuffer outString)
Appends the list of attributes of thisConfigurationElement
into the givenStringBuffer
.protected void
printElements(java.lang.StringBuffer outString)
Appends the list of child-elements of thisConfigurationElement
into the givenStringBuffer
.protected void
printNodeValue(java.lang.StringBuffer outString)
Appends the node value into the givenStringBuffer
.protected void
refreshLists()
protected void
registerClass(java.lang.String nodeName, java.lang.Class c)
Registers a child class for the child with the givennodeName
.protected void
registerElement(java.lang.String nodeName, java.lang.Class c)
Register a child of thisConfigurationElement
.protected void
registerElement(java.lang.String nodeName, java.lang.Class c, boolean canBeNull)
Register a child of thisConfigurationElement
.protected void
registerElementList(java.lang.String nodeName, java.lang.Class c)
Register a list of thisConfigurationElement
.void
reload()
Loops through all theElementSource
of thisConfigurationElement
and reloads the content of those whose underlying configuration file has changed.protected void
reloadPrototype()
Loops through all theElementSource
of thisConfigurationElement
and reloads the content of those whose underlying configuration file has changed.protected void
removeAttribute(java.lang.String name)
Completely remove the value for the given attribute.protected void
removeDefaults(CustomizationInfo c)
This method is called when the use-default attribute is set false, so all previous values of attributes and children must be cleared.void
replaceList(AbstractConfigurationElement.FilteredList list)
void
restore(java.lang.Object key)
void
save()
Saves thisConfigurationElement
back into the files where it was loaded from.void
save(CustomizationInfo c)
Saves deltas for thisConfigurationElement
into the given CustomizationInfo.void
saveChangesAs(java.lang.String fileName)
Saves all in-memory changes to the given file.void
saveConfig(java.lang.String filePath)
Deprecated.To save in a different location, set a custom FileLoader and use the save() method.void
saveFlatXML(java.lang.String fileName)
Saves the current element structure, in XML format, into the given file.protected void
saveNode(org.w3c.dom.Node node, java.lang.String fileLocation)
Saves an XML node into a file in the given location.protected void
saveSource(ConfigurationSource source)
Saves only the contents associated with the given source.protected void
setAttribute(java.lang.String name, java.lang.Object value)
Sets the value for the given attribute.protected void
setBoolAttribute(java.lang.String name, boolean value)
Helper method, sets the value of the given attribute from a boolean.protected void
setChildOriginals()
void
setConfigSrc(java.lang.String path)
Sets the config-src attribute.void
setCustomized(boolean value)
set if this element is a customized element or not.protected void
setElement(java.lang.Object key, ConfigurationElement child)
Allows users to add or replace an element.void
setFileLoader(FileLoader fl)
Sets theFileLoader
instance to be used to load files.protected void
setIntAttribute(java.lang.String name, int value)
Helper method, sets the value of the given attribute from an integer.protected void
setKey(org.w3c.dom.Element element)
Default implementation forsetKey()
.void
setLineNumber(int lineNumber)
Sets the line number of the element in the XML file.protected void
setNodeName(java.lang.String name)
Sets the name of the node associated with this configuration element.protected void
setNodeValue(java.lang.String value)
Returns the node value for this element.void
setPosition(int position)
Sets the expected position of this element.protected void
setPrototype(AbstractConfigurationElement prototype)
Sets the prototype object for this instance.protected void
setSelfInitPath(java.lang.String value)
protected void
setStrAttribute(java.lang.String name, java.lang.String value)
Helper method, sets the value of the given attribute as a string.void
setUseDefault(boolean useDefault)
The definition of a ConfigurationElement can come come from different sources, for example, the definition can come from an external file (by specifying agetConfigSrc()
value), or it can be modified through a Customization.void
setUseValidation(boolean value)
Defines whether the XML content should validated using a DTD.protected boolean
throwConfigParseException()
Control whether to throw configuration parse exception DE20651: Do not throw exception for viz configurations to avoid error / empty on Main pages.java.lang.String
toString()
Generates the String representation of thisConfigurationElement
.org.w3c.dom.Element
toXML()
Generates the DOM representation of thisConfigurationElement
.protected org.w3c.dom.Element
toXML(java.lang.String sourceKey)
Generates the DOM representation of thisConfigurationElement
for the list of attributes and elements defined in the givenElementSource
.org.w3c.dom.Element
toXML(org.w3c.dom.Document doc)
Generates the DOM representation of thisConfigurationElement
.protected org.w3c.dom.Element
toXML(org.w3c.dom.Document doc, java.lang.String sourceKey)
Generates the DOM representation of thisConfigurationElement
for the list of attributes and elements defined in the givenElementSource
.protected boolean
useNodeValue()
Controls whether this element will use the node value as a property.boolean
useValidation()
Returns whether the XML content should be validated using a DTD.
-
-
-
Field Detail
-
ATT_DELETED
protected static final java.lang.String ATT_DELETED
- See Also:
- Constant Field Values
-
ATT_CONFIG_SRC
protected static final java.lang.String ATT_CONFIG_SRC
- See Also:
- Constant Field Values
-
ATT_PROTOTYPE
protected static final java.lang.String ATT_PROTOTYPE
- See Also:
- Constant Field Values
-
ATT_USE_DEFAULT
public static final java.lang.String ATT_USE_DEFAULT
Defines the "use-default" attribute.- See Also:
setUseDefault(boolean)
, Constant Field Values
-
ATT_POSITION
protected static final java.lang.String ATT_POSITION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractConfigurationElement
protected AbstractConfigurationElement()
Default constructor. CallsinitDefaultAttributes()
-
-
Method Detail
-
getNodeName
public java.lang.String getNodeName()
Description copied from interface:ConfigurationElement
Returns the node-name for this element.- Specified by:
getNodeName
in interfaceConfigurationElement
-
setNodeName
protected void setNodeName(java.lang.String name)
Sets the name of the node associated with this configuration element.
-
getParent
public AbstractConfigurationElement getParent()
Gets the parent for this configuration element. Returnsnull
if it's a root or if it's still not associated to any element.
-
registerElement
protected void registerElement(java.lang.String nodeName, java.lang.Class c)
Register a child of thisConfigurationElement
. When a child is registered with this method it is guaranteed that a non-null instance of this child is returned by thegetElement(java.lang.Object)
method regardless of the child being present in the XML or not.
-
registerElement
protected void registerElement(java.lang.String nodeName, java.lang.Class c, boolean canBeNull)
Register a child of thisConfigurationElement
. When a node with the given name is found in the configuration file, an instance ofc
is created and initialized with the corresponding configuration. It's assumed that only one child with this name is available in the configuration file; if more than one is found, the corresponding nodes are merged into a singleConfigurationElement
.
The
canBeNull
parameter controls whether the child instance is created by default or not. Whenfalse
, thegetElement(java.lang.Object)
will always return a non-null instance even if the child is not in the XML; iftrue
the child instance is only created if the object is found in the XML, in this casenull
checks are necessary in your code after callinggetElement
to make sure the return object is not null.
Only elements registered with this and with theregisterElementList(java.lang.String, java.lang.Class)
methods are valid child nodes in the configuration file. If a child has not been registered, WARNING messages will be logged.
This method should only be called in the constructor, otherwise the clone method will fail. It can only be called if theuseNodeValue()
method returns false as they are mutually exclusive: by design an element can only use children if its not using the node value.
Currently it is required that all registered child elements extendAbstractConfigurationElement
. If the given classc
doesn't, this method will throw anIllegalArgumentException
.- See Also:
getElement(java.lang.Object)
-
registerClass
protected void registerClass(java.lang.String nodeName, java.lang.Class c)
Registers a child class for the child with the givennodeName
. Used to keep track of those children than can havenull
values.
-
hasRegisteredClass
protected boolean hasRegisteredClass(java.lang.String nodeName)
Returnstrue
is there is a child registered for the givennodeName
.
-
getRegisteredClass
protected java.lang.Class getRegisteredClass(java.lang.String nodeName)
Returns theClass
associated with the givennodeName
.
-
registerElementList
protected void registerElementList(java.lang.String nodeName, java.lang.Class c)
Register a list of thisConfigurationElement
. When a node with the given name is found in the configuration file, an instance ofc
is created and initialized with the corresponding configuration. If more than one subnodes are found with this name, one instance for each is created and all of them are added as child of thisConfigurationElement
. The list can then be accessed through thegetList(java.lang.String)
method.
Only elements registered with this and with theregisterElement(java.lang.String, java.lang.Class)
methods are valid child nodes in the configuration file.
This method should only be called in the constructor, otherwise the clone method will fail. It can only be called if theuseNodeValue()
method returns false as they are mutually exclusive: by design an element can only use children if its not using the node value.
Currently it is required that all registered child elements extendAbstractConfigurationElement
. If the given classc
doesn't, this method will throw anIllegalArgumentException
.
-
useNodeValue
protected boolean useNodeValue()
Controls whether this element will use the node value as a property. For example, nodes defined as:
can expose a property which will return the node's value (This is the node vale). When this is the case, though, the element can't have any sub elements. They're mutually exclusive.<a att="1">This is the node value</a>
- Returns:
false
by default. Override this method if you want to associate the node value with some property.
-
initDefaultAttributes
protected void initDefaultAttributes()
This method can be overridden to set default values for attributes. Simply extend this method and callsetAttribute(java.lang.String, java.lang.Object)
-
getConfigSrc
public java.lang.String getConfigSrc()
Returns the value of the config-src attribute. This attribute indicates a file path where the definition of this attribute will be loaded from or saved into.
-
setConfigSrc
public void setConfigSrc(java.lang.String path)
Sets the config-src attribute. If setting it to a non-null value, the definiton of this configuration element will be saved into this location.
-
setUseDefault
public void setUseDefault(boolean useDefault)
The definition of a ConfigurationElement can come come from different sources, for example, the definition can come from an external file (by specifying agetConfigSrc()
value), or it can be modified through a Customization. When theuseDefault
is set to false, values that come from previous sources are ignored and only the definition from the current source is used; this includes all attributes and child elements of this element. This is especially useful in customizations to replace the out of the box values of a node with a new definition.- Parameters:
useDefault
- true/false value
-
getUseDefault
public boolean getUseDefault()
Returns the use-default value.- Returns:
- the true/false value of the useDefault flag of this Configuration Element
- See Also:
setUseDefault(boolean)
-
getPosition
public int getPosition()
Returns the expected position of this element. If the position should be automatically infered from the position found in the XML, it returns -1. This value is stored in the "position" attribute of the node. Notice that the actual position of this element might differ from this value, as the position attribute is not guaranteed to be unique or correct.
-
setPosition
public void setPosition(int position)
Sets the expected position of this element. The value is stored in the "position" attribute of the node. If when calling this method, this instance is a member of an ImplicitList, the element will automatically reposition itself in this list. Setting -1 as position indicates to automatically position this element based on its position in the XML.
-
getKey
public java.lang.Object getKey()
Default implementation forgetKey()
. It assumes a single attribute can be used to uniquely identify this element among its siblings; the attribute to use is specified by thegetKeyAttribute()
method.- Specified by:
getKey
in interfaceConfigurationElement
- Returns:
- If
getKeyAttribute()
is empty returnsnull
, otherwise it returns the value of the given attribute.
-
setKey
protected void setKey(org.w3c.dom.Element element)
Default implementation forsetKey()
. It assumes a single attribute can be used to uniquely identify this element among its siblings and adds this attribute to the given element; the attribute to use is specified by thegetKeyAttribute()
method.
-
getKeyAttribute
protected abstract java.lang.String getKeyAttribute()
This method must return the attribute that uniquely identifies this element among its siblings; if no single attribute can be used, return null and override thegetKey
andsetKey
methods.
-
getElements
public final HashList getElements()
Description copied from interface:ConfigurationElement
Returns the list of all child-elements available to this ConfigurationElement.- Specified by:
getElements
in interfaceConfigurationElement
-
getElement
public ConfigurationElement getElement(java.lang.Object key)
Returns theConfigurationElement
instance associated with the given nodeName. If theConfigurationElement
was not present in the xml configuration, this method might return an empty instance of the correspondingConfigurationElement
ornull
depending on thecanBeNull
parameter passed to theregisterElement(java.lang.String, java.lang.Class)
method. If a list is associated with the given nodeName, this method returns a list containing all theConfigurationElement
instances for that nodeName. If noConfigurationElement
is associated with the given nodeName, the method returns null.- Specified by:
getElement
in interfaceConfigurationElement
-
getElement
protected ConfigurationElement getElement(java.lang.Object key, boolean includeDeleted)
-
newChildInstance
protected AbstractConfigurationElement newChildInstance(java.lang.String nodeName, java.lang.Class childClass)
Creates a new instance of a child element for the given class.
-
setElement
protected void setElement(java.lang.Object key, ConfigurationElement child)
Allows users to add or replace an element. If an element with the given key already exists it gets replaced, otherwise it's simply added.
-
delete
public void delete(java.lang.Object key)
-
restore
public void restore(java.lang.Object key)
-
isActive
public boolean isActive()
-
refreshLists
protected void refreshLists()
-
getList
protected AbstractConfigurationElement.FilteredList getList(java.lang.String nodeName)
Returns anImplicitList
with all the elements associated with the givennodeName
. If no child was present in the xml configuration with this name, it will return an empty list. If thenodeName
has not been registered for a list, it throws anIllegalArgumentException
.
-
getAttributes
public HashList getAttributes()
Description copied from interface:ConfigurationElement
Returns the list of all attributes available to this ConfigurationElement.- Specified by:
getAttributes
in interfaceConfigurationElement
-
isKeyAttribute
protected boolean isKeyAttribute(java.lang.String name)
Returnstrue
is the name is that of the key attribute.
-
getNodeValue
public java.lang.String getNodeValue()
Returns the node value for this element. The node value represents the inner content of the xml tag. If multipleElementSources
are defined for this element, it returns the value of the one with greater priority.
-
getNodeValue
protected java.lang.String getNodeValue(ConfigurationSource source)
Returns the node value for this element in the given sourceKey. The node value represents the inner content of the xml tag.
If sourceKey is null, it returns the current value.
-
setNodeValue
protected void setNodeValue(java.lang.String value)
Returns the node value for this element. The node value represents the inner context of the xml tag. If multipleElementSources
are defined for this element, it returns the value of the one with greater priority.
-
getAttribute
public final ConfigurationValue getAttribute(java.lang.String name)
Returns the value associated with the given attribute. If the attribute was not present in the xml configuration the method returns null.- Specified by:
getAttribute
in interfaceConfigurationElement
-
setAttribute
protected void setAttribute(java.lang.String name, java.lang.Object value)
Sets the value for the given attribute.
-
removeAttribute
protected void removeAttribute(java.lang.String name)
Completely remove the value for the given attribute.
-
getStrAttribute
public java.lang.String getStrAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as a string.- Specified by:
getStrAttribute
in interfaceConfigurationElement
-
setStrAttribute
protected void setStrAttribute(java.lang.String name, java.lang.String value)
Helper method, sets the value of the given attribute as a string.
-
getIntAttribute
protected int getIntAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as integer. If the attribute has no value, it returnsInteger.MIN_VALUE
. If the attribute has a non-numeric value, it throws an IllegalArgumentException.
-
getIntAttribute
protected int getIntAttribute(java.lang.String name, int defaultValue)
Helper method, returns the value of the given attribute as integer. If the attribute has no value, it returns thedefaultValue
parameter. If the attribute has a non-numeric value, it throws an IllegalArgumentException.
-
setIntAttribute
protected void setIntAttribute(java.lang.String name, int value)
Helper method, sets the value of the given attribute from an integer.
-
getBoolAttribute
protected boolean getBoolAttribute(java.lang.String name)
Helper method, returns the value of the given attribute as boolean (true/false). If the attribute has no value it returnsfalse
; otherwise it returnsBoolean.valueOf(boolean)
.- See Also:
Boolean.valueOf(boolean)
-
setBoolAttribute
protected void setBoolAttribute(java.lang.String name, boolean value)
Helper method, sets the value of the given attribute from a boolean.
-
isDeleted
public boolean isDeleted()
Returnstrue
is this element has been mark as deleted.- See Also:
delete(Object)
-
isDirty
public boolean isDirty()
Returnstrue
is this element or one of its children has been modified programatically after being loaded.
-
newSource
protected ConfigurationSource newSource(java.lang.String srcKey, CustomizationInfo c)
Create a newElementSource
and adds to the list of sources of this element. If there is already anElementSource
for the given key, this method will return the same instance, but this should be avoided to prevent infinite recursive loops with the config-src attribute.
-
getSource
protected ConfigurationSource getSource(java.lang.String key)
Gets theElementSource
for the given key. If there is noConfigurationSource
for the given key, a new source is automatically added.
-
isInSource
protected boolean isInSource(java.lang.String sourceKey)
Returnstrue
if the element already contains anElementSource
for the given key.
-
initFromXML
public void initFromXML(org.w3c.dom.Node root)
Initialize the attributes and child elements from the values in the givenNode
- Specified by:
initFromXML
in interfaceConfigurationElement
- Parameters:
root
- Node intance representing the configuration element properties
-
initFromXML
protected void initFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigException
Initialize the attributes and child elements from the values in the givenNode
- Parameters:
root
- The DOM Node from where the information is readsourceKey
- The key that identifies theElementSource
where the values are being readc
- CustomizationInfo class where theElementSource
was loaded from.- Throws:
ConfigException
- If an error occurs while reading the definition, typically if there is a problem when reading the file pointed by the config-src attribute.
-
setChildOriginals
protected void setChildOriginals()
-
setCustomized
public void setCustomized(boolean value)
set if this element is a customized element or not. If user adds a new element it is considered a customized element and user needs to set this element as custom.- Parameters:
value
-
-
isCustomized
public boolean isCustomized()
- Returns:
- true - if it is a customized element false - if it is an OOTB element
-
initPrototype
protected void initPrototype(java.lang.String protoName)
Inits the prototype object of this element. This element will inherit all the attribute and child elements from the prototype, but then any values defined through the config-src file or inline take precedence over the prototype. The name attribute represents the name of the prototype as specified in the XML. Typically this is the name of a sibling node in the xml. If name is empty, a different sibling might be used as prototype (like in the case of the PageInfo, which the page marked as isDefault is used as the default prototype). If this object already has a prototype, or if the prototype is not found in the siblings collections this methods throws an Exception.- Parameters:
protoName
- Prototype name, typically the name of a sibling node in the xml.
-
setPrototype
protected void setPrototype(AbstractConfigurationElement prototype)
Sets the prototype object for this instance. The attributes and elements of the prototype are copied into this instance.
-
getPrototype
protected AbstractConfigurationElement getPrototype()
Returns the current prototype of this instance.- See Also:
initPrototype(java.lang.String)
-
removeDefaults
protected void removeDefaults(CustomizationInfo c)
This method is called when the use-default attribute is set false, so all previous values of attributes and children must be cleared.
-
initAttributesFromXML
protected void initAttributesFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c)
Initializes the list of attributes from givenNode
-
initElementsFromXML
protected void initElementsFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigException
Initializes the list of child-elements from givenNode
- Throws:
ConfigException
- See Also:
initFromXML(Node root, String sourceKey, CustomizationInfo c)
-
initNodeValueFromXML
protected void initNodeValueFromXML(org.w3c.dom.Node root, java.lang.String sourceKey, CustomizationInfo c) throws ConfigException
Initializes the list of child-elements from givenNode
- Throws:
ConfigException
- See Also:
initFromXML(Node root, String sourceKey, CustomizationInfo c)
-
initElementFromXML
protected void initElementFromXML(org.w3c.dom.Node child, java.lang.String sourceKey, CustomizationInfo c) throws ConfigException
Initializes a single child-element from the givenNode
- Throws:
ConfigException
-
getLineNumber
public int getLineNumber()
Returns the line number (if known) of the element in the XML file.- Returns:
- The line number (if known). Otherwise, return -1.
-
setLineNumber
public void setLineNumber(int lineNumber)
Sets the line number of the element in the XML file.- Parameters:
lineNumber
- The line number of this AbstractConfigurationElement in the XML file.
-
getOrCreateElement
protected AbstractConfigurationElement getOrCreateElement(java.lang.String nodeName, java.lang.Object key)
Returns the current child instance; if null but the child is registered, it creates a new instance for it.
-
throwConfigParseException
protected boolean throwConfigParseException()
Control whether to throw configuration parse exception DE20651: Do not throw exception for viz configurations to avoid error / empty on Main pages.
-
initFromFile
protected void initFromFile(java.lang.String filePath, CustomizationInfo c) throws ConfigException
Initializes this configuration element by loading the contents of the givenfilePath
using the correspondingCustomizationInfo
.- Throws:
ConfigException
-
addFileSource
protected void addFileSource(java.lang.String filePath, java.lang.String appPath, long lastLoaded)
Adds a reference to a file from a config-source. This file will then be automatically reloaded if changed and will be used when the save() method is called.
-
initFromResource
public void initFromResource(java.lang.String resourceName) throws ConfigException
Initializes this configuration element by loading the contents a resource that exists in the class path.- Throws:
ConfigException
-
getXMLParserParameters
protected ParserParameters getXMLParserParameters(java.lang.String fileName)
Returns an instance ofParserParameters
used by the XML parser. By default if using validation creates a new ParserParameters instance with a SimpleErrorHandler and FileLoaderEntityResolver; otherwise it returns null;
-
getXMLSerializerParameters
protected SerializerParameters getXMLSerializerParameters()
Returns an instance ofSerializerParameters
used by the XML serializer in thetoXML(org.w3c.dom.Document)
By default it returnsnull
. Override if the configuration element requires to pass different parameters than those used by default.
-
getDTDFileName
protected java.lang.String getDTDFileName()
Returns the name of a DTD file that will be added as SystemID to the XML resulting from serializing the contents of this ConfigurationElement into a file;null
by default. This method should be extended if the concrete instance of an element has a predefined DTD file associated.
-
setUseValidation
public void setUseValidation(boolean value)
Description copied from interface:ConfigurationFile
Defines whether the XML content should validated using a DTD.- Specified by:
setUseValidation
in interfaceConfigurationFile
- Parameters:
value
-true
requires that the XML is parsed with DTD validation on.
-
useValidation
public boolean useValidation()
Description copied from interface:ConfigurationFile
Returns whether the XML content should be validated using a DTD. Iftrue
when the XML is parsed the file will be validated using the corresponding DTD (as defined in the XML itself).- Specified by:
useValidation
in interfaceConfigurationFile
-
save
public void save() throws ConfigException
Saves thisConfigurationElement
back into the files where it was loaded from. All in-memory changes are automatically applied into the lastElementSource
used to load this element.- Specified by:
save
in interfaceConfigurationFile
- Throws:
ConfigException
-
saveChangesAs
public void saveChangesAs(java.lang.String fileName) throws ConfigException
Saves all in-memory changes to the given file. If this ConfigurationElement was loaded from that file, the resulting file includes the original contents plus the changes.- Throws:
ConfigException
-
saveConfig
public final void saveConfig(java.lang.String filePath) throws ConfigException
Deprecated.To save in a different location, set a custom FileLoader and use the save() method.Saves this element configuration into the given filePath. Notice that this method has been deprecated: To save the configuration file into a different location it's better to create a FileLoader with the new folder path and assign it to the root element:
This makes sure all config-src are saved into their corresponding file.PageManager pm = new PageManager(); pm.load(".\\WEB-INF\\xml\\pageConfig.xml"); FileLoader fl = new FileLoader(System.getProperty("user.dir") + OUTPUT_FOLDER); //Save it in a different folder: pm.setFileLoader(fl); pm.save();
- Throws:
ConfigException
-
cleanUpDeletedElements
public void cleanUpDeletedElements()
This method when called will delete all the child elements that are marked as deleted.
-
saveSource
protected void saveSource(ConfigurationSource source) throws ConfigException
Saves only the contents associated with the given source.- Throws:
ConfigException
-
saveFlatXML
public void saveFlatXML(java.lang.String fileName) throws ConfigException
Saves the current element structure, in XML format, into the given file.- Throws:
ConfigException
-
saveNode
protected void saveNode(org.w3c.dom.Node node, java.lang.String fileLocation) throws ConfigException
Saves an XML node into a file in the given location.- Parameters:
node
- the xml node to savefileLocation
- An absolute path for the file location- Throws:
ConfigException
-
save
public void save(CustomizationInfo c) throws ConfigException
Saves deltas for thisConfigurationElement
into the given CustomizationInfo.- Specified by:
save
in interfaceConfigurationFile
- Throws:
ConfigException
-
mergeChanges
protected void mergeChanges(java.lang.String srcKey)
Removes deltas and applies them to the given source.
-
getSelfInitPath
public java.lang.String getSelfInitPath()
Returns the path to the file where this configuration element was originally loaded from. It only returns a non-null value when this element was loaded using theload(java.lang.String)
method, or if it was loaded from a node that had the "config-src" attribute specified.
-
setSelfInitPath
protected void setSelfInitPath(java.lang.String value)
-
toXML
public org.w3c.dom.Element toXML(org.w3c.dom.Document doc)
Generates the DOM representation of thisConfigurationElement
. This method returns the list of attributes and elements merged from allElementSource
. Note that the resultingElement
will not be associated with theDocument
parameter. It is important to ensure that all DOM trees have aDocument
root as some serializers do not behave correctly otherwise. UsetoXML()
if the resulting DOM is not going to be appended in another DOM structure.- Specified by:
toXML
in interfaceConfigurationElement
- Parameters:
doc
- factory for creating underlyingElement
- Returns:
- DOM of this instance
-
toXML
public org.w3c.dom.Element toXML()
Generates the DOM representation of thisConfigurationElement
. This method returns the list of attributes and elements merged from allElementSource
.- Returns:
- a stand alone DOM with its own document root instance
-
toXML
protected org.w3c.dom.Element toXML(java.lang.String sourceKey)
Generates the DOM representation of thisConfigurationElement
for the list of attributes and elements defined in the givenElementSource
.- Returns:
- a stand alone DOM with its own document root instance
-
toXML
protected org.w3c.dom.Element toXML(org.w3c.dom.Document doc, java.lang.String sourceKey)
Generates the DOM representation of thisConfigurationElement
for the list of attributes and elements defined in the givenElementSource
. Note that the resultingElement
will not be associated with theDocument
parameter. It is important to ensure that all DOM trees have aDocument
root as some serializers do not behave correctly otherwise.
-
exportAttributesToXML
protected void exportAttributesToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the list of attributes of thisConfigurationElement
into the given node. The list is filter to include only attributes defined in the givenElementSource
. IfsourceKey
isnull
, it appends the list of attributes merged from allElementSources
.
-
exportElementsToXML
protected void exportElementsToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the list of child-elements of thisConfigurationElement
into the given node. The list is filter to include only elements defined in the givenElementSource
. IfsourceKey
isnull
, it appends the list of elements merged from allElementSources
.
-
exportNodeValueToXML
protected void exportNodeValueToXML(org.w3c.dom.Element element, ConfigurationSource source)
Appends the node value associated with the given source key into the given node. IfsourceKey
isnull
, it appends the current node value.
-
toString
public java.lang.String toString()
Generates the String representation of thisConfigurationElement
.- Overrides:
toString
in classjava.lang.Object
-
printAttributes
protected void printAttributes(java.lang.StringBuffer outString)
Appends the list of attributes of thisConfigurationElement
into the givenStringBuffer
. It includes the list attributes merged from allElementSources
.
-
printElements
protected void printElements(java.lang.StringBuffer outString)
Appends the list of child-elements of thisConfigurationElement
into the givenStringBuffer
. It appends the list of elements merged from allElementSources
.
-
printNodeValue
protected void printNodeValue(java.lang.StringBuffer outString)
Appends the node value into the givenStringBuffer
. It appends the node value of elements merged from allElementSources
.
-
load
public void load(java.lang.String fileName) throws ConfigException
Loads the file with the given name and initializes thisConfigurationElement
with its content.- Specified by:
load
in interfaceConfigurationFile
- Parameters:
fileName
- The path to the configuration file. This path will be resolved by theFileLoader
- Throws:
ConfigException
-
reload
public void reload() throws ConfigException
Loops through all theElementSource
of thisConfigurationElement
and reloads the content of those whose underlying configuration file has changed.- Specified by:
reload
in interfaceConfigurationElement
- Specified by:
reload
in interfaceConfigurationFile
- Throws:
ConfigException
-
reloadPrototype
protected void reloadPrototype()
Loops through all theElementSource
of thisConfigurationElement
and reloads the content of those whose underlying configuration file has changed.
-
applyCustomizations
public void applyCustomizations() throws ConfigException
Loops through all theCustomizationInfo
in theCustomizations
class and apply the corresponding customizations.- Specified by:
applyCustomizations
in interfaceConfigurationFile
- Throws:
ConfigException
-
applyCustomization
public void applyCustomization(CustomizationInfo c) throws ConfigException
Applies the corresponding customizations.- Specified by:
applyCustomization
in interfaceConfigurationFile
- Throws:
ConfigException
-
original
public final AbstractConfigurationElement original()
Returns a new instance of this object, populated only with the out of the box values of Microstrategy Web, that is, only default values or those that came from the load method. Values from customizations or programatic changes are not included.
-
deltas
public final AbstractConfigurationElement deltas()
Returns thedeltas
between theoriginal()
andthis
objects. The returned value therefore includes all changes to this object after it was loaded; this includes both programatic changes and plugins changes.- See Also:
original()
,deltas()
-
deltas
public AbstractConfigurationElement deltas(AbstractConfigurationElement other)
Returns a partial instance of this object that contains the attributes and elements required to make this object equals to the
other
paramter. It is used to identify the differences between the two instances of this class.Being a partial instance, the resulting
Notice that if bothdelta
includes strictly those attributes and elements required to make it equal to the other object; typically default attributes and elements are not included so its possible that getter methods for properties and/or chidlren will returnnull
.x
andy
areAbstractConfigurationElement
, andx != y
, thend = x.deltas(y) x + d = y
Or programatically:if (!x.equals(y)) { AbstractConfigurationElement d = x.deltas(y); x.populates(d).equals(y); //returns true }
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a new instance of this object with the same values.
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
equalsIncludingDeletedElements
public boolean equalsIncludingDeletedElements(java.lang.Object object)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
hashCodeAtts
protected int hashCodeAtts()
Returns the hashcode for attributes.
-
hashCodeElements
protected int hashCodeElements()
Returns the hashcode for attributes.
-
hashCodeNodeValues
protected int hashCodeNodeValues()
Returns the hashcode for attributes.
-
equalAtts
protected boolean equalAtts(AbstractConfigurationElement other)
Returnstrue
if the list of active attributes of the given AbstractConfigurationElement is equal to this list of active attributes of this AbstractConfigurationElement.
-
equalElements
protected boolean equalElements(AbstractConfigurationElement other)
Returnstrue
if the list of all child elements of the given AbstractConfigurationElement is equal to this list of all child-elements of this AbstractConfigurationElement.
-
equalNodeValues
protected boolean equalNodeValues(AbstractConfigurationElement other)
Returnstrue
if the node value of both configuration elements is the same.
-
getFileLoader
public FileLoader getFileLoader()
Returns the file loader instance used by this ConfigurationElement to load files from the file system. IfsetFileLoader(com.microstrategy.utils.FileLoader)
has not been explicitly called, this method uses the parent'sFileLoader
, and if it is a root object, it uses theFileLoader
singleton, that isFileLoader.getInstance()
.
-
setFileLoader
public void setFileLoader(FileLoader fl)
Sets theFileLoader
instance to be used to load files. This method is typically used to set a different root folder for relative paths. Normally, all relative paths (for example "/WEB-INF/web.xml") are relative to the application's root folder, to change this root folder users can create a new FileLoader instance and set it to this ConfigurationElement, then relative paths are resolved relative to the new FileLoader base path, for example:
In the previous sample, "/WEB-INF/xml/pageConfig.xml" is resolved toFileLoader fl = new FileLoader("C:\\Temp"); PagaManager pm = new PageManager(); pm.load("/WEB-INF/xml/pageConfig.xml", true);
C:\Temp\WEB-INF\xml\pageConfig.xml
as the FileLoader's base path is "C:\Temp"
-
populate
public ConfigurationElement populate(ConfigurationElement other)
This method takes another configuration element and populates this element with the other's attributes and child-elements. Existing values are merged in this process. After this method is called, attributes and elements from the other will be available in this element.- Returns:
- this same object.
-
replaceList
public void replaceList(AbstractConfigurationElement.FilteredList list)
-
getChildKey
protected java.lang.Object getChildKey(org.w3c.dom.Node node)
Returns the key that uniquely identifies the child element associated with the givenNode
.
-
getNextKey
public java.lang.Object getNextKey()
Returns an object that can be used as key for a list of child-elements that doesn't have a key by itself.
-
-