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 classAbstractXmlAdapter.EnumIO<T extends java.lang.Enum<T>>Base for support of Enum load/store to XML files.static classAbstractXmlAdapter.EnumIoMapped<T extends java.lang.Enum<T>>Support for Enum I/O to XML using explicit mapping.static classAbstractXmlAdapter.EnumIoNames<T extends java.lang.Enum<T>>Support for Enum I/O to XML using the enum's element names.static classAbstractXmlAdapter.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 classAbstractXmlAdapter.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 booleangetAttributeBooleanValue(org.jdom2.Element element, java.lang.String name, boolean def)Service method to handle attribute input of boolean (true/yes vs false/no) values.doublegetAttributeDoubleValue(org.jdom2.Element element, java.lang.String name, double def)Service method to handle attribute input of double values.floatgetAttributeFloatValue(org.jdom2.Element element, java.lang.String name, float def)Service method to handle attribute input of float values.intgetAttributeIntegerValue(org.jdom2.Element element, java.lang.String name, int def)Service method to handle attribute input of integer values.ErrorHandlergetExceptionHandler()Get the current error handler.voidhandleException(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.booleanload(org.jdom2.Element e)Create a set of configured objects from their XML descriptionvoidload(org.jdom2.Element e, java.lang.Object o)Create 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.voidload(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.booleanloadDeferred()Determine if this set of configured objects should be loaded after basic GUI construction is completed.intloadOrder()voidsetExceptionHandler(ErrorHandler errorHandler)Set the error handler that will handle any errors encountered while parsing the XML.org.jdom2.Elementstore(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
-
-
-
-
Field Detail
-
STR_TRUE
public static final java.lang.String STR_TRUE
- See Also:
- Constant Field Values
-
STR_FALSE
public static final java.lang.String STR_FALSE
- See Also:
- Constant Field Values
-
STR_YES
public static final java.lang.String STR_YES
- See Also:
- Constant Field Values
-
STR_NO
public static final java.lang.String STR_NO
- See Also:
- Constant Field Values
-
-
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 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
public boolean load(org.jdom2.Element e) throws JmriConfigureXmlException
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
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:
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, 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:
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
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:
loadDeferredin interfaceXmlAdapter- Returns:
- true to defer loading
- Since:
- 2.11.2
- See Also:
XmlAdapter.loadDeferred()
-
loadOrder
public int loadOrder()
- Specified by:
loadOrderin interfaceXmlAdapter
-
store
public org.jdom2.Element store(@Nonnull java.lang.Object o, boolean shared)
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
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:
setExceptionHandlerin interfaceXmlAdapter- Parameters:
errorHandler- the error handler or null to ignore parser errors
-
getExceptionHandler
public ErrorHandler 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 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.
-
-