Language:

The Free and Open Productivity Suite
Apache OpenOffice 4.1.6 released

OpenOfficeMapping of Uno IDL to Java


Contents

Abstract
Mapping of basic types
Mapping of complex types
Mapping of „sequence“
Mapping of „module“
Mapping of „interface“
Mapping of „struct“
Mapping of „exception“
Mapping of „enum“
Mapping of „constant“
Mapping of „contstants“

Abstract

This document describes the complete mapping of Uno IDL into the Java language.

Mapping of basic types

The following table shows the mapping of IDL basic types to the corresponding Java types.

Users should be careful when using unsigned types in Java. Because there is no support in the Java language for unsigned types, a user is responsible for ensuring that large unsigned IDL type values are handled correctly as negative integers in Java.

IDL
Java
boolean boolean
short short
unsigned short short
long int
usigned long int
hyper long
unsigned hyper long
float float
double double
char char
byte byte
string java.lang.String
any com.sun.star.uno.Any
type com.sun.star.uno.Type
void void

Mapping of complex types

In C++ Uno all needed type information will be described with the type Type, in java Type is mapped to the Java type Class, but some informations described in IDL will be lost. So the mapping for the complex types (interface, struct, exception) will created an additional public static final member of type com.sun.star.lib.uno.typelib.TypeInfo array UNOTYPEINFO to describe this information. This array can be filled with objects of type:

  • MethodTypeInfo
    to describe the attributes of a method, is oneway, is const and if the return type is unsigned.

  • ParameterTypeInfo
    to describe if the parameter type is unsigned and if the direction is inout or out.

  • AttributeTypeInfo
    to describe if the type is unsigned and if the attibute is readonly.

  • MemberTypeInfo
    to describe if the type is unsigned

Note that only definitions where information are lost will be described.

This additional type information and the information from Class will be used by the runtime to handle the type when transport it on a remote connection or convert it to another object model.

All generated types (interface, struct, enum, exception) have another public static member of type Object UNORUNTIMEDATA. This member is reserved for internal use by the Uno runtime.

Mapping of „sequence“

Sequence types are mapped to a Java array of the sequence base type.

An IDL sequence<long> is mapped to int[]

An IDL sequence< sequence <long> > is mapped to int[][]

Mapping of „module“

An IDL module is mapped to a Java package with the same name. All IDL type declarations within the module are mapped to corresponding Java class or interface declarations within the generated package. IDL declarations not enclosed in any modules are mapped into the Java global scope.

Example:

An IDL

module stardiv {   ...}

is mapped to

package stardiv;   ...

Mapping of „interface“

An IDL interface is mapped to a Java interface with the same name as the IDL interface type. If an IDL interface inherits another interface, the Java interface will extends this appropriate Java interface. Each interface has an additional static member to store the uik of the IDL interface.

Attributes are mapped to a pair of Java 'get' and 'set' methods. These methods have the name get/set followed by the name of the attribute. A readonly attribute is mapped only to a 'get' method.

Parameter mapping:

IDL in parameters, which implement call-by-value semantics, are mapped to normal Java actual parameters. The result of IDL operations are returned as the result of the corresponding Java method. IDL out and inout parameters, which implement call-by-result and call-by-result/value semantics, are mapped to an array (with length 1) of the appropriate type to avoid generating of holder classes for each IDL type. The 0th element of the array has to be created by the caller of an inout parameter, and will be exchanged by the callee of an inout/out parameter. Specified exceptions (raises declarations) are mapped to normal Java throws statements and every method throws the com.sun.star.uno.RuntimeException if declared or not.

Example:

An IDL

module com {  module sun {  module star {  module registry {  

[ uik(00000000-33D6-11D1-AABE00A0-249D5590), ident( "XImplementationRegistration", 1.0 ) ]
interface XImplementationRegistration: com::sun::star::uno::XInterface
{
	void registerImplementation( [in] string aImplementationLoader, 
			 [in] string aLocation, 
			 [in] com::sun::star::registry::XSimpleRegistry xReg ) 
			raises( com::sun::star::registry::CannotRegisterImplementationException ); 

	boolean revokeImplementation( [in] string aLocation, 
			 [in] com::sun::star::registry::XSimpleRegistry xReg ); 

	sequence getImplementations( [in] string aImplementationLoader, 
			 [in] string aLocation ); 

	sequence checkInstantiation( [in] string implementationName ); 
};

is mapped to

package com.sun.star.registry;

public interface XImplementationRegistration extends com.sun.star.uno.XInterface
{
    // Methods
    public void registerImplementation( /*IN*/String aImplementationLoader, /*IN*/String aLocation, /*IN*/XSimpleRegistry xReg ) throws CannotRegisterImplementationException, com.sun.star.uno.RuntimeException;
    public boolean revokeImplementation( /*IN*/String aLocation, /*IN*/XSimpleRegistry xReg ) throws com.sun.star.uno.RuntimeException;
    public String[] getImplementations( /*IN*/String aImplementationLoader, /*IN*/String aLocation ) throws com.sun.star.uno.RuntimeException;
    public String[] checkInstantiation( /*IN*/String implementationName ) throws com.sun.star.uno.RuntimeException;

    // static Member
    public static com.sun.star.uno.Uik UIK = new com.sun.star.uno.Uik( 0x00000000, (short)0x33d6, (short)0x11d1, 0xaabe00a0, 0x249d5590 );

