Class PamguardXMLWriter
java.lang.Object
PamController.settings.output.xml.PamguardXMLWriter
- All Implemented Interfaces:
PamSettings
,SettingsNameProvider
Class for writing XML configuration output to a file.
- Author:
- dg50
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addNameSpaceToElements
(Document doc, Element el, String nameSpace) Recursively walk the tree and add a namespace to every single element.getAsString
(Document doc) Get the xml document as a String.getAsString
(Document doc, boolean indent) Get the xml document as a String.long
static PamguardXMLWriter
boolean
static boolean
isWritableType
(Class<?> clazz) Is this element a writable type ? Basically, this means that it's a primitive of some sort.makeFileName
(long time) boolean
restoreSettings
(PamControlledUnitSettings pamControlledUnitSettings) void
setExcludeDisplaySettings
(boolean excludeDisplaySettings) void
setWriterSettings
(XMLWriterSettings writerSettings) writeEverything
(long time) writeModuleChain
(PamControlledUnit pcu, long time) Write a module and all modules that feed into that module.writeModules
(ArrayList<PamSettings> settings) boolean
writeOneModule
(File file, PamSettings pamControlledUnit, Serializable objToWrite) Can be called from a dialog to write one object into a settings xml file.writeOneModule
(PamSettings pcu, long time) writeOneObject
(Object data) writeSelection
(long time) Make a document with the options specified in writerSettings.void
writeStartSettings
(long timeNow) Write everything to an XML file with same name as psf, the date appended.boolean
writeToFile
(Document doc, long time) Write the xml document to a file which will have the same path and name as the current psf file, appended with the data constructed from the time argumentvoid
writeToFile
(Document doc, File outFile) Write to the given file.void
writeToTerminal
(Document doc) Write the xml document to System.out.writeUnitSettings
(Document doc, Element parent, PamSettings pamSettingsUnit) Writes unit settings from the main settings list of settings recovered from modules.writeUnitSettings
(Document doc, Element parent, PamSettings pamSettingsUnit, PamSettings[] toWrite) Write a units settings.
-
Method Details
-
getXMLWriter
- Returns:
- Singleton XML writer. There are shared settings, so this is needed. May have to re-think this if we try to use this writer for other things apart from settings, or writing settings in other ways, such as binary headers in order to make it thread safe.
-
addNameSpaceToElements
Recursively walk the tree and add a namespace to every single element.- Parameters:
doc
-nameSpace
-- Returns:
-
writeSelection
Make a document with the options specified in writerSettings.- Parameters:
time
- timestamp for document- Returns:
-
writeModuleChain
Write a module and all modules that feed into that module. e.g. if you write a click detector, you'll also get an acquisition module.- Parameters:
pcu
- Pamguard module to writetime
- timestamp for document- Returns:
- XML document.
-
writeOneModule
-
writeOneModule
Can be called from a dialog to write one object into a settings xml file. It will write the objtoWrite in place of any settings from the module, since from the dialog, they may not be current.- Parameters:
file
-pamControlledUnit
-objToWrite
-- Returns:
-
writeModules
-
writeEverything
-
writeToTerminal
Write the xml document to System.out.- Parameters:
doc
- xml document
-
writeToFile
Write the xml document to a file which will have the same path and name as the current psf file, appended with the data constructed from the time argument- Parameters:
doc
- xml documenttime
- time in milliseconds.
-
writeToFile
Write to the given file.- Parameters:
doc
- xml documentoutFile
- file- Throws:
IOException
-
getAsString
Get the xml document as a String.- Parameters:
doc
- xml document- Returns:
- xml content as a a string.
-
getAsString
Get the xml document as a String.- Parameters:
doc
- xml documentindent
- Indent / format the document.- Returns:
- xml content as a a string.
-
makeFileName
-
writeUnitSettings
Writes unit settings from the main settings list of settings recovered from modules. Note that this can't be used for what may be temporary settings currently not saved within a dialog.
There is a bit of messing about to avoid rewriting an object if there are two objects that refer backwards and forth to each other ?- Parameters:
doc
-parent
-pamSettingsUnit
-- Returns:
- xml element
-
writeUnitSettings
public Element writeUnitSettings(Document doc, Element parent, PamSettings pamSettingsUnit, PamSettings[] toWrite) Write a units settings.- Parameters:
doc
- Documentparent
- XML parentpamSettingsUnit
- Generally a PAMcontrolledUnit, so it can write processes too.toWrite
- List of settings to write, generally all settings with same unitName as pamSettingsUnit but can be temporary settings objects when writing temporary settings from dialogs.- Returns:
- new XML element.
-
writeOneObject
-
writeObjectData
-
makeSettingsList
-
isWritableType
Is this element a writable type ? Basically, this means that it's a primitive of some sort. Otherwise it's probably an object and may even be a list in which case it will need treating differently.- Parameters:
clazz
-- Returns:
-
getWriterSettings
- Returns:
- the writerSettings
-
setWriterSettings
- Parameters:
writerSettings
- the writerSettings to set
-
writeStartSettings
public void writeStartSettings(long timeNow) Write everything to an XML file with same name as psf, the date appended. If binary store exists, put it in there, if not put it with the configuration file.- Parameters:
timeNow
-
-
getUnitName
- Specified by:
getUnitName
in interfaceSettingsNameProvider
- Returns:
- A Name specific to this instance of the particular class, e.g. Sperm whale detector, Beaked whale detector, etc.
-
getUnitType
- Specified by:
getUnitType
in interfacePamSettings
- Returns:
- A Name specific to the type, e.g. Click detector
-
getSettingsReference
- Specified by:
getSettingsReference
in interfacePamSettings
- Returns:
- The serialisable object that will be stored
-
getSettingsVersion
public long getSettingsVersion()- Specified by:
getSettingsVersion
in interfacePamSettings
- Returns:
- An integer version number for the settings
-
restoreSettings
- Specified by:
restoreSettings
in interfacePamSettings
- Returns:
- true if successful The object performs final checks (if needed) and then casts the settings data pamcontrolledunitSettings.settings into the correct type and uses as required
-
isExcludeDisplaySettings
public boolean isExcludeDisplaySettings()- Returns:
- the excludeDisplaySettings
-
setExcludeDisplaySettings
public void setExcludeDisplaySettings(boolean excludeDisplaySettings) - Parameters:
excludeDisplaySettings
- the excludeDisplaySettings to set
-