Class PamguardXMLWriter

java.lang.Object
PamController.settings.output.xml.PamguardXMLWriter
All Implemented Interfaces:
PamSettings, SettingsNameProvider

public class PamguardXMLWriter extends Object implements PamSettings
Class for writing XML configuration output to a file.
Author:
dg50
  • Method Details

    • getXMLWriter

      public static PamguardXMLWriter 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

      public boolean addNameSpaceToElements(Document doc, Element el, String nameSpace)
      Recursively walk the tree and add a namespace to every single element.
      Parameters:
      doc -
      nameSpace -
      Returns:
    • writeSelection

      public Document writeSelection(long time)
      Make a document with the options specified in writerSettings.
      Parameters:
      time - timestamp for document
      Returns:
    • writeModuleChain

      public Document writeModuleChain(PamControlledUnit pcu, long time)
      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 write
      time - timestamp for document
      Returns:
      XML document.
    • writeOneModule

      public Document writeOneModule(PamSettings pcu, long time)
    • writeOneModule

      public boolean writeOneModule(File file, PamSettings pamControlledUnit, Serializable objToWrite)
      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

      public Document writeModules(ArrayList<PamSettings> settings)
    • writeEverything

      public Document writeEverything(long time)
    • writeToTerminal

      public void writeToTerminal(Document doc)
      Write the xml document to System.out.
      Parameters:
      doc - xml document
    • writeToFile

      public 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 argument
      Parameters:
      doc - xml document
      time - time in milliseconds.
    • writeToFile

      public void writeToFile(Document doc, File outFile) throws IOException
      Write to the given file.
      Parameters:
      doc - xml document
      outFile - file
      Throws:
      IOException
    • getAsString

      public String getAsString(Document doc)
      Get the xml document as a String.
      Parameters:
      doc - xml document
      Returns:
      xml content as a a string.
    • getAsString

      public String getAsString(Document doc, boolean indent)
      Get the xml document as a String.
      Parameters:
      doc - xml document
      indent - Indent / format the document.
      Returns:
      xml content as a a string.
    • makeFileName

      public String makeFileName(long time)
    • writeUnitSettings

      public Element writeUnitSettings(Document doc, Element parent, PamSettings pamSettingsUnit)
      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 - Document
      parent - XML parent
      pamSettingsUnit - 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

      public Document writeOneObject(Object data)
    • writeObjectData

      public Element writeObjectData(Document doc, Element el, Object data, ArrayList<Object> objectHierarchy)
    • makeSettingsList

      public ArrayList<PamSettings> makeSettingsList()
    • isWritableType

      public static boolean isWritableType(Class<?> clazz)
      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

      public XMLWriterSettings getWriterSettings()
      Returns:
      the writerSettings
    • setWriterSettings

      public void setWriterSettings(XMLWriterSettings writerSettings)
      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

      public String getUnitName()
      Specified by:
      getUnitName in interface SettingsNameProvider
      Returns:
      A Name specific to this instance of the particular class, e.g. Sperm whale detector, Beaked whale detector, etc.
    • getUnitType

      public String getUnitType()
      Specified by:
      getUnitType in interface PamSettings
      Returns:
      A Name specific to the type, e.g. Click detector
    • getSettingsReference

      public Serializable getSettingsReference()
      Specified by:
      getSettingsReference in interface PamSettings
      Returns:
      The serialisable object that will be stored
    • getSettingsVersion

      public long getSettingsVersion()
      Specified by:
      getSettingsVersion in interface PamSettings
      Returns:
      An integer version number for the settings
    • restoreSettings

      public boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings)
      Specified by:
      restoreSettings in interface PamSettings
      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