gov.sns.xal.smf.data
Class XMLDataManager

java.lang.Object
  |
  +--gov.sns.xal.smf.data.XMLDataManager

public class XMLDataManager
extends java.lang.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).


Nested Class Summary
protected  class XMLDataManager.MissingUrlForGroup
          Exception thrown when a URL has not been specified for the given group and an attempt is made to read or write the group.
 
Field Summary
protected  gov.sns.xal.smf.data.TimingDataManager _timingManager
           
protected  gov.sns.xal.smf.data.XMLDataManager.AcceleratorManager acceleratorManager
           
protected static java.lang.String MAIN_PATH_PREF_KEY
           
protected  gov.sns.xal.smf.data.XMLDataManager.MainManager mainManager
           
protected  gov.sns.xal.smf.data.XMLDataManager.TableManager tableManager
           
 
Constructor Summary
XMLDataManager(java.lang.String urlPath)
          Creates new XMLDataManager
 
Method Summary
static Accelerator acceleratorWithPath(java.lang.String filePath)
          Read the accelerator from the data source at the file path.
static Accelerator acceleratorWithPath(java.lang.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 acceleratorWithUrlSpec(java.lang.String urlPath)
          Read the accelerator from the data source at the URL path.
static java.lang.String defaultPath()
          Get the path to the default main data source specified in the user's preferences.
 Accelerator getAccelerator()
          Parse the accelerator from the optics URL without DTD validation and also populate the dynamic data.
 Accelerator getAccelerator(boolean isValidating)
          Parse the accelerator from the optics URL with the specified DTD validation flag and also populate the dynamic data.
static XMLDataManager getDefaultInstance()
          Get the default XMLDataManager based on the user's preferred path to the Main data source
 java.util.Collection getTableGroups()
          Get the table groups (names) read from the edit context of the accelerator data source.
 TimingCenter getTimingCenter()
          Read the timing center from the timing URL.
static Accelerator loadDefaultAccelerator()
          Load the accelerator corresponding to the default accelerator data source specified in the user's preferences.
 java.net.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.
 java.lang.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.
static XMLDataManager managerWithFilePath(java.lang.String filePath)
          Create and return a new XMLDataManager with its source given by the specified file path.
 java.lang.String opticsDtdUrlSpec()
          Get the URL spec of the DTD file used in the optics XML file.
 java.lang.String opticsUrlSpec()
          Get the URL spec to the accelerator optics.
 void readTableGroup(EditContext editContext, java.lang.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, java.lang.String group, java.lang.String urlSpec)
          Reads the tables of the table group into the editContext getting its data from the specified URL.
static void setDefaultPath(java.lang.String path)
          Set the path to the default main data source and store it in the user's preferences.
 void setMainPath(java.lang.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(java.lang.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(java.lang.String urlSpec)
          Set the URL spec of the DTD file to use in the optics XML file.
 void setOpticsUrlSpec(java.lang.String urlSpec)
          Set the URL spec to the accelerator optics.
 void setUrlSpecForTableGroup(java.lang.String urlSpec, java.lang.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 flag
 java.lang.String urlSpecForTableGroup(java.lang.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 writeEditContext(EditContext editContext)
           
 void writeMain()
          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 writeTableGroup(EditContext editContext, java.lang.String groupName)
           
static void writeTableGroupToUrl(EditContext editContext, java.lang.String tableGroup, java.lang.String urlSpec)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIN_PATH_PREF_KEY

protected static final java.lang.String MAIN_PATH_PREF_KEY
See Also:
Constant Field Values

mainManager

protected gov.sns.xal.smf.data.XMLDataManager.MainManager mainManager

acceleratorManager

protected gov.sns.xal.smf.data.XMLDataManager.AcceleratorManager acceleratorManager

tableManager

protected gov.sns.xal.smf.data.XMLDataManager.TableManager tableManager

_timingManager

protected gov.sns.xal.smf.data.TimingDataManager _timingManager
Constructor Detail

XMLDataManager

public XMLDataManager(java.lang.String urlPath)
Creates new XMLDataManager

Method Detail

managerWithFilePath

public static XMLDataManager managerWithFilePath(java.lang.String filePath)
                                          throws UrlTool.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
UrlTool.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
See Also:
gov.sns.apps.opticsswitcher.Switcher

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:
XmlDataAdaptor.ParseException - if the TimingCenter cannot be generated

acceleratorWithUrlSpec

public static Accelerator acceleratorWithUrlSpec(java.lang.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(java.lang.String filePath)
                                       throws UrlTool.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.
UrlTool.FilePathException

acceleratorWithPath

public static Accelerator acceleratorWithPath(java.lang.String filePath,
                                              boolean isValidating)
                                       throws UrlTool.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
UrlTool.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
See Also:
gov.sns.apps.opticsswitcher.Switcher

defaultPath

public static java.lang.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
See Also:
gov.sns.apps.opticsswitcher.Switcher

setDefaultPath

public static void setDefaultPath(java.lang.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
See Also:
gov.sns.apps.opticsswitcher.Switcher, gov.sns.smf.data.OpticsSwitcher

mainUrl

public java.net.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 java.lang.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(java.lang.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(java.lang.String filePath)
                 throws UrlTool.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.
UrlTool.FilePathException

opticsUrlSpec

public java.lang.String opticsUrlSpec()
Get the URL spec to the accelerator optics.

Returns:
The URL spec to the accelerator optics.

setOpticsUrlSpec

public void setOpticsUrlSpec(java.lang.String urlSpec)
Set the URL spec to the accelerator optics.

Parameters:
urlSpec - The new URL spec to the accelerator optics.

opticsDtdUrlSpec

public java.lang.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(java.lang.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.

getTableGroups

public java.util.Collection 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:
EditContext

urlSpecForTableGroup

public java.lang.String urlSpecForTableGroup(java.lang.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(java.lang.String urlSpec,
                                    java.lang.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
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
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 accelerato to update with data from the sources
isValidating - use DTD validation if true and don't validate if false
XmlDataAdaptor.ParseException

readTableGroup

public void readTableGroup(EditContext editContext,
                           java.lang.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,
                                         java.lang.String group,
                                         java.lang.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.

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.

writeEditContext

public void writeEditContext(EditContext editContext)

writeTableGroupToUrl

public static void writeTableGroupToUrl(EditContext editContext,
                                        java.lang.String tableGroup,
                                        java.lang.String urlSpec)

writeTableGroup

public void writeTableGroup(EditContext editContext,
                            java.lang.String groupName)