[Solved] Two services in the same class?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
DavidBo
Posts: 27
Joined: Thu Mar 12, 2009 3:57 pm

[Solved] Two services in the same class?

Post by DavidBo »

I try to modify the StarterProject which goes by the LOEclipse plugin.
I have added the "com.sun.star.frame.ProtocolHandler" and implemented the interfaces
com.sun.star.lang.XInitialization,
com.sun.star.frame.XDispatchProvider, XDispatch

But only the original service seems to work the "org.libreoffice.example.StarterProject". I don't get any error messages, it is just that none of the newly added methods are ever called. :shock:

Is it not possible to implement two services in the same class?
The beginning of the code:

Code: Select all

package org.libreoffice.example.comp;

import com.sun.star.uno.XComponentContext;
import com.sun.star.lib.uno.helper.Factory;

import org.libreoffice.example.dialog.ActionOneDialog;
import org.libreoffice.example.helper.DialogHelper;

import com.sun.star.frame.XFrame;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.beans.NamedValue;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XController;
import com.sun.star.ui.XContextMenuInterceptor;
import com.sun.star.ui.XContextMenuInterception;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;


public final class StarterProjectImpl extends WeakBase
   implements com.sun.star.lang.XServiceInfo,
              com.sun.star.task.XJobExecutor,
              com.sun.star.lang.XInitialization,
              com.sun.star.frame.XDispatchProvider, XDispatch
{
    private final XComponentContext m_xContext;
    private XFrame m_xFrame;
    private static final String m_implementationName = StarterProjectImpl.class.getName();
    private static final String[] m_serviceNames = {
        "org.libreoffice.example.StarterProject","com.sun.star.frame.ProtocolHandler" };


    public StarterProjectImpl( XComponentContext context )
    {
        m_xContext = context;
      
    };

    public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
        XSingleComponentFactory xFactory = null;

        if ( sImplementationName.equals( m_implementationName ) )
            xFactory = Factory.createComponentFactory(StarterProjectImpl.class, m_serviceNames);
        return xFactory;
    }

    public static boolean __writeRegistryServiceInfo( XRegistryKey xRegistryKey ) {
        return Factory.writeRegistryServiceInfo(m_implementationName,
                                                m_serviceNames,
                                                xRegistryKey);
    }

    // com.sun.star.lang.XServiceInfo:
    public String getImplementationName() {
         return m_implementationName;
    }

    public boolean supportsService( String sService ) {
        int len = m_serviceNames.length;

        for( int i=0; i < len; i++) {
            if (sService.equals(m_serviceNames[i]))
                return true;
        }
        return false;
    }

    public String[] getSupportedServiceNames() {
        return m_serviceNames;
    }
Last edited by MrProgrammer on Fri Mar 05, 2021 11:01 pm, edited 3 times in total.
Reason: Tagged [Solved]
Apache Open Office 4.1.9 Windows 10
DavidBo
Posts: 27
Joined: Thu Mar 12, 2009 3:57 pm

Re: Two services in the same class?

Post by DavidBo »

It is possible to have several services in the same class.
But many of the service methods in my example will not be called unless jobs.xcu, addons.xcu or/and ProtolHandler.xcu have been configured properly.
Apache Open Office 4.1.9 Windows 10
User avatar
Hagar Delest
Moderator
Posts: 32627
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Two services in the same class?

Post by Hagar Delest »

Have you fixed your problem eventually?
The green icon (especially in first post) is to tell that the problem has been solved. It can be misleading if you are waiting for further help.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
DavidBo
Posts: 27
Joined: Thu Mar 12, 2009 3:57 pm

Re: Two services in the same class?

Post by DavidBo »

Yes it has been solved therefore i gave it a green V . The problem was that I didn't configure any *.xcu file
Apache Open Office 4.1.9 Windows 10
Post Reply