Class FWSimResourceAdapter<T>

Type Parameters:
T - type of the data provided by the FWSimInterface
All Implemented Interfaces:
FWSimFieldContainer
Direct Known Subclasses:
CSVResourceAdapter, DatabaseResourceAdapter, JSONResourceAdapter, NetCDFResourceAdapter, XMLResourceAdapter

public abstract class FWSimResourceAdapter<T> extends FWSimInputAdapter
Resource adapters read data from an interface (FWSimInterface) into a FWSimResourceCache. They are specific to the media type of the interface (CSV, database, DBF/SHP, NetCDF, XML, JSON); the matching adapter is created by createResourceAdapter(FWSimSession, Element, int).
Author:
Andreas Enders
  • Field Details

    • iLinesToRead

      protected Integer[] iLinesToRead
      lines of the resource to read, or null for all
  • Constructor Details

    • FWSimResourceAdapter

      protected FWSimResourceAdapter(org.jdom2.Element aResourceElement, FWSimSession aCurrentSession, int aOrderNumber)
      Creates the adapter from a resource element of the solution.
      Parameters:
      aResourceElement - the resource element
      aCurrentSession - the session
      aOrderNumber - order number of the adapter
    • FWSimResourceAdapter

      public FWSimResourceAdapter(org.jdom2.Element aResourceElement, String aName, int aOrderNumber, FWSimInterface<?> aInterface, FWSimIOAdapter.FREQUENCE aFrequence, FWSimSession aFwSimSession)
      Creates the adapter from the graph panel.
      Parameters:
      aResourceElement - the resource element
      aName - name (id) of the adapter
      aOrderNumber - order number of the adapter
      aInterface - interface to read from
      aFrequence - frequency the data is read with
      aFwSimSession - the session
    • FWSimResourceAdapter

      public FWSimResourceAdapter(FWSimResourceAdapter<?> aAdapter, FWSimInterface<?> aInterface)
      Copy constructor used when the interface of an adapter is replaced.
      Parameters:
      aAdapter - the adapter to copy
      aInterface - the new interface
  • Method Details

    • createResourceAdapter

      public static FWSimResourceAdapter createResourceAdapter(FWSimSession aSession, org.jdom2.Element aResourceElement, int aOrderNumber) throws MissingSimResourceException, DuplicateSimFieldException
      Factory method: creates the resource adapter matching the type of the interface named in the attribute interface (SHP and DBF share one adapter).
      Parameters:
      aSession - the session
      aResourceElement - the resource element
      aOrderNumber - order number of the adapter
      Returns:
      the created adapter
      Throws:
      MissingSimResourceException - if no interface is given, the interface does not exist or its type is not supported
      DuplicateSimFieldException - if a resource with the same id already exists
    • getLinesToRead

      public Integer[] getLinesToRead()
      Returns:
      the lines of the resource to read, or null for all
    • setLinesToRead

      public void setLinesToRead(Integer[] aLinesToRead)
      Parameters:
      aLinesToRead - the lines of the resource to read, or null for all
    • updateAdapter

      public static FWSimResourceAdapter updateAdapter(FWSimResourceAdapter<?> aOldAdapter, FWSimInterface<?> aInterface)
      Factory method: creates a copy of an adapter for a new interface, with the adapter class matching the interface type.
      Parameters:
      aOldAdapter - the adapter to copy
      aInterface - the new interface
      Returns:
      the new adapter, or null if the interface type is not supported (e.g. MEMORY, CUSTOM)
    • toXML

      public org.jdom2.Element toXML()
      Creates the resource element with id, interface, frequency, rule, dbcache and header.
      Returns:
      an XML element with all settings of this container
      See Also:
    • createAdapterFromObservable

      public static FWSimFieldContainer createAdapterFromObservable(FWObservable aObservable, FWSimSession aFwSimSession, int aOrderNumber) throws MissingSimResourceException
      Creates a resource adapter from the data of the GUI form (fields Name, Datatype, Frequence and, depending on the type, Driver, URL, User, Pass, Statement or File, Content). Supported types are DATABASE, CSV (the divider is chosen in a preview dialog) and XML.
      Parameters:
      aObservable - the form data
      aFwSimSession - the session
      aOrderNumber - order number of the adapter
      Returns:
      the created adapter, or null if creating it failed (the error is logged)
      Throws:
      MissingSimResourceException - if the type is not supported