Page 1 of 1

[Solved] Two services in the same class?

PostPosted: Mon Mar 01, 2021 9:12 pm
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   Expand viewCollapse view
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;
    }

Re: Two services in the same class?

PostPosted: Fri Mar 05, 2021 3:27 pm
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.

Re: Two services in the same class?

PostPosted: Fri Mar 05, 2021 6:35 pm
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.

Re: Two services in the same class?

PostPosted: Fri Mar 05, 2021 10:21 pm
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