Data Services

Top  Previous  Next

The data required by the application can be acquired from different sources such as Databases, files, web services, etc. The MoreMotion provides a standard interface for the classes that supposed to populate data by accessing to different sources. The responsibility of a data service class is to populate data and place into the ADOM object passed to it.

Data Request

The need for data in a page is expressed with dataRequest configuration element in the Page Configuration.

Page Configuration:

  <dataRequest name="products" dataSource="products" selectAll="true" />

See below how the data, that is requested with data request "products", is used in XSLT stylesheet.

XSL StyleSheet:

  <xsl:for-each select="/root/products/item">
    <tr>
      <td><xsl:value-of select="NAME" /></td>
    </tr>
  </xsl:for-each>

A Page XML Data is prepared prior to the XSLT processing and it contains the XML data required by the stylesheet.

Page XML Data:

  <root>
    <products>
      <item>
        <NAME>Computer</NAME>
      </item>
    </products>
  </root>

The name of the root element of the Page XML Data is always "root". The second level elements are called data request names. The Page XML data may contain 0 or more second level XML elements depending on the data request defined in the configuration.

Data Request Definitions in Page Configuration:

  <dataRequest name="products" dataSource="products" selectAll="true" />
  <dataRequest name="customers" dataSource="customers" selectAll="true" />

Page XML Data:

   <root>
    <products>
      ...
    </products>
    <customers>
      ...
    </customers>
  </root>

If the name of a data request is identical with the name of the data source then the dataSource attribute of the dataRequest element can be omitted.

Page Configuration:

  <dataRequest name="products" selectAll="true" />
  <dataRequest name="customers" selectAll="true" />

The selectAll attribute specifies that all the data provided by the data source should be transferred to the Page XML Data. If the value of the selectAll attribute is "false" then node child element(s) should also be provided to specify which of the data nodes provided by the data source should be included in the Page XML Data.

Page Configuration:

  <dataRequest name="products" selectAll="false">
    <node name="NAME" />
  </dataRequest>
 
  <dataRequest name="customers" selectAll="true" /> 

See Data Request Configuration.

Data Source

The data requests are linked to data sources in the configuration. A data source is defined with dataSource configuration element in the configuration.

Page Configuration:

  <dataRequest name="products" dataSource="products" selectAll="true" />
 
  <dataSource name="products">
    <class>org.moremotion.reldb.RelDBQueryDataService</class>
    <conn>SS</conn>
    <scope>Request</scope>
    <query>select * from products</query>
  </dataSource> 

A data source is nothing but a definition of the responsible Data Service Class and its parameters. A data source definition must include a class element. The value of the class element should be the name of a Java class that implements org.moremotion.datasrc.DataService interface.

See Data Source Configuration.