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
Abstract class to provide basic error handling for XmlAdapter
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstractXmlAdapter.EnumIO<T extends Enum<T>>Base for support of Enum load/store to XML files.static classAbstractXmlAdapter.EnumIoMapped<T extends Enum<T>>Support for Enum I/O to XML using explicit mapping.static classAbstractXmlAdapter.EnumIoNames<T extends Enum<T>>Support for Enum I/O to XML using the enum's element names.static classAbstractXmlAdapter.EnumIoNamesNumbers<T extends 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 classAbstractXmlAdapter.EnumIoOrdinals<T extends Enum<T>>Support for Enum I/O to XML using the enum's ordinal numbers in String form. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleangetAttributeBooleanValue(org.jdom2.Element element, String name, boolean def) Service method to handle attribute input of boolean (true/yes vs false/no) values.final doublegetAttributeDoubleValue(org.jdom2.Element element, String name, double def) Service method to handle attribute input of double values.final floatgetAttributeFloatValue(org.jdom2.Element element, String name, float def) Service method to handle attribute input of float values.final intgetAttributeIntegerValue(org.jdom2.Element element, String name, int def) Service method to handle attribute input of integer values.Get the current error handler.voidhandleException(String description, String operation, String systemName, String userName, Exception exception) Provide a simple handler for errors.booleanload(org.jdom2.Element e) Create a set of configured objects from their XML descriptionvoidCreate a set of configured objects from their XML description, using an auxiliary object.booleanload(org.jdom2.Element shared, org.jdom2.Element perNode) Create a set of configured objects from their XML description.voidCreate a set of configured objects from their XML description, using an auxiliary object.booleanDetermine if this set of configured objects should be loaded after basic GUI construction is completed.intvoidsetExceptionHandler(ErrorHandler errorHandler) Set the error handler that will handle any errors encountered while parsing the XML.org.jdom2.ElementStore the object in XMLMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.configurexml.XmlAdapter
store
-
Field Details
-
STR_TRUE
- See Also:
-
STR_FALSE
- See Also:
-
STR_YES
- See Also:
-
STR_NO
- See Also:
-
-
Constructor Details
-
AbstractXmlAdapter
public AbstractXmlAdapter()
-
-
Method Details
-
handleException
public void handleException(String description, String operation, String systemName, String userName, Exception exception) Provide a simple handler for errors. Calls the configuredErrorHandlerwith anErrorMemocreated using the provided parameters.- Specified by:
handleExceptionin 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
Create a set of configured objects from their XML description- Specified by:
loadin 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
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:
loadin 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:
loadin 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, 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:
loadin 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
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:
loadDeferredin interfaceXmlAdapter- Returns:
- true to defer loading
- Since:
- 2.11.2
- See Also:
-
loadOrder
- Specified by:
loadOrderin interfaceXmlAdapter
-
store
Store the object in XML- Specified by:
storein 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
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:
setExceptionHandlerin interfaceXmlAdapter- Parameters:
errorHandler- the error handler or null to ignore parser errors
-
getExceptionHandler
Get the current error handler.- Specified by:
getExceptionHandlerin interfaceXmlAdapter- Returns:
- the error handler or null if no error handler is assigned
-
getAttributeBooleanValue
public final boolean getAttributeBooleanValue(@Nonnull org.jdom2.Element element, @Nonnull 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 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 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 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.
-