Mapping of Enum Types

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 12:42, 23 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



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

The base class com.sun.star.uno.Enum 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 com.sun.star.uno.TypeClass:

  module com { module sun { module star { module uno {
 
  enum TypeClass {
      INTERFACE,
      SERVICE,
      IMPLEMENTATION,
      STRUCT,
      TYPEDEF,
      ...
  };
 
  }; }; }; };

is mapped to:

  package com.sun.star.uno;
 
  public final class TypeClass extends com.sun.star.uno.Enum {
      private TypeClass(int value) {
          super(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