Class ConfigXmlManager
- java.lang.Object
-
- jmri.jmrit.XmlFile
-
- jmri.configurexml.ConfigXmlManager
-
- All Implemented Interfaces:
ConfigureManager
public class ConfigXmlManager extends XmlFile implements ConfigureManager
Provides the mechanisms for storing an entire layout configuration to XML. "Layout" refers to the hardware: Specific communication systems, etc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrit.XmlFile
XmlFile.Validate
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.Object,java.lang.Integer>
clist
(package private) java.io.File
prefsFile
static java.lang.String
schemaVersion
Define the current schema version string for the layout-config schema.-
Fields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation
-
-
Constructor Summary
Constructors Constructor Description ConfigXmlManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
adapterName(java.lang.Object o)
Find the name of the adapter class for an object.protected boolean
addConfigStore(org.jdom2.Element root)
protected void
addPrefsStore(org.jdom2.Element root)
protected boolean
addToolsStore(org.jdom2.Element root)
protected void
addUserPrefsStore(org.jdom2.Element root)
protected boolean
addUserStore(org.jdom2.Element root)
(package private) void
confirmAdapterAvailable(java.lang.Object o)
Common check routine to confirm an adapter is available as part of registration process.static void
creationErrorEncountered(XmlAdapter adapter, java.lang.String operation, java.lang.String description, java.lang.String systemName, java.lang.String userName, java.lang.Throwable exception)
Invoke common handling of errors that happen during the "load" process.static java.lang.String
currentClassName(java.lang.String name)
Handles ConfigureXml classes that have moved to a new package or been superseded.void
deregister(java.lang.Object o)
static org.jdom2.Element
elementFromObject(java.lang.Object o)
static org.jdom2.Element
elementFromObject(java.lang.Object object, boolean shared)
protected boolean
finalStore(org.jdom2.Element root, java.io.File file)
java.net.URL
find(java.lang.String f)
Find a file by looking in xml/layout/ in the preferences directory, if that exists in xml/layout/ in the application directory, if that exists in xml/ in the preferences directory, if that exists in xml/ in the application directory, if that exists at top level in the application directoryjava.lang.Object
findInstance(java.lang.Class<?> c, int index)
Find the ith instance of an object of particular class that's been registered for storage.java.util.List<java.lang.Object>
getInstanceList(java.lang.Class<?> c)
Returns a list of instances stored for a given class.protected java.util.List<org.jdom2.Element>
getLoadDeferredList()
XmlFile.Validate
getValidate()
Whether to verify the DTD of this XML file when read.protected void
includeHistory(org.jdom2.Element root, java.io.File file)
protected org.jdom2.Element
initStore()
boolean
load(java.io.File fi)
Load a file.boolean
load(java.io.File fi, boolean registerDeferred)
Load a file.boolean
load(java.net.URL url)
Create the objects defined in a particular configuration fileboolean
load(java.net.URL url, boolean registerDeferred)
Load a file.boolean
loadDeferred(java.io.File fi)
Create the objects defined in a particular configuration file that have been deferred until after basic GUI construction completedboolean
loadDeferred(java.net.URL url)
Create the objects defined in a particular configuration file that have been deferred until after basic GUI construction completed(package private) void
locateClassFailed(java.lang.Throwable ex, java.lang.String adapterName, java.lang.Object o)
Handle failure to load adapter class.(package private) void
locateFileFailed(java.lang.String f)
Report a failure to find a file.boolean
makeBackup(java.io.File file)
Make a backup file.void
registerConfig(java.lang.Object o)
void
registerConfig(java.lang.Object o, int x)
void
registerPref(java.lang.Object o)
void
registerTool(java.lang.Object o)
void
registerUser(java.lang.Object o)
Register an object whose state is to be tracked.void
registerUserPrefs(java.lang.Object o)
void
removePrefItems()
static void
setErrorHandler(ErrorHandler handler)
void
setPrefsLocation(java.io.File prefsFile)
Set location for preferences file.void
setValidate(XmlFile.Validate v)
Control the scope of validation of XML files when loading.boolean
storeConfig(java.io.File file)
Stores just configuration information.void
storePrefs()
Stores just preferences information.void
storePrefs(java.io.File file)
Stores just preferences information.boolean
storeUser(java.io.File file)
Stores user and config information.void
storeUserPrefs(java.io.File file)
Stores just user preferences information.static void
storingErrorEncountered(XmlAdapter adapter, java.lang.String operation, java.lang.String description, java.lang.String systemName, java.lang.String userName, java.lang.Throwable exception)
Invoke common handling of errors that happen during the "store" process.-
Methods inherited from class jmri.jmrit.XmlFile
addDefaultInfo, backupFileName, checkFile, createFileNameWithDate, dumpElement, findFile, getBuilder, getDefaultDtdLocation, getDefaultValidate, getDtdLocation, getProcessingInstructionHRef, getProcessingInstructionType, getRoot, makeBackupFile, makeBackupFile, newDocument, newDocument, revertBackupFile, rootFromFile, rootFromInputStream, rootFromName, rootFromURL, setDefaultDtdLocation, setDefaultValidate, setDtdLocation, userFileChooser, userFileChooser, writeXML, xmlDir
-
-
-
-
Field Detail
-
schemaVersion
public static final java.lang.String schemaVersion
Define the current schema version string for the layout-config schema. See the Schema versioning discussion. Also controls the stylesheet file version.- See Also:
- Constant Field Values
-
clist
java.util.Map<java.lang.Object,java.lang.Integer> clist
-
prefsFile
java.io.File prefsFile
-
-
Constructor Detail
-
ConfigXmlManager
public ConfigXmlManager()
-
-
Method Detail
-
registerConfig
public void registerConfig(java.lang.Object o)
- Specified by:
registerConfig
in interfaceConfigureManager
-
registerPref
public void registerPref(java.lang.Object o)
- Specified by:
registerPref
in interfaceConfigureManager
-
confirmAdapterAvailable
void confirmAdapterAvailable(java.lang.Object o)
Common check routine to confirm an adapter is available as part of registration process.Note: Should only be called for debugging purposes, for example, when Log4J DEBUG level is selected, to load fewer classes at startup.
- Parameters:
o
- object to confirm XML adapter exists for
-
currentClassName
public static java.lang.String currentClassName(java.lang.String name)
Handles ConfigureXml classes that have moved to a new package or been superseded.- Parameters:
name
- name of the moved or superceded ConfigureXml class- Returns:
- name of the ConfigureXml class in newer package or of superseding class
-
removePrefItems
public void removePrefItems()
- Specified by:
removePrefItems
in interfaceConfigureManager
-
findInstance
public java.lang.Object findInstance(java.lang.Class<?> c, int index)
Find the ith instance of an object of particular class that's been registered for storage.Note that the index of an object can change when other objects are stored or removed. The index is for indexing over the objects stored at a moment, not for use as an identification number.
There may be synchronization issues associated with this, although they are expected to be rare in practice.
- Specified by:
findInstance
in interfaceConfigureManager
- Parameters:
c
- Class of the desired objectsindex
- a 1-based index of the object to return- Returns:
- an object of class c or null
-
getInstanceList
public java.util.List<java.lang.Object> getInstanceList(java.lang.Class<?> c)
Returns a list of instances stored for a given class.- Specified by:
getInstanceList
in interfaceConfigureManager
- Parameters:
c
- Class of the desired objects- Returns:
- an List of objects of class c or null
-
registerConfig
public void registerConfig(java.lang.Object o, int x)
- Specified by:
registerConfig
in interfaceConfigureManager
-
registerTool
public void registerTool(java.lang.Object o)
- Specified by:
registerTool
in interfaceConfigureManager
-
registerUser
public void registerUser(java.lang.Object o)
Register an object whose state is to be tracked. It is not an error if the original object was already registered.- Specified by:
registerUser
in interfaceConfigureManager
- Parameters:
o
- The object, which must have an associated adapter class.
-
registerUserPrefs
public void registerUserPrefs(java.lang.Object o)
- Specified by:
registerUserPrefs
in interfaceConfigureManager
-
deregister
public void deregister(java.lang.Object o)
- Specified by:
deregister
in interfaceConfigureManager
-
adapterName
public static java.lang.String adapterName(java.lang.Object o)
Find the name of the adapter class for an object.- Parameters:
o
- object of a configurable type- Returns:
- class name of adapter
-
locateClassFailed
void locateClassFailed(java.lang.Throwable ex, java.lang.String adapterName, java.lang.Object o)
Handle failure to load adapter class. Although only a one-liner in this class, it is a separate member to facilitate testing.- Parameters:
ex
- the exception throw failing to load adapterName as oadapterName
- name of the adapter classo
- adapter object
-
initStore
protected org.jdom2.Element initStore()
-
addPrefsStore
protected void addPrefsStore(org.jdom2.Element root)
-
addConfigStore
protected boolean addConfigStore(org.jdom2.Element root)
-
addToolsStore
protected boolean addToolsStore(org.jdom2.Element root)
-
addUserStore
protected boolean addUserStore(org.jdom2.Element root)
-
addUserPrefsStore
protected void addUserPrefsStore(org.jdom2.Element root)
-
includeHistory
protected void includeHistory(org.jdom2.Element root, java.io.File file)
-
finalStore
protected boolean finalStore(org.jdom2.Element root, java.io.File file)
-
storePrefs
public void storePrefs()
Stores just preferences information.Where that information is stored is implementation-specific.
- Specified by:
storePrefs
in interfaceConfigureManager
-
storePrefs
public void storePrefs(java.io.File file)
Stores just preferences information.- Specified by:
storePrefs
in interfaceConfigureManager
- Parameters:
file
- the to store preferences into
-
storeUserPrefs
public void storeUserPrefs(java.io.File file)
Stores just user preferences information.- Specified by:
storeUserPrefs
in interfaceConfigureManager
- Parameters:
file
- the file to store user preferences into
-
setPrefsLocation
public void setPrefsLocation(java.io.File prefsFile)
Set location for preferences file.File need not exist, but location must be writable when storePrefs() called.
- Parameters:
prefsFile
- new location for preferences file
-
storeConfig
public boolean storeConfig(java.io.File file)
Stores just configuration information.- Specified by:
storeConfig
in interfaceConfigureManager
- Parameters:
file
- Output file- Returns:
- true if successful; false otherwise
-
storeUser
public boolean storeUser(java.io.File file)
Stores user and config information.- Specified by:
storeUser
in interfaceConfigureManager
- Parameters:
file
- Output file- Returns:
- true if succeeded
-
makeBackup
public boolean makeBackup(java.io.File file)
Make a backup file.- Specified by:
makeBackup
in interfaceConfigureManager
- Parameters:
file
- to be backed up- Returns:
- true if successful
-
elementFromObject
public static org.jdom2.Element elementFromObject(java.lang.Object o)
- Parameters:
o
- The object to get an XML representation of- Returns:
- An XML element representing o
-
elementFromObject
public static org.jdom2.Element elementFromObject(java.lang.Object object, boolean shared)
- Parameters:
object
- The object to get an XML representation ofshared
- true if the XML should be shared, false if the XML should be per-node- Returns:
- An XML element representing object
-
load
public boolean load(java.io.File fi) throws JmriConfigureXmlException
Load a file.Handles problems locally to the extent that it can, by routing them to the creationErrorEncountered method.
- Specified by:
load
in interfaceConfigureManager
- Parameters:
fi
- file to load- Returns:
- true if no problems during the load
- Throws:
JmriConfigureXmlException
- if unable to load file
-
load
public boolean load(java.net.URL url) throws JmriConfigureXmlException
Create the objects defined in a particular configuration file- Specified by:
load
in interfaceConfigureManager
- Parameters:
url
- Input URL- Returns:
- true if succeeded
- Throws:
JmriConfigureXmlException
-
load
public boolean load(java.io.File fi, boolean registerDeferred) throws JmriConfigureXmlException
Load a file.Handles problems locally to the extent that it can, by routing them to the creationErrorEncountered method.
- Specified by:
load
in interfaceConfigureManager
- Parameters:
fi
- file to loadregisterDeferred
- true to register objects to defer- Returns:
- true if no problems during the load
- Throws:
JmriConfigureXmlException
- if problem during load- Since:
- 2.11.2
- See Also:
XmlAdapter.loadDeferred()
-
load
public boolean load(java.net.URL url, boolean registerDeferred) throws JmriConfigureXmlException
Load a file.Handles problems locally to the extent that it can, by routing them to the creationErrorEncountered method.
Always processes on Swing thread
- Specified by:
load
in interfaceConfigureManager
- Parameters:
url
- URL of file to loadregisterDeferred
- true to register objects to defer- Returns:
- true if no problems during the load
- Throws:
JmriConfigureXmlException
- if problem during load- Since:
- 3.3.2
- See Also:
XmlAdapter.loadDeferred()
-
setValidate
public void setValidate(XmlFile.Validate v)
Control the scope of validation of XML files when loading.- Specified by:
setValidate
in interfaceConfigureManager
- Overrides:
setValidate
in classXmlFile
- Parameters:
v
- the validation scope
-
getValidate
public XmlFile.Validate getValidate()
Whether to verify the DTD of this XML file when read.- Specified by:
getValidate
in interfaceConfigureManager
- Overrides:
getValidate
in classXmlFile
- Returns:
- the level of validation to apply to a file
-
loadDeferred
public boolean loadDeferred(java.io.File fi)
Create the objects defined in a particular configuration file that have been deferred until after basic GUI construction completed- Specified by:
loadDeferred
in interfaceConfigureManager
- Parameters:
fi
- Input file- Returns:
- true if succeeded
- See Also:
XmlAdapter.loadDeferred()
-
loadDeferred
public boolean loadDeferred(java.net.URL url)
Create the objects defined in a particular configuration file that have been deferred until after basic GUI construction completed- Specified by:
loadDeferred
in interfaceConfigureManager
- Parameters:
url
- Input URL- Returns:
- true if succeeded
- See Also:
XmlAdapter.loadDeferred()
-
find
public java.net.URL find(java.lang.String f)
Find a file by looking- in xml/layout/ in the preferences directory, if that exists
- in xml/layout/ in the application directory, if that exists
- in xml/ in the preferences directory, if that exists
- in xml/ in the application directory, if that exists
- at top level in the application directory
- Specified by:
find
in interfaceConfigureManager
- Parameters:
f
- Local filename, perhaps without path information- Returns:
- Corresponding File object
-
locateFileFailed
void locateFileFailed(java.lang.String f)
Report a failure to find a file. This is a separate member to ease testing.- Parameters:
f
- Name of file not located.
-
creationErrorEncountered
public static void creationErrorEncountered(XmlAdapter adapter, java.lang.String operation, java.lang.String description, java.lang.String systemName, java.lang.String userName, java.lang.Throwable exception)
Invoke common handling of errors that happen during the "load" process.Exceptions passed into this are absorbed.
- Parameters:
adapter
- Object that encountered the error (for reporting), may be nulloperation
- description of the operation being attempted, may be nulldescription
- description of error encounteredsystemName
- System name of bean being handled, may be nulluserName
- used name of the bean being handled, may be nullexception
- Any exception being handled in the processing, may be null
-
storingErrorEncountered
public static void storingErrorEncountered(XmlAdapter adapter, java.lang.String operation, java.lang.String description, java.lang.String systemName, java.lang.String userName, java.lang.Throwable exception)
Invoke common handling of errors that happen during the "store" process.Exceptions passed into this are absorbed.
- Parameters:
adapter
- Object that encountered the error (for reporting), may be nulloperation
- description of the operation being attempted, may be nulldescription
- description of error encounteredsystemName
- System name of bean being handled, may be nulluserName
- used name of the bean being handled, may be nullexception
- Any exception being handled in the processing, may be null
-
setErrorHandler
public static void setErrorHandler(ErrorHandler handler)
-
getLoadDeferredList
protected java.util.List<org.jdom2.Element> getLoadDeferredList()
- Returns:
- the loadDeferredList
-
-