Building Enums

Overview

The BEnum base class is used to define enumerated types. An enum is composed of a fixed set of int/String pairs called its range. The int identifiers are called ordinals and the String identifiers are called tags. Enum ranges are managed by the BEnumRange class.

There are three subclasses of BEnum. BBoolean is a special case which models a boolean primitive. The BDynamicEnum class is used to manage weakly typed enums which may store any ordinal and range. Strongly typed enums may be defined at compile time by subclassing BFrozenEnum. The Niagara Framework builds a BFrozenEnum's range using the following set of introspection rules:

Example

The following source provides a complete example of the implementation for BOrientation:
  
/*
 * Copyright 2000 Tridium, Inc. All Rights Reserved.
 */
package javax.baja.ui.enum;

import javax.baja.sys.*;

/**
 * BOrientation defines a widget's orientation as
 * either horizontal or vertical.
 */
public final class BOrientation
  extends BFrozenEnum
{
  
  public static final int HORIZONTAL = 0;
  public static final int VERTICAL = 1;
  
  public static final BOrientation horizontal = new BOrientation(HORIZONTAL);
  public static final BOrientation vertical = new BOrientation(VERTICAL);

  public Type getType() { return TYPE; }
  public static final Type TYPE = Sys.loadType(BOrientation.class);
  
  public static BOrientation make(int ordinal)
  {
    return (BOrientation)horizontal.getRange().get(ordinal);
  }
  
  public static BOrientation make(String tag)
  {
    return (BOrientation)horizontal.getRange().get(tag);
  }
  
  private BOrientation(int ordinal) { super(ordinal); }
  
}