com.ihr.xbrl.mapper.source

## Interface XBRLDataSource

- All Known Implementing Classes:
    AbstractWorksheetDataSource, CSVDataSource, ExcelDataSource, JNDIDataSource, SQLDataSource, VoidDataSource, WebFormDataSource, XBRLFileDataSource

      public interface XBRLDataSource

  This is the interface that describes methods required to be implemented by drivers. Drivers are classes that will act as data provider to create an XBRL instance document.

  XBRLDataSources can be develop for Relational Databases, Excel Spreadsheets, TXT files, web services, API calls to existing ERPs, etc.

  The MapperEngine and the driver establish a dialog to obtain the data for the preparation of the instance document. The dialog has specific order and the order is the following:

  `startOfDocument(XBRLInstance, Object[], DTSLoadingBarInterface)`
  `getNumberOfValues(String, Fact)`
  if previous function returns a number greater than 0 then the following loop is performed for each fact
  `startOfFact(String, QName)`
  `getContext(String, int, XBRLContext)`
  `isNil(String, int, XMLElementDefinition)`
  `getValue(String, int, XBRLContext, SimpleType)`
  `getUnit(String, int, XBRLContext, XBRLUnit)`
  `getFormat(String, int, XBRLContext, XBRLUnit)`
  `getFormatValue(String, int, XBRLContext, XBRLUnit)`
  `getFootnote(String, int, XBRLFact)`
  `getFootnoteLang(String, int, XBRLFact, Object)`
  `endOfFact(String, QName)`
  `endOfDocument(XBRLInstance)`

  Other methods serves different purposes and are out of the dialog:

  `createConfigFileContent()` must be implemented by drivers that interacts with the MapperEditor. This method should create a configuration file for the driver is the driver is selected in the GUI.

  `getConfigFile()` must be implemented to return this drivers' absolute URI configuration file.

  `getSampleData(Object)` must be implemented if this driver will be integrated with the MapperEngine the parameter passed to this function is an object of arbitrary type like an URI of a file. the returned object will be the input object for the driver to generate values. For example, the excel driver will convert an URI into an HSSFWorkBook object.

  `init()` called when the mapper instantiates this driver

  `isConfigfileRequired()` boolean value that indicates if this driver requires a configuration file or not

  `save()` called by the GUI to serialize the configuration parameters in a file

  `setConfigFile(URI)` called from the MapperEditor to set the file name for the configuration file

  The cycle for creating an instance of a XBRLDataSource is:

  1. The object is created using the newInstance() method of the indicated class with no arguments
  2. The setConfigFile(URI) method is called with the configuration file
  3. The init() method is called
  Author:
    Ignacio
  See Also:
    `setConfigFile(URI)`, `init()`

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `createConfigFileContent()` This function is used by the GUI during the generation of a new mapper.
    `void` | `endOfDocument(XBRLInstance instance)` Called by the MapEngine when a new instance is finished Can be used to close connections to data sources.
    `void` | `endOfFact(java.lang.String mapIdentifier, javax.xml.namespace.QName factName)` Called by the MapEngine when a new fact is finalized returns nothing.
    `boolean` | `equals(java.lang.Object obj)` Equals.
    `java.net.URI` | `getConfigFile()` Access to the name of the configuration file.
    `XBRLContext` | `getContext(java.lang.String mapIdentifier, int index, XBRLContext context)` Each data item has mapIdentifier string each used concept in the taxonomy has at least one mapIdentifier returns the XBRLContext to be used for the fact item.
    `java.lang.Object` | `getFootnote(java.lang.String mapIdentifier, int index, XBRLFact fact)` After a fact is produced the data source is asked for a footnote to be added to the instance document by doing a call to this method.
    `java.lang.String` | `getFootnoteLang(java.lang.String mapIdentifier, int index, XBRLFact fact, java.lang.Object footnoteContent)` After a footnote resource is create it MUST have an xml:lang attribute.
    `int` | `getFormat(java.lang.String mapIdentifier, int index, XBRLContext context, XBRLUnit localUnit)` Ask the driver for the preferred serialization for the numeric data.
    `java.lang.String` | `getFormatValue(java.lang.String mapIdentifier, int index, XBRLContext context, XBRLUnit localUnit)` Returns the value (as string) for the data format.
    `java.lang.Object[]` | `getMapIdentifierReferences(java.lang.String mapIdentifier)` This method is used to automatically generate loader files from mapper files.
    `int` | `getNumberOfValues(java.lang.String mapIdentifier, Fact fact)` Each data item has mapIdentifier string, each used concept in the taxonomy has at least one mapIdentifier This method returns the number of facts in the source that corresponds to the mapIdentifier string.
    `java.lang.Object` | `getSampleData(java.lang.Object data)` This method is used by the mapper editor during test cycles of the mapper The implemented class should use the incoming data to produce an object that the mapper can use later to produce an instance document .
    `java.lang.String` | `getSourceReference(java.lang.String mapIdentifier, int index, XBRLContext localContext, net.sf.saxon.type.SimpleType theType)` Returns a string that describes the source of data for a specific mapIdentifier, index, localContext and data type This method is used in order to build an error message that takes into consideration where the data comes from so the user can better track the path the data is following inside the tools.
    `XBRLUnit` | `getUnit(java.lang.String mapIdentifier, int index, XBRLContext localContext, XBRLUnit unit)` Each time a numeric concept is created this function is called to request or change the required unit.
    `net.sf.saxon.value.AtomicValue` | `getValue(java.lang.String mapIdentifier, int index, XBRLContext context, net.sf.saxon.type.SimpleType schemaType)` Each data item has mapIdentifier string each used concept in the taxonomy has at least one mapIdentifier returns the Value to be sent to the fact item. null is allowed and will be considered as no input data available
    `int` | `hashCode()` Hash code.
    `void` | `init()` Called by the mapping engine once the object is created.
    `boolean` | `isConfigfileRequired()` Returns true if the configuration file is required for this XBRLDataSource.
    `boolean` | `isInputFileRequired()` Returns true if this driver requires an input file.
    `boolean` | `isNil(java.lang.String mapIdentifier, int index, XMLElementDefinition concept)` Return true if the concept content is xsi:nil so there will be no request for a value.
    `boolean` | `isTupleSourceRequired()` Returns a boolean value indicating if the source format has a meaning to indicate the number of occurrences of a tuple.
    `void` | `save()` Save the content of the configuration file to disk.
    `void` | `setConfigFile(java.net.URI configFile)` Sets the configuration file for this XBRLDataSource.
    `void` | `startOfDocument(XBRLInstance instance, java.lang.Object[] inputs, DTSLoadingBarInterface bar)` Called by the MapEngine when a new instance that requires this data source is going to be created.
    `void` | `startOfFact(java.lang.String mapIdentifier, javax.xml.namespace.QName factName)` Called by the MapEngine when a new fact is about to be started Return nothing.
    `boolean` | `verifyRule(Section section)` Checks the current driver for a rule for section passed in in the parameter.

