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

Notification

Icon
Error

How to define static enumerations in the model
xomega
#1 Posted : Sunday, October 14, 2012 5:47:06 PM(UTC)
xomega



Many fields in software systems can assume only a limited set of values, which have a very important meaning in the business domain they apply to. These values are generally stored as a short alpha and/or numeric code and can be displayed on the forms using longer user-friendly names/descriptions. Typically, such lists are either hardcoded in the application code, or stored in database tables with little to no version control.

Xomega object model provides a simple, yet very powerful and flexible way to model various static lists of values through enumerations. Each enumeration may define its own set of additional properties that enumeration's items may have, and the Xomega object model will validate that the items will use the right properties, have unique codes and descriptions, etc.

In order to define a new enumeration in the model, you can perform the following steps.
  1. Add an enum element to the enums grouping element in the most appropriate file. Typically it's recommended to declare the enumerations in the file where they are used the most often.
  2. Give the enumeration a unique name by setting the name attribute.
  3. If you want your enumeration to extend another enumeration defined in the model, then set the base attribute to the name of that enumeration.
  4. For each additional property that enumeration's items can have, add a new property element inside the properties child element of the enum element.
  5. Give the property a unique name by setting the name attribute.
  6. If you want the items that don't have this property set to use a default value for that property, then set the default attribute to the default value.
  7. If you want to allow enumeration's items to specify multiple values for that property, then set the multi-value attribute to true.
  8. For each enumerations item, add a new item element inside the enum element.
  9. Give the item a unique name by setting the name attribute. It will be used to generate static constants, so it should be relatively short but descriptive. It may use spaces, but should otherwise follow the naming rules for constants.
  10. Specify a unique short code for the item, that will be stored in the field, by setting the value attribute.
  11. If you want to use a screen description for your item that is different from the name, then add a nested text element inside the item element and specify the description inside the text element. This may also be used for localization.
  12. To set the values of any additional properties for your item, and a prop element inside the item element for each property value.
  13. Set the ref attribute of the prop element to the name of the property. It can repeat for any given item if the corresponding property is defined as multi-value.
  14. Set the value attribute to the value of that property for that item.
  15. Add enumeration's description inside the nested elements doc > summary of the enum element to provide more details about the enumeration for developers and users.

The following example demonstrates how enumeration severity is defined using a numeric code and severity description. Some severities are also classified as errors by having their is error property set, which is defined on the enumeration. Severity Info also uses a custom description that is shown to the users.
Code:
<enums>
  <enum name="severity">
    <properties>
      <property name="is error" default="0"/>
    </properties>
    <item name="Critical" value="1">
      <prop ref="is error" value="1"/>
    </item>
    <item name="Error" value="2">
      <prop ref="is error" value="1"/>
    </item>
    <item name="Warning" value="3"/>
    <item name="Info" value="4">
      <text>Information</text>
    </item>
  </enum>
</enums>
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.

Copyright © 2009-2022 Xomega.Net. All rights reserved.