2017-02-19

8: To Build a First UNO Extension (LibreOffice Extension or Apache OpenOffice Extension), Part Two

<The previous article in this series | The table of contents of this series | The next article in this series>

Main body START

To Know How to Handle (Read or Write) LibreOffice or Apache OpenOffice Writer or Calc Documents via Extensions from Java or Macro Programs

A Sample UNO Extension Project

-Hypothesizer

The 'hiUnoExtensionsUnoExtension' directory contains a sample UNO extension project.

Explanations of the 'build.xml' and 'build.gradle' files, the directories, 'source', 'java', and 'resource', and 'MANIFEST.MF.addition' are the same as before. . . .

-Rebutter

. . . And?

-Hypothesizer

The rest is the difficult part to explain. 'HiUnoExtensionsImplementation.java' is a UNO interface implementation class.

-Rebutter

. . .

-Hypothesizer

. . . Just accept for now that there is a concept called UNO interface, which is mapped to Java interface. 'HiUnoExtensionsImplementation.java' is an implementation of a Java interface mapped from a UNO interface.

-Rebutter

OK.

-Hypothesizer

'HiUnoExtensionsUnoExtensionGlobalServicesProvider.java' is a class that is necessary for the UNO interface implementation to be registered as a global UNO service into LibreOffice. Such a class is called a 'global UNO services' provider.

-Rebutter

. . .

-Hypothesizer

. . . Just, please, accept for now that there is a concept called global UNO service. Not all UNO interface implementations have to be registered as global UNO services, but when we want some UNO interface implementations to be registered as global UNO services, we need to have a 'global UNO services' provider.

-Rebutter

One 'global UNO services' provider for multiple global UNO services?

-Hypothesizer

Yes. A UNO extension can contain multiple UNO interface implementations, and some of them can be registered as global UNO services, but there is only one 'global UNO services' provider in the UNO extension.

-Rebutter

What do we have to describe in the 'global UNO services' provider?

-Hypothesizer

We have to associate a UNO service name to each UNO interface implementation to be registered as a global UNO service. 'GlobalUnoServicesProviderUtility.java' in the 'unoUtilitiesToDisclose' project contains static methods used by 'global UNO services' providers. That is, common codes used by all the 'global UNO services' providers have been separated from the 'global UNO services' providers into the class.

-Rebutter

I see.

-Hypothesizer

The 'manifest.xml' file in the 'resource' directory is the manifest file of the UNO extension file.

-Rebutter

The UNO extension file?

-Hypothesizer

The UNO extension is archived as a zip file, which is the UNO extension file.

-Rebutter

What do we have to describe in the manifest file?

-Hypothesizer

We have to describe what UNO data types registry file is included in the UNO extension, and we have to also name a UNO components setting file, which I will explain next.

-Rebutter

What is a UNO data types registry file?

-Hypothesizer

As UNO is 'programming language'-independent, UNO data types like UNO interfaces have to be registered into LibreOffice in a 'programming language'-independent form. The UNO data types registry file contains definitions of UNO data types in that 'programming language'-independent form.

-Rebutter

How is the UNO data types registry file created?

-Hypothesizer

We can create it from UNO-specific source files using UNO tools.

-Rebutter

Hmm . . .

-Hypothesizer

The 'thebiasplanet.hiunoextensionsunoextension.uno.components' file is the UNO components setting file named in the manifest file. The UNO components setting file specifies what UNO interface implementations are included in the UNO extension. And in the setting file, we also associate UNO service names to UNO interface implementations that are registered as global UNO services.

-Rebutter

. . . Haven't we already designated that information in the 'global UNO services' provider?

-Hypothesizer

Well, . . . if you accuse of its being redundant, I think, it's redundant.

-Rebutter

Hmm, if it's required, it can't be helped.

-Hypothesizer

The 'unoIdl' directory is the root directory of UNOIDL (UNO Interface Definition Language) files.

-Rebutter

. . .

-Hypothesizer

. . . UNOIDL is a definition language in which UNO artifacts are defined. For example, the UNO interface is first defined in UNOIDL in a UNOIDL file; the UNO interface is converted to a Java interface class file and a UNO data type unmerged registry file by UNO tools. Actually, UNOIDL files are what I meant by 'UNO-specific source files'.

-Rebutter

A UNO data type unmerged registry file?

-Hypothesizer

First, we create a UNO data type unmerged registry file per UNO data type. Next, we merge those UNO data type unmerged registry files into a UNO data types merged registry file, which is the aforementioned UNO data types registry file.

-Rebutter

Ah-ha.

-Hypothesizer

The directories, like 'thebiasplanet', under the 'unoIdl' directory represent UNO modules. We can think of the UNO module as an equivalent of a Java package. In fact, the UNO module is mapped to a Java package.

'XHiUnoExtensions.idl' is a UNOIDL file in which a UNO interface is defined.

About 'HiUnoExtensions.idl' . . .

-Rebutter

. . . About that, what?

-Hypothesizer

As descriptions in the reference documents are confusing, I will describe it in my terms. 'HiUnoExtensions.idl' is a UNOIDL file in which a 'global UNO service' instances factory is defined.

-Rebutter

I understand your description, but what are descriptions in the reference documents?

-Hypothesizer

They are as though a 'UNO new-style service' is defined in it.

-Rebutter

What are UNO new-style services?

-Hypothesizer

The usage of terms, 'UNO new-style service' and 'UNO old-style service' in the reference documents is confusing, and I can't explain it here (we will delve into it when we learn basic concepts of UNO). But anyway, 'UNO new-style service' sounds like a kind of UNO service, but what is defined in that UNOIDL file isn't a UNO service itself, but a UNO service instances factory.

-Rebutter

What exactly is described in the UNOIDL file?

-Hypothesizer

So-called 'constructors' are described in the UNOIDL file; the UNOIDL file is converted to a Java class that has those 'constructors' as static methods. We can create 'global UNO service' instances by calling those static methods.

-Rebutter

So, 'constructors' aren't constructors in the Java terminology, but factory methods. The Java class converted from the UNOIDL file is a UNO service instances factory, not a UNO service.

-Hypothesizer

That's what I mean. In fact, we don't have to create the UNOIDL file for us to register and use the global UNO service, if we don't intend to use that type of UNO service instances factory.

-Rebutter

But don't we need a kind of UNO service instances factory to instantiate the global UNO service?

-Hypothesizer

Yes, but there is a generic UNO service instances factory called global UNO services manager, and we can instantiate the global UNO service from the global UNO services manager. By 'generic', I mean, the global UNO services manager can instantiate multiple UNO services while the UNO service instances factory converted from the UNOIDL file is a 'UNO service'-specific UNO service instances factory that can instantiate only the specific UNO service.

-Rebutter

I understand.

Main body END

References

  • Apache OpenOffice Wiki. (2014/01/02). Apache OpenOffice Developer's Guide. Retrieved from https://wiki.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide

<The previous article in this series | The table of contents of this series | The next article in this series>