- - ### Method Detail

    - #### startOfDocument

          void startOfDocument(XBRLInstance instance,
                             java.lang.Object[] inputs,
                             DTSLoadingBarInterface bar)
                               throws MapException

      Called by the MapEngine when a new instance that requires this data source is going to be created. Can be used to open connections to data sources. Be careful when processing the inputs because the same mapper could use more than one driver and inputs are shared across all the drivers. Don't assume there will always be just one driver providing data to the mapper.
      Parameters:
        `instance` - this is the instance document.
        `inputs` - Input parameters, they are different objects for each driver.
        `bar` - this is an optional parameter, if not null, the driver can send messages to inform about the initialization process
      Throws:
        `MapException` - the map exception

    - #### endOfDocument

          void endOfDocument(XBRLInstance instance)

      Called by the MapEngine when a new instance is finished Can be used to close connections to data sources.
      Parameters:
        `instance` - XBRLInstance

    - #### startOfFact

          void startOfFact(java.lang.String mapIdentifier,
                         javax.xml.namespace.QName factName)

      Called by the MapEngine when a new fact is about to be started Return nothing. It is used to inform the "other side" and can be used to attach resources
      Parameters:
        `mapIdentifier` - String
        `factName` - QName

    - #### endOfFact

          void endOfFact(java.lang.String mapIdentifier,
                       javax.xml.namespace.QName factName)

      Called by the MapEngine when a new fact is finalized returns nothing. It is used to inform the "other side" and can be used to free-up resources.
      Parameters:
        `mapIdentifier` - the map identifier
        `factName` - the fact name

    - #### getNumberOfValues

          int getNumberOfValues(java.lang.String mapIdentifier,
                              Fact fact)

      Each data item has mapIdentifier string, each used concept in the taxonomy has at least one mapIdentifier This method returns the number of facts in the source that corresponds to the mapIdentifier string. Normally this is 1 but there may be cases in which more are returned by the source. Facts inside tuples often returns more than one. Facts with dimensions may be mappend using different map identifiers for each dimension combination.
      Parameters:
        `mapIdentifier` - the map identifier
        `fact` - the fact
      Returns:
        int

    - #### getContext

          XBRLContext getContext(java.lang.String mapIdentifier,
                               int index,
                               XBRLContext context)

      Each data item has mapIdentifier string each used concept in the taxonomy has at least one mapIdentifier returns the XBRLContext to be used for the fact item. Or the proposed context if no modifications are required. MUST not return null.
      Parameters:
        `mapIdentifier` - String
        `index` - int
        `context` - XBRLContext the context proposed by the mapping engine. If the context is modified it will be modified for all concepts using this context. So if the context requires modifications for a specified fact it would be better to clone the context before modifications are performed.
      Returns:
        net.sf.saxon.Value

    - #### getValue

          net.sf.saxon.value.AtomicValue getValue(java.lang.String mapIdentifier,
                                                int index,
                                                XBRLContext context,
                                                net.sf.saxon.type.SimpleType schemaType)
                                                  throws MapException

      Each data item has mapIdentifier string each used concept in the taxonomy has at least one mapIdentifier returns the Value to be sent to the fact item. null is allowed and will be considered as no input data available
      Parameters:
        `mapIdentifier` - String
        `index` - int
        `context` - XBRLContext the XBRL Context for the fact being reported. The context should not be modified here.
        `schemaType` - This is that target schema type obtained from the element definition
      Returns:
        net.sf.saxon.Value
      Throws:
        `MapException` - the map exception

    - #### getFootnote

          java.lang.Object getFootnote(java.lang.String mapIdentifier,
                                     int index,
                                     XBRLFact fact)

      After a fact is produced the data source is asked for a footnote to be added to the instance document by doing a call to this method. If this method returns null then the concept has no text in a footnote. If this method returns a java.lang.String then the string text will be added as a footnote to the instance document. If this method returns a org.jdom.Content
      Parameters:
        `mapIdentifier` - String
        `index` - int
        `fact` - XBRLFactItem
      Returns:
        Object , null, String or Content

    - #### getFootnoteLang

          java.lang.String getFootnoteLang(java.lang.String mapIdentifier,
                                         int index,
                                         XBRLFact fact,
                                         java.lang.Object footnoteContent)

      After a footnote resource is create it MUST have an xml:lang attribute. This function is called by the mapping engine in order to obtain the value of the xml:lang attribute for a particular footnote
      Parameters:
        `mapIdentifier` - the map identifier
        `index` - the index
        `fact` - the fact
        `footnoteContent` - the footnote content
      Returns:
        String

    - #### isNil

          boolean isNil(java.lang.String mapIdentifier,
                      int index,
                      XMLElementDefinition concept)

      Return true if the concept content is xsi:nil so there will be no request for a value.
      Parameters:
        `mapIdentifier` - the map identifier
        `index` - the index
        `concept` - the concept
      Returns:
        boolean

    - #### init

          void init()
                    throws MapConfigurationFileException

      Called by the mapping engine once the object is created. Allows the driver to read the configuration file for the driver.
      Throws:
        `MapConfigurationFileException` - the map configuration file exception

    - #### setConfigFile

          void setConfigFile(java.net.URI configFile)

      Sets the configuration file for this XBRLDataSource. If the driver requires no configuration file the argument configFile is null
      Parameters:
        `configFile` - the new config file

    - #### getConfigFile

          java.net.URI getConfigFile()

      Access to the name of the configuration file.
      Returns:
        URI of the configuration file or null if not needed or not set

    - #### getUnit

          XBRLUnit getUnit(java.lang.String mapIdentifier,
                         int index,
                         XBRLContext localContext,
                         XBRLUnit unit)

      Each time a numeric concept is created this function is called to request or change the required unit. If no change is required then unit (the incoming parameter) must be returned
      Parameters:
        `mapIdentifier` - String code
        `index` - int indicating which value we are working on
        `localContext` - the context for the new data
        `unit` - the proposed unit. Can be changed
      Returns:
        XBRLUnit the original unit or a new unit to use

    - #### getFormat

          int getFormat(java.lang.String mapIdentifier,
                      int index,
                      XBRLContext context,
                      XBRLUnit localUnit)

      Ask the driver for the preferred serialization for the numeric data. One of XBRLNumericValue.DECIMALS or XBRLNumericValue.PRECISION constants must be returned
      Parameters:
        `mapIdentifier` - the map identifier
        `index` - the index
        `context` - the context
        `localUnit` - the local unit
      Returns:
        integer

    - #### getFormatValue

          java.lang.String getFormatValue(java.lang.String mapIdentifier,
                                        int index,
                                        XBRLContext context,
                                        XBRLUnit localUnit)

      Returns the value (as string) for the data format. "INF" means infinite. integers (positive and negative) can be set for decimals="-6" (millions of the specified unit etc).
      Parameters:
        `mapIdentifier` - the map identifier
        `index` - the index
        `context` - the context
        `localUnit` - the local unit
      Returns:
        String

    - #### getSampleData

          java.lang.Object getSampleData(java.lang.Object data)
                                         throws MapException

      This method is used by the mapper editor during test cycles of the mapper The implemented class should use the incoming data to produce an object that the mapper can use later to produce an instance document .
      Parameters:
        `data` - object
      Returns:
        another object
      Throws:
        `MapException` - in the case the input object cannot be used

    - #### isConfigfileRequired

          boolean isConfigfileRequired()

      Returns true if the configuration file is required for this XBRLDataSource. Returns false if it is optional or not required at all.
      Returns:
        boolean value

    - #### createConfigFileContent

          void createConfigFileContent()

      This function is used by the GUI during the generation of a new mapper. Generates a sample configuration file that can be loaded by the XBRLDataSource without generating java exceptions.

    - #### save

          void save()
                    throws MapException

      Save the content of the configuration file to disk. This method is called by the GUI when the mapper has changes in the configuration and the configuration requires to be serialized to disk
      Throws:
        `MapException` - in the event of problems like IOException

    - #### isInputFileRequired

          boolean isInputFileRequired()

      Returns true if this driver requires an input file. This function is used by the GUI in order to enable or disable the "Test Mapper" menu item depending on whether or not input files are required
      Returns:
        boolean

    - #### isTupleSourceRequired

          boolean isTupleSourceRequired()

      Returns a boolean value indicating if the source format has a meaning to indicate the number of occurrences of a tuple.

      This information is used during the algorithm for generating a template file automatically.

      Excel Data Source, for example, does not provides a meaning to indicate the number of occurrences of a tuple. The number of occurrences will be indicated in the instance document template itself. SQL Data Source, is on the other side. The SQL Driver and the source format may have information to provide the number of occurrences for a tuple.

      Note, once a template has been automatically generated. it is up to the team to change the generated template into something different if this is required by the project.

      Returns:
        boolean value.

    - #### getSourceReference

          java.lang.String getSourceReference(java.lang.String mapIdentifier,
                                            int index,
                                            XBRLContext localContext,
                                            net.sf.saxon.type.SimpleType theType)

      Returns a string that describes the source of data for a specific mapIdentifier, index, localContext and data type

      This method is used in order to build an error message that takes into consideration where the data comes from so the user can better track the path the data is following inside the tools.

      Parameters:
        `mapIdentifier` - current map identifier
        `index` - current index for the map identifier
        `localContext` - XBRL context for the generated fact
        `theType` - data type as SimpleType
      Returns:
        String with target description

    - #### verifyRule

          boolean verifyRule(Section section)

      Checks the current driver for a rule for section passed in in the parameter. If the rule is satisfied the return value shall be true, otherwise, the return value shall be false.

      This method is called only if the fact contains a sectionRef and the sectionRef contains a rule.

      The algorithm to determine the output value is driver dependant and there is no default value.

      If the return value is true, the fact will be included to the output instance and all files in the section will be added to the DTS. If the return value is false, the fact will be skipped.

      Parameters:
        `section` - the section
      Returns:
        boolean value

    - #### getMapIdentifierReferences

          java.lang.Object[] getMapIdentifierReferences(java.lang.String mapIdentifier)

      This method is used to automatically generate loader files from mapper files.
      Parameters:
        `mapIdentifier` - the map identifier
      Returns:
        the map identifier references

    - #### hashCode

          int hashCode()

      Hash code.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        the int

    - #### equals

          boolean equals(java.lang.Object obj)

      Equals.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `obj` - the obj
      Returns:
        true, if successful