Skip to content

Passive registration - #152

Merged
smehrbrodt merged 1 commit into
LibreOffice:masterfrom
prrvchr:Passive-Registration
Mar 27, 2025
Merged

Passive registration#152
smehrbrodt merged 1 commit into
LibreOffice:masterfrom
prrvchr:Passive-Registration

Conversation

@prrvchr

@prrvchr prrvchr commented Feb 25, 2025

Copy link
Copy Markdown
Contributor

Here is a possible implementation of passive registration.

To be considered as a UNO service a Java Class must have:

  • An ctor with com.sun.star.uno.XComponentContext as unique parameter.
  • A static field m_serviceName of type String and having as value a literal (ie: the name of the UNO service). This field can be private, protected or public, it doesn't matter.

All classes with these characteristics will be stored in the XML file package.components located at the root of the Eclipse project.
This file will record the name of the implementation (ie: the full name of the class recognized as a UNO service) and the name of the UNO service (ie: the value of the m_serviceName field).

The RegistrationHandler.java.tpl file has been updated and now only implements the __getComponentFactory(String implementation) method needed to create Java UNO services. For existing projects it is necessary to update this file with this RegistrationHandler.java.txt, moreover the RegistrationHandler.classes file can be deleted.

Similarly, for a Python class to be considered a UNO service it must:

  • Exist a global variable g_ImplementationHelper declared as follows: g_ImplementationHelper = unohelper.ImplementationHelper().
  • Exist a global variable g_ServiceName declared as follows: g_ServiceName = 'com.sun.star.MyServiceName'.
  • Although this is not controlled, it will also be necessary for it to have the following code:
g_ImplementationHelper.addImplementation(YourPythonClass,         # UNO object class
     g_ServiceName,                                               # Implementation name
    (g_ServiceName, 'com.sun.star.sdbc.Driver'))                  # List of implemented services

The use of global variable limits to one UNO service declared per Python source .py file.

As before, we will find in the package.components file the path of the Python source file as well as the name of the UNO service declared by the variable g_ServiceName.

If during an update of the package.components file, for example following the modification of a UNO Java or Python service, the file does not exist then it will be created and checked if the META-INF/manifest.xml file correctly references package.components file.

For a project using active registration, it will be necessary to save in Eclipse all Java and/or Python files declared as UNO Service in order to switch their registration to passive.
Unfortunately it will however be necessary to manually delete the old registration of these active components in the META-INF/manifest.xml file. That is, lines like:

    <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java" manifest:full-path="jdbcDriverOOo.jar"/>
    <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Python" manifest:full-path="service/Driver.py"/>

If the extension's oxt file is built via Ant, it is also necessary to edit the package.properties file to include the new package.components file located at the root of the project.

@prrvchr
prrvchr force-pushed the Passive-Registration branch 5 times, most recently from 26c9795 to 604fb09 Compare February 28, 2025 13:08
/**
* The name of the package.components file.
*/
private static final String COMPONENTS_FILE = "package.components"; //$NON-NLS-1$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be .component (without s)

@prrvchr prrvchr Mar 1, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessarily. Besides all the examples under libreoffice/odk/examples/DevelopersGuide/Components show it.

As a good example the file: JavaComponent.components

It appears that there can be two types of components:

  • Simple components whose root of the XML document is the <component> element.
  • Multiple components whose root of the XML document is the <components> element.

I think the file extension follows this logic? At least that's what I thought.

* {@inheritDoc}
*/
@Override
public IFile getComponentsFile() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@smehrbrodt

Copy link
Copy Markdown
Contributor

I just tested creating a new Extension project and deploying it using a run configuration.
The resulting oxt did not have a .component file and was not registered successfully in LO.
Can you check if you can reproduce that?

@prrvchr

prrvchr commented Mar 1, 2025

Copy link
Copy Markdown
Contributor Author

I have not tested the creation of a new Project. I will do it.

It is necessary to verify the presence and the content of the following files in the oxt extension file:

  • RegistrationHandler.class
  • package.components
  • META-INF/manifest.xml

After testing, I had to clean the Eclipse plugin directory of any trace of LibreOffice and reinstall LOEclipse manually in order to be able to create a new project and for it to display the expected RegistrationHandler.java file and no longer see the RegistrationHandler.classes file.

On the other hand, the model of the Java service that is created is not valid (it still contains the __writeRegistryServiceInfo() method which is no longer necessary) and I have trouble identifying how it is made.

And finally when creating a project no META-INF/manifest.xml file is created even though this file is essential for an extension... And reading the code it seems to me that this file is managed as a temporary file?
On the other hand, if the META-INF/manifest.xml file is created manually then everything works correctly.

I created issue #153 to reference this problem.

@prrvchr

prrvchr commented Mar 2, 2025

Copy link
Copy Markdown
Contributor Author

If we want passive registration to be effective, we must answer the two questions posed by the issues:

@prrvchr
prrvchr force-pushed the Passive-Registration branch from 604fb09 to 894826b Compare March 15, 2025 22:52
@prrvchr

prrvchr commented Mar 16, 2025

Copy link
Copy Markdown
Contributor Author

The uno-skeletonmaker utility has been updated to version 0.5 to support the creation of Java services supporting passive registration. This will be available with LibreOffice version 25.2 and 25.8. See issue #154.
When using a lower LibreOffice version, a helper UnoSkeletonHelper.java will convert the Java skeleton to make it compatible with passive registration.

The META-INF/manifest.xlm file is now automatically managed by:

  • The background build of idl files generating the types.rdb file.
  • Creating UNO services in Java or Python.

Thank you for your feedback.

@prrvchr
prrvchr force-pushed the Passive-Registration branch from 894826b to 26c2739 Compare March 18, 2025 11:13
@smehrbrodt

Copy link
Copy Markdown
Contributor

Looks good!

Is this done from your POV? Will merge it then.

@prrvchr

prrvchr commented Mar 24, 2025

Copy link
Copy Markdown
Contributor Author

Yes, it's done. The next logical step would be issue: #37 (comment)
But I would prefer that we apply this PR and continue with a new PR. Isn't it?

@smehrbrodt
smehrbrodt merged commit 9808cdf into LibreOffice:master Mar 27, 2025
@prrvchr
prrvchr deleted the Passive-Registration branch April 3, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants