Class AbstractXmlAdapter

java.lang.Object
jmri.configurexml.AbstractXmlAdapter
All Implemented Interfaces:
XmlAdapter
Direct Known Subclasses:
AbstractConnectionConfigXml, AbstractNamedBeanManagerConfigXML, AnalogClock2DisplayXml, BeanSwitchXml, BlockBossLogicProviderXml, ControlPanelEditorXml, CreateButtonModelXml, DccLocoAddressXml, DefaultJavaBeanConfigXML, DefaultUserMessagePreferencesXml, EcosPreferencesXml, EntryExitPairsXml, FileHistoryXml, FileLocationPaneXml, GuiLafConfigPaneXml, JmrixConfigPaneXml, LayoutEditorXml, LayoutShapeXml, LayoutSlipViewXml, LayoutTrackDrawingOptionsXml, LayoutTurnoutViewXml, LayoutTurntableViewXml, LevelXingViewXml, LocoAddressXml, ManagerDefaultsConfigPaneXml, ManagerDefaultSelectorXml, MeterFrameManagerXml, OBlockManagerXml, PanelEditorXml, PerformActionModelXml, PerformActionModelXml, PerformFileModelXml, PerformFileModelXml, PerformScriptModelXml, PerformScriptModelXml, PositionableLabelXml, PositionablePointViewXml, PositionableShapeXml, ProgrammerConfigPaneXml, ProxyTurnoutManagerXml, RevHistoryXml, RosterConfigPaneXml, SampleFunctionalClassXml, ScriptButtonModelXml, SimpleTimebaseXml, StartupActionsPreferencesPanelXml, StartupPauseModelXml, SwitchboardEditorXml, SystemConsoleConfigPanelXml, TrackSegmentViewXml, TriggerRouteModelXml, TurnoutOperationManagerXml, TurnoutOperationXml, WarrantManagerXml

public abstract class AbstractXmlAdapter
extends Object
implements XmlAdapter
Abstract class to provide basic error handling for XmlAdapter
See Also:
XmlAdapter
  • Constructor Details

  • Method Details

    • handleException

      public void handleException​(String description, String operation, String systemName, String userName, Exception exception)
      Provide a simple handler for errors. Calls the configured ErrorHandler with an ErrorMemo created using the provided parameters.
      Specified by:
      handleException in interface XmlAdapter
      Parameters:
      description - description of error encountered
      operation - the operation being performed, may be null
      systemName - system name of bean being handled, may be null
      userName - user name of the bean being handled, may be null
      exception - Any exception being handled in the processing, may be null
    • load

      public boolean load​(Element e) throws JmriConfigureXmlException
      Create a set of configured objects from their XML description
      Specified by:
      load in interface XmlAdapter
      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​(Element e, 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 interface XmlAdapter
      Parameters:
      e - Top-level XML element containing the description
      o - 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 Element shared, Element perNode) throws JmriConfigureXmlException
      Create a set of configured objects from their XML description.
      Specified by:
      load in interface XmlAdapter
      Parameters:
      shared - Top-level XML element containing the common, multi-node elements of the description
      perNode - 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 Element shared, 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:
      load in interface XmlAdapter
      Parameters:
      shared - Top-level XML element containing the common description
      perNode - Top-level XML element containing the per-node description
      o - 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 interface XmlAdapter
      Returns:
      true to defer loading
      Since:
      2.11.2
      See Also:
      XmlAdapter.loadDeferred()
    • loadOrder

      public int loadOrder()
      Specified by:
      loadOrder in interface XmlAdapter
    • store

      public Element store​(@Nonnull Object o, boolean shared)
      Store the object in XML
      Specified by:
      store in interface XmlAdapter
      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 interface XmlAdapter
      Parameters:
      errorHandler - the error handler or null to ignore parser errors
    • getExceptionHandler

      Get the current error handler.
      Specified by:
      getExceptionHandler in interface XmlAdapter
      Returns:
      the error handler or null if no error handler is assigned
    • getAttributeBooleanValue

      public final boolean getAttributeBooleanValue​(@Nonnull 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 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 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 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.