Difference between revisions of "Documentation/DevGuide/ProUNO/Java/Mapping of Enum Types"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 12: Line 12:
  
 
The base class <code>com.sun.star.uno.Enum</code> declares a protected member to store the actual value, a protected constructor to initialize the value and a public <code>getValue()</code> method to get the actual value. The generated final class has a protected constructor and a public method <code>getDefault()</code> 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 <code>fromInt()</code> that returns the instance with the specified value. The following IDL definition for <idl>com.sun.star.uno.TypeClass</idl>:
 
The base class <code>com.sun.star.uno.Enum</code> declares a protected member to store the actual value, a protected constructor to initialize the value and a public <code>getValue()</code> method to get the actual value. The generated final class has a protected constructor and a public method <code>getDefault()</code> 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 <code>fromInt()</code> that returns the instance with the specified value. The following IDL definition for <idl>com.sun.star.uno.TypeClass</idl>:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   module com { module sun { module star { module uno {
 
   module com { module sun { module star { module uno {
 
    
 
    
Line 25: Line 25:
 
    
 
    
 
   }; }; }; };
 
   }; }; }; };
</source>
+
</syntaxhighlight>
 
is mapped to:
 
is mapped to:
<source lang="java">
+
<syntaxhighlight lang="java">
 
   package com.sun.star.uno;
 
   package com.sun.star.uno;
 
    
 
    
Line 62: Line 62:
 
       }
 
       }
 
   }
 
   }
</source>
+
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Professional UNO]]
 
[[Category:Documentation/Developer's Guide/Professional UNO]]

Latest revision as of 12:42, 23 December 2020



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