    public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[] = { 
        new com.sun.star.lib.uno.typeinfo.MethodTypeInfo( "registerImplementation", 0, 0 ),
        new com.sun.star.lib.uno.typeinfo.ParameterTypeInfo( "xReg", "registerImplementation", 2, com.sun.star.lib.uno.typeinfo.TypeInfo.INTERFACE ),
        new com.sun.star.lib.uno.typeinfo.MethodTypeInfo( "revokeImplementation", 1, 0 ),
        new com.sun.star.lib.uno.typeinfo.ParameterTypeInfo( "xReg", "revokeImplementation", 1, com.sun.star.lib.uno.typeinfo.TypeInfo.INTERFACE ),
        new com.sun.star.lib.uno.typeinfo.MethodTypeInfo( "getImplementations", 2, 0 ),
        new com.sun.star.lib.uno.typeinfo.MethodTypeInfo( "checkInstantiation", 3, 0 )
     };

    public static Object UNORUNTIMEDATA = null;
}

Mapping of „struct“

An IDL struct is mapped to a Java class with the same name as the struct type. Each member of the IDL struct is mapped to a public instance variable with the same type and name. The class also provides a default constructor which initialize all members with default values and a constructor for all values. If a struct inherit from another struct, the generated class extends the class of the inherited struct. The default constructor only initialize the members which have a complex type. The member constructor has all fields of the extended class and his own fields as parameter.

module com { module sun { module star { module uno {
    struct Uik
    {
        unsigned long  m_Data1;
        unsigned short m_Data2;
        unsigned short m_Data3;
        unsigned long  m_Data4;
        unsigned long  m_Data5;
    };
}; }; }; };

is mapped to

package com.sun.star.uno;

public class Uik
{
    // instance variables
    public int m_Data1;
    public short m_Data2;
    public short m_Data3;
    public int m_Data4;
    public int m_Data5;

    // constructors
    public Uik()
    {
    }

    public Uik(int _m_Data1,
               short _m_Data2,
               short _m_Data3,
               int _m_Data4,
               int _m_Data5)
    {
        m_Data1 = _m_Data1;
        m_Data2 = _m_Data2;
        m_Data3 = _m_Data3;
        m_Data4 = _m_Data4;
        m_Data5 = _m_Data5;
    }

    public static final com.sun.star.lib.uno.typelib.TypeInfo UNOTYPEINFO[] = 
		{ necom.sun.star.lib.uno.v.typelib.MemberTypeInfo( "m_Data1"com.sun.star.lib.uno.v.typelib.TypeInfo.UNSIGNED ),
        new com.sun.star.lib.uno.typelib.MemberTypeInfo( "m_Data2", com.sun.star.lib.uno.typelib.TypeInfo.UNSIGNED ),
        new com.sun.star.lib.uno.typelib.MemberTypeInfo( "m_Data3", com.sun.star.lib.uno.typelib.TypeInfo.UNSIGNED ),
        new com.sun.star.lib.uno.typelib.MemberTypeInfo( "m_Data4", com.sun.star.lib.uno.typelib.TypeInfo.UNSIGNED ),
        new com.sun.star.lib.uno.typelib.MemberTypeInfo( "m_Data5", com.sun.star.lib.uno..typelib.TypeInfo.UNSIGNED ) };

    public static Object UNORUNTIMEDATA = null;
}

Mapping of „exception“

An IDL exception is mapped to a Java class with the same name as the exception type. Each member of the IDL exception is mapped to a public instance variable with the same type and name. The class also provides a default constructor which initialize all members with default values and a constructor for all values. If an exception inherit from another exception, the generated class extends the class of the inherited exception. If the exception does not inherit the com.sun.star.uno.Exception, the generated Java class extends the java.lang.Exception. The member constructor has all fields of the extended class and his own fields as parameter.

module com { module sun { module star { module uno {
    exception RuntimeException : Exception
    {
    };
}; }; }; }; 

is mapped to

package com.sun.star.uno;

public class RuntimeException extends com.sun.star.uno.Exception
{
    // instance variables

    // constructors
    public RuntimeException()
    {
    }

    public RuntimeException(String _Message,
                            com.sun.star.uno.XInterface _Context)
    {
        super(_Message,
              _Context);
    }

    public static Object UNORUNTIMEDATA = null;
}

Mapping of „enum“

An IDL enum is mapped to a Java final class with the same name as the enum type. This class inherits the class com.sun.star.uno.Enum. This base class declares a protected member to store the actual value, a protected constructor to initialize the value, a public getValue method to get the actual value. The generated final class has an protected constructor, a public method getDefault, which returns an enum with the value of the first enum label as default. For each IDL enum label the class declares a public static member of the same type as the enum and initialized with the defined value in IDL. The Java class for the enum has an additional public method fromInt, which returns the enum with the specified value.

Example:

An IDL

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

is mapped to

package com.sun.star.uno;

final public 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;
         ...
      }
   }

   public static Object UNORUNTIMEDATA = null;
}

Mapping of „constant“

IDL constants are mapped to a public interface with the same as the constant and containing a public static final field, named value, that holds the constant value. (Note that the Java compiler will normally inline the value when the class is used in other Java code.)

Example:

An IDL

module example {
    const long USERFLAG = 1;
};

is mapped to

package example;

public interface USERFLAG
{
   public static final int value = (int)1L;
}

Mapping of „contstants“

IDL constant groups are mapped to a public interface with the same as the constant group. All defined constants in this constant group are mapped to public static member of the interface with type and name of the constant, that holds the value.

An IDL

module example {
    constants USER
    {
        const long FLAG1 = 1;
        const long FLAG2 = 2;
        const long FLAG3 = 3;
    };
};

is mapped to

package example;

public interface USER
{
   public static final int FLAG1 = (int)1L;
   public static final int FLAG2 = (int)2L;
   public static final int FLAG3 = (int)3L;
}

Auhor: Jürgen Schmidt ($Date: 2002/10/22 11:11:27 $)
Copyright 2001 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, CA 94303 USA.


Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache and the Apache feather logo are trademarks of The Apache Software Foundation. OpenOffice, OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.