Package xal.smf.data

Class XMLDataManager

java.lang.Object
xal.smf.data.XMLDataManager

public class XMLDataManager extends Object
**************************************************************************** The XMLDataManager is the central class providing XML specific access to the optics file (which represents static accelerator data) and the table files (which represent dynamic data). A single main file lists the references to the optics file and the table files to load for a particular session. XMLDataManager is the central class providing access to parse and write all of this data. It generates the appropriate data adaptors for populating the object graph. Three private inner member classes provide help to the XMLDataManager for parsing and writing the three data files (Main reference file, Static optics file and the dynamic table files).
Author:
tap
  • Constructor Details

    • XMLDataManager

      public XMLDataManager(String urlPath, ChannelFactory channelFactory)
      Primary Constructor
    • XMLDataManager

      public XMLDataManager(String urlPath)
      Constructor
  • Method Details

    • getInstance

      public static XMLDataManager getInstance(URL url)
      factory method given a URL to the main optics source
    • newEmptyManager

      public static XMLDataManager newEmptyManager(ChannelFactory channelFactory)
      Create and return a new empty XMLDataManager. The sources take default values unless they are specified afterwards.
      Parameters:
      channelFactory - the channel factory for generating channels within the accelerator (nodes, timing, etc.)
      Returns:
      The new XMLDataManager
    • managerWithFilePath

      public static XMLDataManager managerWithFilePath(String filePath, ChannelFactory channelFactory) throws URLUtil.FilePathException
      Create and return a new XMLDataManager with its source given by the specified file path.
      Parameters:
      filePath - The file path of the accelerator data source.
      channelFactory - the channel factory for generating channels within the accelerator (nodes, timing, etc.)
      Returns:
      The new XMLDataManager
      Throws:
      URLUtil.FilePathException
    • managerWithFilePath

      public static XMLDataManager managerWithFilePath(String filePath) throws URLUtil.FilePathException
      Create and return a new XMLDataManager with its source given by the specified file path.
      Parameters:
      filePath - The file path of the accelerator data source.
      Returns:
      The new XMLDataManager
      Throws:
      URLUtil.FilePathException
    • getDefaultInstance

      public static XMLDataManager getDefaultInstance()
      Get the default XMLDataManager based on the user's preferred path to the Main data source
      Returns:
      A new instance of the XMLDataManager with the user's preferred data source or null if no default has been specified
    • getTimingCenter

      public TimingCenter getTimingCenter() throws XmlDataAdaptor.ParseException
      Read the timing center from the timing URL.
      Returns:
      a timing center read from the timing URL.
      Throws:
      xal.tools.xml.ParseException - if the TimingCenter cannot be generated
      XmlDataAdaptor.ParseException
    • acceleratorWithUrlSpec

      public static Accelerator acceleratorWithUrlSpec(String urlPath, ChannelFactory channelFactory)
      Read the accelerator from the data source at the URL path.
      Parameters:
      urlPath - The URL spec of the data source.
      channelFactory - the channel factory from which items (e.g. nodes, timing center, etc.) generate their channels
      Returns:
      the new accelerator read from the data source.
    • acceleratorWithUrlSpec

      public static Accelerator acceleratorWithUrlSpec(String urlPath)
      Read the accelerator from the data source at the URL path.
      Parameters:
      urlPath - The URL spec of the data source.
      Returns:
      the new accelerator read from the data source.
    • acceleratorWithPath

      public static Accelerator acceleratorWithPath(String filePath, ChannelFactory channelFactory) throws URLUtil.FilePathException
      Read the accelerator from the data source at the file path.
      Parameters:
      filePath - The file path of the data source.
      channelFactory - the channel factory from which items (e.g. nodes, timing center, etc.) generate their channels
      Returns:
      the new accelerator read from the data source.
      Throws:
      URLUtil.FilePathException
    • acceleratorWithPath

      public static Accelerator acceleratorWithPath(String filePath) throws URLUtil.FilePathException
      Read the accelerator from the data source at the file path.
      Parameters:
      filePath - The file path of the data source.
      Returns:
      the new accelerator read from the data source.
      Throws:
      URLUtil.FilePathException
    • acceleratorWithPath

      public static Accelerator acceleratorWithPath(String filePath, boolean isValidating) throws URLUtil.FilePathException
      Read the accelerator from the data source at the file path and using DTD validation if if the user specifies.
      Parameters:
      filePath - The file path of the data source.
      isValidating - enable DTD validation if true and disable DTD validation if false
      Returns:
      the new accelerator read from the data source
      Throws:
      URLUtil.FilePathException
    • loadDefaultAccelerator

      public static Accelerator loadDefaultAccelerator()
      Load the accelerator corresponding to the default accelerator data source specified in the user's preferences.
      Returns:
      the accelerator built from the default data source or null if no default accelerator is specified
    • loadDefaultAccelerator

      public static Accelerator loadDefaultAccelerator(ChannelFactory channelFactory)
      Load the accelerator corresponding to the default accelerator data source specified in the user's preferences.
      Parameters:
      channelFactory - the channel factory to use to generate the channels for the accelerator
      Returns:
      the accelerator built from the default data source or null if no default accelerator is specified
    • defaultPath

      public static String defaultPath()
      Get the path to the default main data source specified in the user's preferences.
      Returns:
      the file path to the default accelerator data source or null if a default hasn't been specified
    • setDefaultPath

      public static void setDefaultPath(String path)
      Set the path to the default main data source and store it in the user's preferences.
      Parameters:
      path - the new file path to the default accelerator data source
    • mainUrl

      public URL mainUrl()
      Get the URL to the accelerator data source which includes pointers to the optics and other supporting data such as the edit context and optics corrections.
      Returns:
      The URL to the accelerator data source.
    • mainUrlSpec

      public String mainUrlSpec()
      Get the URL spec to the accelerator data source which includes pointers to the optics and other supporting data such as the edit context and optics corrections.
      Returns:
      The URL spec to the accelerator data source.
    • setMainUrlSpec

      public void setMainUrlSpec(String urlSpec)
      Set the URL spec to use as the accelerator data source which includes pointers to the optics and other supporting data such as the edit context and optics corrections.
      Parameters:
      urlSpec - The new URL spec to the accelerator data source.
    • setMainPath

      public void setMainPath(String filePath) throws URLUtil.FilePathException
      Set the file path to use as the accelerator data source which includes pointers to the optics and other supporting data such as the edit context and optics corrections.
      Parameters:
      filePath - The new file path to the accelerator data source.
      Throws:
      URLUtil.FilePathException
    • absoluteUrlSpec

      public String absoluteUrlSpec(String urlSpec)
      Get absolute URL specifications given a URL spec relative to the main URL
      Returns:
      absolute URL specification
    • opticsUrlSpec

      public String opticsUrlSpec()
      Get the URL spec to the accelerator optics.
      Returns:
      The URL spec to the accelerator optics.
    • setOpticsUrlSpec

      public void setOpticsUrlSpec(String urlSpec)
      Set the URL spec to the accelerator optics.
      Parameters:
      urlSpec - The new URL spec to the accelerator optics.
    • opticsDtdUrlSpec

      public String opticsDtdUrlSpec()
      Get the URL spec of the DTD file used in the optics XML file.
      Returns:
      the URL spec of the DTD file used in the optics XML file.
    • setOpticsDtdUrlSpec

      public void setOpticsDtdUrlSpec(String urlSpec)
      Set the URL spec of the DTD file to use in the optics XML file.
      Parameters:
      urlSpec - the URL spec of the DTD file to use in the optics XML file.
    • getHardwareStatusUrlSpec

      public String getHardwareStatusUrlSpec()
      Get the URL spec for the hardware status
    • setHardwareStatusUrlSpec

      public void setHardwareStatusUrlSpec(String urlSpec)
      Set the URL spec for the hardware status
    • getPowerSuppliesUrlSpec

      public String getPowerSuppliesUrlSpec()
      Get the URL spec for the power supplies
    • setPowerSuppliesUrlSpec

      public void setPowerSuppliesUrlSpec(String urlSpec)
      Set the URL spec for the power supplies
    • getDeviceMappingUrlSpec

      public String getDeviceMappingUrlSpec()
      Get the URL spec to the device mapping file.
      Returns:
      The URL spec to the device mapping file.
    • setDeviceMappingUrlSpec

      public void setDeviceMappingUrlSpec(String urlSpec)
      Set the URL spec to the device mapping file
    • getElementMappingUrlSpec

      public String getElementMappingUrlSpec()
    • setElementMappingUrlSpec

      public void setElementMappingUrlSpec(String elementMappingUrlSpec)
    • getTimingManagerUrlSpec

      public String getTimingManagerUrlSpec()
    • setTimingManagerUrlSpec

      public void setTimingManagerUrlSpec(String timingManagerUrlSpec)
    • getTableGroups

      public Collection<String> getTableGroups()
      Get the table groups (names) read from the edit context of the accelerator data source. An edit context lists table groups and each table group is the name of a group of tables all of which reside in a single file.
      Returns:
      the collection of table group names read from the edit context
      See Also:
    • urlSpecForTableGroup

      public String urlSpecForTableGroup(String tableGroup)
      Get the URL spec of the data source of the specified table group. An edit context lists table groups and each table group is the name of a group of tables all of which reside in a single file.
      Parameters:
      tableGroup - The table group name
      Returns:
      The URL spec of the data source of the specified table group
    • setUrlSpecForTableGroup

      public void setUrlSpecForTableGroup(String urlSpec, String tableGroup)
      Set the URL spec of the data source for the specified table group. An edit context lists table groups and each table group is the name of a group of tables all of which reside in a single file.
      Parameters:
      urlSpec - The URL spec of the file where the table group resides.
      tableGroup - The table group name
    • getAccelerator

      public Accelerator getAccelerator() throws XmlDataAdaptor.ParseException
      Parse the accelerator from the optics URL without DTD validation and also populate the dynamic data.
      Returns:
      the accelerator parsed from the accelerator data source
      Throws:
      XmlDataAdaptor.ParseException
    • getAccelerator

      public Accelerator getAccelerator(boolean isValidating) throws XmlDataAdaptor.ParseException
      Parse the accelerator from the optics URL with the specified DTD validation flag and also populate the dynamic data.
      Parameters:
      isValidating - use DTD validation if true and don't validate if it is valse
      Returns:
      the accelerator parsed from the accelerator data source
      Throws:
      XmlDataAdaptor.ParseException
    • updateOptics

      public void updateOptics(Accelerator accelerator, boolean isValidating) throws XmlDataAdaptor.ParseException
      update the accelerator with data from the optics URL with a DTD validation flag
      Parameters:
      accelerator - The accelerator to update with data from the sources
      isValidating - use DTD validation if true and don't validate if false
      Throws:
      XmlDataAdaptor.ParseException
    • readTableGroup

      public void readTableGroup(EditContext editContext, String group)
      Reads the tables of the table group into the editContext getting its data from the URL associated with the group.
      Parameters:
      editContext - The edit context into which to place the tables which are read
      group - The table group to read from its associated URl
    • readTableGroupFromUrl

      public static void readTableGroupFromUrl(EditContext editContext, String group, String urlSpec)
      Reads the tables of the table group into the editContext getting its data from the specified URL.
      Parameters:
      editContext - The edit context into which to place the tables which are read
      group - The table group to read from the specified URL
      urlSpec - The URL spec of the table group source
    • writeMain

      public void writeMain()
      Write the main file which lists the pointers to the optics, edit context and extra optics files. This does not write the files to which the main file points.
    • writeAccelerator

      public void writeAccelerator(Accelerator accelerator)
      Write the entire accelerator including the optics to the optics file, edit context to the appropriate files for the table groups and the main file which references these sources. Juan: since input from many different files are merged to produce the Accelerator object, it is not possible to establish a 1-to-1 mapping between the Accelerator object and the files. Therefore some design choices have been taken here.

      - all the elements of the accelerator are saved on the same file, specified by OPTICS_TAG. Therefore no optics_extra are generated.

      - magnets power supplies are saved on a separate file, specified by POWERSUPPLIES_TAG.

      - all status flags set to false are saved on a separate file, specified by HARDWARE_STATUS_TAG.

      - if the accelerator is loaded from XML files, saving will result in merging all optics_extra files in the same optics file and also losing all comments of the original XML files.

      Parameters:
      accelerator - The accelerator which holds the optics and the edit context.
    • writeOptics

      public void writeOptics(Accelerator accelerator)
      Write the optics part of the accelerator to an optics file using the location set in this data manager.
      Parameters:
      accelerator - The accelerator to store in the optics file.
    • writeStatus

      public void writeStatus(Accelerator accelerator)
      Write the hardware status part of the accelerator to a file using the location set in this data manager.
      Parameters:
      accelerator - The accelerator to extract the status flags.
    • writePowerSupplies

      public void writePowerSupplies(Accelerator accelerator)
      Write the power supplies of the accelerator to a file using the location set in this data manager.
      Parameters:
      accelerator - The accelerator that contains the power supplies.
    • writeEditContext

      public void writeEditContext(EditContext editContext)
    • writeTableGroupToUrl

      public static void writeTableGroupToUrl(EditContext editContext, String tableGroup, String urlSpec)
    • writeTableGroup

      public void writeTableGroup(EditContext editContext, String groupName)
    • writeDeviceMapping

      public void writeDeviceMapping(Accelerator accelerator)
      Write the device mapping defined by the accelerator node factory.
    • writeElementMapping

      public void writeElementMapping(Accelerator accelerator)
      Write the element mapping defined by the accelerator.
    • writeFieldMaps

      public void writeFieldMaps(Accelerator accelerator)
      Write the field maps used by the accelerator.
    • writeTimingManager

      public void writeTimingManager(Accelerator accelerator)
      Write the Timing Manager.