Class LocoFile


  • public class LocoFile
    extends XmlFile
    Represents and manipulates a locomotive definition, both as a file and in memory. The interal storage is a JDOM tree. See locomotive-config.xsd

    This class is intended for use by RosterEntry only; you should not use it directly. That's why this is not a public class.

    See Also:
    RosterEntry, Roster
    • Method Detail

      • titleString

        public java.lang.String titleString()
        Convert to a canonical text form for ComboBoxes, etc.
        Returns:
        loco title.
      • loadCvModel

        public static void loadCvModel​(org.jdom2.Element loco,
                                       CvTableModel cvModel,
                                       java.lang.String mfgID,
                                       java.lang.String family)
        Load a CvTableModel from the locomotive element in the File.
        Parameters:
        loco - A JDOM Element containing the locomotive definition
        cvModel - An existing CvTableModel object which will have the CVs from the loco Element appended. It is intended, but not required, that this be empty.
        mfgID - Decoder manufacturer. Used to check if there's need for special treatment.
        family - Decoder family. Used to check if there's need for special treatment.
      • loadVariableModel

        public static void loadVariableModel​(org.jdom2.Element loco,
                                             VariableTableModel varModel)
        Load a VariableTableModel from the locomotive element in the File
        Parameters:
        loco - A JDOM Element containing the locomotive definition
        varModel - An existing VariableTableModel object
      • selectMissingVarResponse

        protected static LocoFile.MessageResponse selectMissingVarResponse​(java.lang.String var)
        Determine if a missing variable in decoder definition should be logged
        Parameters:
        var - Name of missing variable
        Returns:
        Decision on how to handle
      • writeFile

        public void writeFile​(java.io.File file,
                              CvTableModel cvModel,
                              VariableTableModel variableModel,
                              RosterEntry r)
        Write an XML version of this object, including also the RosterEntry information, and memory-resident decoder contents. Does not do an automatic backup of the file, so that should be done elsewhere.
        Parameters:
        file - Destination file. This file is overwritten if it exists.
        cvModel - provides the CV numbers and contents
        variableModel - provides the variable names and contents
        r - RosterEntry providing name, etc, information
      • writeFile

        public void writeFile​(java.io.File pFile,
                              org.jdom2.Element pRootElement,
                              RosterEntry pEntry)
        Write an XML version of this object from an existing XML tree, updating only the ID string. Does not do an automatic backup of the file, so that should be done elsewhere. This is intended for copy and import operations, where the tree has been read from an existing file. Hence, only the "ID" information in the roster entry is updated. Note that any multi-line comments are not changed here.
        Parameters:
        pFile - Destination file. This file is overwritten if it exists.
        pRootElement - Root element of the JDOM tree to write. This should be of type "locomotive-config", and should not be in use elsewhere (clone it first!)
        pEntry - RosterEntry providing name, etc, information
      • writeFile

        public void writeFile​(java.io.File pFile,
                              org.jdom2.Element existingElement,
                              org.jdom2.Element newLocomotive)
        Write an XML version of this object, updating the RosterEntry information, from an existing XML tree. Does not do an automatic backup of the file, so that should be done elsewhere. This is intended for writing out changes to the RosterEntry information only.
        Parameters:
        pFile - Destination file. This file is overwritten if it exists.
        existingElement - Root element of the existing JDOM tree containing the CV and variable contents
        newLocomotive - Element from RosterEntry providing name, etc, information