Package xal.smf.data
Class XMLDataManager
java.lang.Object
xal.smf.data.XMLDataManager
****************************************************************************
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Exception thrown when a URL has not been specified for the given group and an attempt is made to read or write the group. -
Constructor Summary
ConstructorsConstructorDescriptionXMLDataManager
(String urlPath) ConstructorXMLDataManager
(String urlPath, ChannelFactory channelFactory) Primary Constructor -
Method Summary
Modifier and TypeMethodDescriptionabsoluteUrlSpec
(String urlSpec) Get absolute URL specifications given a URL spec relative to the main URLstatic Accelerator
acceleratorWithPath
(String filePath) Read the accelerator from the data source at the file path.static Accelerator
acceleratorWithPath
(String filePath, boolean isValidating) Read the accelerator from the data source at the file path and using DTD validation if if the user specifies.static Accelerator
acceleratorWithPath
(String filePath, ChannelFactory channelFactory) Read the accelerator from the data source at the file path.static Accelerator
acceleratorWithUrlSpec
(String urlPath) Read the accelerator from the data source at the URL path.static Accelerator
acceleratorWithUrlSpec
(String urlPath, ChannelFactory channelFactory) Read the accelerator from the data source at the URL path.static String
Get the path to the default main data source specified in the user's preferences.Parse the accelerator from the optics URL without DTD validation and also populate the dynamic data.getAccelerator
(boolean isValidating) Parse the accelerator from the optics URL with the specified DTD validation flag and also populate the dynamic data.static XMLDataManager
Get the default XMLDataManager based on the user's preferred path to the Main data sourceGet the URL spec to the device mapping file.Get the URL spec for the hardware statusstatic XMLDataManager
getInstance
(URL url) factory method given a URL to the main optics sourceGet the URL spec for the power suppliesGet the table groups (names) read from the edit context of the accelerator data source.Read the timing center from the timing URL.static Accelerator
Load the accelerator corresponding to the default accelerator data source specified in the user's preferences.static Accelerator
loadDefaultAccelerator
(ChannelFactory channelFactory) Load the accelerator corresponding to the default accelerator data source specified in the user's preferences.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.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.static XMLDataManager
managerWithFilePath
(String filePath) Create and return a new XMLDataManager with its source given by the specified file path.static XMLDataManager
managerWithFilePath
(String filePath, ChannelFactory channelFactory) Create and return a new XMLDataManager with its source given by the specified file path.static XMLDataManager
newEmptyManager
(ChannelFactory channelFactory) Create and return a new empty XMLDataManager.Get the URL spec of the DTD file used in the optics XML file.Get the URL spec to the accelerator optics.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.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.static void
setDefaultPath
(String path) Set the path to the default main data source and store it in the user's preferences.void
setDeviceMappingUrlSpec
(String urlSpec) Set the URL spec to the device mapping filevoid
setElementMappingUrlSpec
(String elementMappingUrlSpec) void
setHardwareStatusUrlSpec
(String urlSpec) Set the URL spec for the hardware statusvoid
setMainPath
(String filePath) 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.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.void
setOpticsDtdUrlSpec
(String urlSpec) Set the URL spec of the DTD file to use in the optics XML file.void
setOpticsUrlSpec
(String urlSpec) Set the URL spec to the accelerator optics.void
setPowerSuppliesUrlSpec
(String urlSpec) Set the URL spec for the power suppliesvoid
setTimingManagerUrlSpec
(String timingManagerUrlSpec) void
setUrlSpecForTableGroup
(String urlSpec, String tableGroup) Set the URL spec of the data source for the specified table group.void
updateOptics
(Accelerator accelerator, boolean isValidating) update the accelerator with data from the optics URL with a DTD validation flagurlSpecForTableGroup
(String tableGroup) Get the URL spec of the data source of the specified table group.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.void
writeDeviceMapping
(Accelerator accelerator) Write the device mapping defined by the accelerator node factory.void
writeEditContext
(EditContext editContext) void
writeElementMapping
(Accelerator accelerator) Write the element mapping defined by the accelerator.void
writeFieldMaps
(Accelerator accelerator) Write the field maps used by the accelerator.void
Write the main file which lists the pointers to the optics, edit context and extra optics files.void
writeOptics
(Accelerator accelerator) Write the optics part of the accelerator to an optics file using the location set in this data manager.void
writePowerSupplies
(Accelerator accelerator) Write the power supplies of the accelerator to a file using the location set in this data manager.void
writeStatus
(Accelerator accelerator) Write the hardware status part of the accelerator to a file using the location set in this data manager.void
writeTableGroup
(EditContext editContext, String groupName) static void
writeTableGroupToUrl
(EditContext editContext, String tableGroup, String urlSpec) void
writeTimingManager
(Accelerator accelerator) Write the Timing Manager.
-
Constructor Details
-
XMLDataManager
Primary Constructor -
XMLDataManager
Constructor
-
-
Method Details
-
getInstance
factory method given a URL to the main optics source -
newEmptyManager
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
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
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
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 generatedXmlDataAdaptor.ParseException
-
acceleratorWithUrlSpec
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
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
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
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
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
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
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
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
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
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
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
Get absolute URL specifications given a URL spec relative to the main URL- Returns:
- absolute URL specification
-
opticsUrlSpec
Get the URL spec to the accelerator optics.- Returns:
- The URL spec to the accelerator optics.
-
setOpticsUrlSpec
Set the URL spec to the accelerator optics.- Parameters:
urlSpec
- The new URL spec to the accelerator optics.
-
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
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
Get the URL spec for the hardware status -
setHardwareStatusUrlSpec
Set the URL spec for the hardware status -
getPowerSuppliesUrlSpec
Get the URL spec for the power supplies -
setPowerSuppliesUrlSpec
Set the URL spec for the power supplies -
getDeviceMappingUrlSpec
Get the URL spec to the device mapping file.- Returns:
- The URL spec to the device mapping file.
-
setDeviceMappingUrlSpec
Set the URL spec to the device mapping file -
getElementMappingUrlSpec
-
setElementMappingUrlSpec
-
getTimingManagerUrlSpec
-
setTimingManagerUrlSpec
-
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
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
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
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
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 sourcesisValidating
- use DTD validation if true and don't validate if false- Throws:
XmlDataAdaptor.ParseException
-
readTableGroup
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 readgroup
- The table group to read from its associated URl
-
readTableGroupFromUrl
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 readgroup
- The table group to read from the specified URLurlSpec
- 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
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
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
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
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
-
writeTableGroupToUrl
-
writeTableGroup
-
writeDeviceMapping
Write the device mapping defined by the accelerator node factory. -
writeElementMapping
Write the element mapping defined by the accelerator. -
writeFieldMaps
Write the field maps used by the accelerator. -
writeTimingManager
Write the Timing Manager.
-