| 
Decoding StarTeam's built-in Enumerations Print

It often happens that you retrieve some useful piece of information from the SDK, and you get it in the form of an integer.  It is best to use the PropertyEnums class to decode those integers.  Here are some examples:

This one takes an Audit object and returns a human-friendly string of the audit event.
<blockquote>  private String DecodeAuditEventID(com.starbase.starteam.Audit a) {
    String s = "???";
    com.starbase.starteam.PropertyEnums pe = a.getServer().getPropertyEnums();
    int iEventID = Integer.parseInt(
      a.get(a.getServer().getPropertyNames().AUDIT_EVENT_ID).toString()
      );
    switch (iEventID) {
      case pe.AUDIT_EVENT_ID_ADDED: s="Added";
      case pe.AUDIT_EVENT_ID_BRANCHED: s="Branched";
      case pe.AUDIT_EVENT_ID_CHECKED_IN: s="Checked In";
      case pe.AUDIT_EVENT_ID_CHECKED_OUT: s="Checked Out";
      case pe.AUDIT_EVENT_ID_COMMENT_EDITED: s="Comment Edited";
      case pe.AUDIT_EVENT_ID_CREATED: s="Created";
      case pe.AUDIT_EVENT_ID_DELETED: s="Deleted";
      case pe.AUDIT_EVENT_ID_ITEM_OVERWRITTEN: s="Overwritten";
      case pe.AUDIT_EVENT_ID_LOCKED: s="Locked";
      case pe.AUDIT_EVENT_ID_LOCK_BROKEN: s="Lock Broken";
      case pe.AUDIT_EVENT_ID_MODIFIED: s="Modified";
      case pe.AUDIT_EVENT_ID_MOVED_FROM: s="Moved From";
      case pe.AUDIT_EVENT_ID_MOVED_TO: s="Moved to";
      case pe.AUDIT_EVENT_ID_SHARED: s="Shared";
      case pe.AUDIT_EVENT_ID_UNLOCKED: s="Unlocked";
    }
    return s;
  }
</blockquote>
(UPDATE:  the switch/case doesn't really work cuz these are not constant values, so a nested "if" would be the thing to do.)

This one takes a ItemBehavior object and returns a human-friendly string of its branch state.
<blockquote>  private String DecodeBranchState(ItemBehavior b) {
    String s = "???";
    int iBranch = b.getBranchState();
    switch (iBranch) {
      case ItemBehavior.BRANCH_STATE_ROOT: s="root";
      case ItemBehavior.BRANCH_STATE_BRANCHED: s="yes";
      case ItemBehavior.BRANCH_STATE_NOT_SUPPORTED: s="can't";
      case ItemBehavior.BRANCH_STATE_BRANCHABLE: s="not yet";
    }
    return s;
  }
</blockquote>

There is an important difference in this second example.  Here we are using the SDK itself, rather than the server.  For example, the notation "ItemBehavior.BRANCH_STATE_ROOT" gets the integer code from the static properties of the ItemBehavior class in the SDK, whereas the first approach (above) using the PropertyEnums object retrieves the integer code from the server.
The first approach is better and more reliable, but both usually work the same.

:) dave

Trackback(0)
Comments (0)add comment

Write comment
smaller | bigger

security image
Write the displayed characters


busy
 
< Prev   Next >

Video News