Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to define dynamic enumerations in the model
xomega
#1 Posted : Monday, October 15, 2012 6:08:51 PM(UTC)
xomega



When your fields can assume only a limited set of possible values, those lists are either static and require code change when the list needs to be updated, or they can be dynamic and can be updated with no code change. Xomega provides great support for describing the static lists as enumerations in the model.

Dynamic lists though, are generally stored in a database and retrieved from there when the application runs. However, since this data doesn't really get changed very often, and yet is accessed quite frequently, it lends itself to being cached in the application layer. With that in mind, Xomega model provides an easy and flexible way to define dynamic enumerations based on an existing service operation that returns a list of values with any additional attributes. It is tailored to the Xomega Framework's support of Lookup Caches.

Here are the steps to define a dynamic enumeration in a Xomega model based on a service operation.
  1. Add a config element inside the element for the operation that returns a list of structures for the enumeration.
  2. Add an xfk:enum-cache element inside the config element, where the xfk prefix is mapped to the "http://www.xomega.net/framework" namespace.
  3. Specify a unique enumeration name by setting the enum-name attribute. This name will serve as an identifier of the lookup cache table in the Xomega Framework. If your operation returns more than one enumeration (e.g. a system dictionary), then specify the parameter in the output structure that returns the enumeration name for any given item by setting the enum-param attribute instead.
  4. Set the id-param attribute to the name of parameter in the output structure that serves as an identifier for the items, which is what will be actually stored by default when a certain item is selected.
  5. Set the desc-param attribute to the name of parameter in the output structure that serves as a description for the items, which is what will be displayed by default when selecting an item.
  6. All other parameters returned by the operation will be stored as additional attributes of each item. However, if your operation returns additional properties as a separate list of name/value pairs for each item, then you can specify that list by adding an xfk:properties element inside the xfk:enum-cache element.
  7. Set the properties-struct attribute to the name of the parameter of each item that has that list of additional properties.
  8. Set the name-param attribute to the parameter for the name of the property in the nested structure of additional properties.
  9. Set the value-param attribute to the parameter for the value of the property in the nested structure of additional properties.
  10. Generate the Lookup Cache Loaders and review the generated files. If you don't want the lookup cache loaders to be automatically registered with Xomega Framework, such as when you want to implement your own subclass of the generated loaders and register it manually, then you need to set the skip-registration attribute to true on the xfk:enum-cache element before generating the lookup cache loaders.

The following example demonstrates how to set up a dynamic enumeration for states based on a read list operation on the state province object.
Code:
<object name="state province" xmlns:xfk="http://www.xomega.net/framework">
  <operations>
    <operation name="read list">
      <output list="true">
        <param name="state province id" required="false"/>
        <param name="state province code"/>
        <param name="name"/>
        <param name="country region code"/>
      </output>
      <config>
        <xfk:enum-cache enum-name="states" id-param="state province id" desc-param="name"/>
      </config>
    </operation>
  </operations>
</object>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.