Mapping of Enum Types

From Apache OpenOffice Wiki
Jump to: navigation, search

An UNO enum type is mapped to a public, final Java class with the same name, derived from the class Only non-null references to the generated final classes are valid.

The base class declares a protected member to store the actual value, a protected constructor to initialize the value and a public getValue() method to get the actual value. The generated final class has a protected constructor and a public method getDefault() that returns an instance with the value of the first enum member as a default. For each member of a UNO enum type, the corresponding Java class declares a public static member of the given Java type that is initialized with the value of the UNO enum member. The Java class for the enum type has an additional public method fromInt() that returns the instance with the specified value. The following IDL definition for

  module com { module sun { module star { module uno {
  enum TypeClass {
  }; }; }; };

is mapped to:

  public final class TypeClass extends {
      private TypeClass(int value) {
      public static TypeClass getDefault() {
          return INTERFACE;
      public static final TypeClass INTERFACE = new TypeClass(0);
      public static final TypeClass SERVICE = new TypeClass(1);
      public static final TypeClass IMPLEMENTATION = new TypeClass(2);
      public static final TypeClass STRUCT = new TypeClass(3);
      public static final TypeClass TYPEDEF = new TypeClass(4);
      public static TypeClass fromInt(int value) {
          switch (value) {
          case 0:
              return INTERFACE;
          case 1:
              return SERVICE;
          case 2:
              return IMPLEMENTATION;
          case 3:
              return STRUCT;
          case 4:
              return TYPEDEF;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages