Package jmri.configurexml
Class AbstractXmlAdapter
- java.lang.Object
-
- jmri.configurexml.AbstractXmlAdapter
-
- All Implemented Interfaces:
XmlAdapter
- Direct Known Subclasses:
AbstractConnectionConfigXml
,AbstractNamedBeanManagerConfigXML
,BeanSwitchXml
,BlockBossLogicProviderXml
,ControlPanelEditorXml
,CreateButtonModelXml
,DccLocoAddressXml
,DefaultJavaBeanConfigXML
,DefaultUserMessagePreferencesXml
,EcosPreferencesXml
,EntryExitPairsXml
,FileHistoryXml
,FileLocationPaneXml
,JmrixConfigPaneXml
,LayoutEditorXml
,LayoutShapeXml
,LayoutTrackDrawingOptionsXml
,LayoutTrackViewXml
,LocoAddressXml
,ManagerDefaultsConfigPaneXml
,ManagerDefaultSelectorXml
,MeterFrameManagerXml
,OBlockManagerXml
,PanelEditorXml
,PerformActionModelXml
,PerformFileModelXml
,PerformScriptModelXml
,PositionableLabelXml
,PositionableShapeXml
,ProgrammerConfigPaneXml
,ProxyTurnoutManagerXml
,RevHistoryXml
,RosterConfigPaneXml
,SampleFunctionalClassXml
,ScriptButtonModelXml
,SimpleTimebaseXml
,StartupActionsPreferencesPanelXml
,StartupPauseModelXml
,SwitchboardEditorXml
,SystemConsoleConfigPanelXml
,TriggerRouteModelXml
,TurnoutOperationManagerXml
,TurnoutOperationXml
,WarrantManagerXml
public abstract class AbstractXmlAdapter extends java.lang.Object implements XmlAdapter
Abstract class to provide basic error handling for XmlAdapter- See Also:
XmlAdapter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractXmlAdapter.EnumIO<T extends java.lang.Enum<T>>
Base for support of Enum load/store to XML files.static class
AbstractXmlAdapter.EnumIoMapped<T extends java.lang.Enum<T>>
Support for Enum I/O to XML using explicit mapping.static class
AbstractXmlAdapter.EnumIoNames<T extends java.lang.Enum<T>>
Support for Enum I/O to XML using the enum's element names.static class
AbstractXmlAdapter.EnumIoNamesNumbers<T extends java.lang.Enum<T>>
Support for Enum I/O to XML using the enum's element names; for backward compatibility, it will also accept ordinal numbers when reading.static class
AbstractXmlAdapter.EnumIoOrdinals<T extends java.lang.Enum<T>>
Support for Enum I/O to XML using the enum's ordinal numbers in String form.
-
Constructor Summary
Constructors Constructor Description AbstractXmlAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
getAttributeBooleanValue(org.jdom2.Element element, java.lang.String name, boolean def)
Service method to handle attribute input of boolean (true/yes vs false/no) values.double
getAttributeDoubleValue(org.jdom2.Element element, java.lang.String name, double def)
Service method to handle attribute input of double values.float
getAttributeFloatValue(org.jdom2.Element element, java.lang.String name, float def)
Service method to handle attribute input of float values.int
getAttributeIntegerValue(org.jdom2.Element element, java.lang.String name, int def)
Service method to handle attribute input of integer values.ErrorHandler
getExceptionHandler()
Get the current error handler.void
handleException(java.lang.String description, java.lang.String operation, java.lang.String systemName, java.lang.String userName, java.lang.Exception exception)
Provide a simple handler for errors.boolean
load(org.jdom2.Element e)
Create a set of configured objects from their XML descriptionvoid
load(org.jdom2.Element e, java.lang.Object o)
Create a set of configured objects from their XML description, using an auxiliary object.boolean
load(org.jdom2.Element shared, org.jdom2.Element perNode)
Create a set of configured objects from their XML description.void
load(org.jdom2.Element shared, org.jdom2.Element perNode, java.lang.Object o)
Create a set of configured objects from their XML description, using an auxiliary object.boolean
loadDeferred()
Determine if this set of configured objects should be loaded after basic GUI construction is completed.int
loadOrder()
void
setExceptionHandler(ErrorHandler errorHandler)
Set the error handler that will handle any errors encountered while parsing the XML.org.jdom2.Element
store(java.lang.Object o, boolean shared)
Store the object in XML-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.configurexml.XmlAdapter
store
-
-
-
-
Constructor Detail
-
AbstractXmlAdapter
public AbstractXmlAdapter()
-
-
Method Detail
-
handleException
public void handleException(java.lang.String description, java.lang.String operation, java.lang.String systemName, java.lang.String userName, java.lang.Exception exception)
Provide a simple handler for errors. Calls the configuredErrorHandler
with anErrorMemo
created using the provided parameters.- Specified by:
handleException
in interfaceXmlAdapter
- Parameters:
description
- description of error encounteredoperation
- the operation being performed, may be nullsystemName
- system name of bean being handled, may be nulluserName
- user name of the bean being handled, may be nullexception
- Any exception being handled in the processing, may be null
-
load
public boolean load(org.jdom2.Element e) throws JmriConfigureXmlException
Create a set of configured objects from their XML description- Specified by:
load
in interfaceXmlAdapter
- Parameters:
e
- Top-level XML element containing the description- Returns:
- true if successful
- Throws:
JmriConfigureXmlException
- when a error prevents creating the objects as as required by the input XML.
-
load
public void load(org.jdom2.Element e, java.lang.Object o) throws JmriConfigureXmlException
Create a set of configured objects from their XML description, using an auxiliary object.For example, the auxilary object o might be a manager or GUI of some type that needs to be informed as each object is created.
- Specified by:
load
in interfaceXmlAdapter
- Parameters:
e
- Top-level XML element containing the descriptiono
- Implementation-specific Object needed for the conversion- Throws:
JmriConfigureXmlException
- when a error prevents creating the objects as as required by the input XML
-
load
public boolean load(@Nonnull org.jdom2.Element shared, org.jdom2.Element perNode) throws JmriConfigureXmlException
Create a set of configured objects from their XML description.- Specified by:
load
in interfaceXmlAdapter
- Parameters:
shared
- Top-level XML element containing the common, multi-node elements of the descriptionperNode
- Top-level XML element containing the private, single-node elements of the description- Returns:
- true if successful
- Throws:
JmriConfigureXmlException
- when a error prevents creating the objects as as required by the input XML
-
load
public void load(@Nonnull org.jdom2.Element shared, org.jdom2.Element perNode, java.lang.Object o) throws JmriConfigureXmlException
Create a set of configured objects from their XML description, using an auxiliary object.For example, the auxilary object o might be a manager or GUI of some type that needs to be informed as each object is created.
- Specified by:
load
in interfaceXmlAdapter
- Parameters:
shared
- Top-level XML element containing the common descriptionperNode
- Top-level XML element containing the per-node descriptiono
- Implementation-specific Object needed for the conversion- Throws:
JmriConfigureXmlException
- when a error prevents creating the objects as as required by the input XML
-
loadDeferred
public boolean loadDeferred()
Determine if this set of configured objects should be loaded after basic GUI construction is completed.Default behavior is to load when requested. Classes that should wait until basic GUI is constructed should override this method and return true
- Specified by:
loadDeferred
in interfaceXmlAdapter
- Returns:
- true to defer loading
- Since:
- 2.11.2
- See Also:
XmlAdapter.loadDeferred()
-
loadOrder
public int loadOrder()
- Specified by:
loadOrder
in interfaceXmlAdapter
-
store
public org.jdom2.Element store(@Nonnull java.lang.Object o, boolean shared)
Store the object in XML- Specified by:
store
in interfaceXmlAdapter
- Parameters:
o
- The object to be recorded. Specific XmlAdapter implementations will require this to be of a specific type; that binding is done in ConfigXmlManager.shared
- true if the returned element should be the common XML and false if the returned element should be per-node.- Returns:
- The XML representation Element
-
setExceptionHandler
public void setExceptionHandler(ErrorHandler errorHandler)
Set the error handler that will handle any errors encountered while parsing the XML. If not specified, the default error handler will be used.- Specified by:
setExceptionHandler
in interfaceXmlAdapter
- Parameters:
errorHandler
- the error handler or null to ignore parser errors
-
getExceptionHandler
public ErrorHandler getExceptionHandler()
Get the current error handler.- Specified by:
getExceptionHandler
in interfaceXmlAdapter
- Returns:
- the error handler or null if no error handler is assigned
-
getAttributeBooleanValue
public final boolean getAttributeBooleanValue(@Nonnull org.jdom2.Element element, @Nonnull java.lang.String name, boolean def)
Service method to handle attribute input of boolean (true/yes vs false/no) values. Not being present is not an error. Not parsing (which shouldn't happen due to the XML Schema checks) invokes the default error handler.- Parameters:
element
- the element to parse.name
- element attribute name.def
- default value if name not present in element.- Returns:
- boolean value of attribute, else default if not present or error.
-
getAttributeIntegerValue
public final int getAttributeIntegerValue(@Nonnull org.jdom2.Element element, @Nonnull java.lang.String name, int def)
Service method to handle attribute input of integer values. Not being present is not an error. Not parsing (which shouldn't happen due to the XML Schema checks) invokes the default error handler.- Parameters:
element
- the element to parse.name
- element attribute name.def
- default value if name not present in element.- Returns:
- integer value of attribute, else default if not present or error.
-
getAttributeDoubleValue
public final double getAttributeDoubleValue(@Nonnull org.jdom2.Element element, @Nonnull java.lang.String name, double def)
Service method to handle attribute input of double values. Not being present is not an error. Not parsing (which shouldn't happen due to the XML Schema checks) invokes the default error handler.- Parameters:
element
- the element to parse.name
- element attribute name.def
- default value if name not present in element.- Returns:
- double value of attribute, else default if not present or error.
-
getAttributeFloatValue
public final float getAttributeFloatValue(@Nonnull org.jdom2.Element element, @Nonnull java.lang.String name, float def)
Service method to handle attribute input of float values. Not being present is not an error. Not parsing (which shouldn't happen due to the XML Schema checks) invokes the default error handler.- Parameters:
element
- the element to parse.name
- element attribute name.def
- default value if name not present in element.- Returns:
- float value of attribute, else default if not present or error.
-
-