1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 package com
.sun
.star
.comp
.connections
;
22 import com
.sun
.star
.bridge
.XInstanceProvider
;
24 import com
.sun
.star
.lang
.XMultiServiceFactory
;
25 import com
.sun
.star
.lang
.XSingleServiceFactory
;
27 import com
.sun
.star
.registry
.XRegistryKey
;
29 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
33 * The <code>ConstantInstanceProvider</code> is a component
34 * that implements the <code>XInstanceProvider</code> Interface.
36 * @see com.sun.star.bridge.XBridge
37 * @see com.sun.star.bridge.XBridgeFactory
38 * @see com.sun.star.bridge.XInstanceProvider
39 * @see com.sun.star.comp.loader.JavaLoader
42 public class ConstantInstanceProvider
implements XInstanceProvider
{
44 * When set to true, enables various debugging output.
46 public static final boolean DEBUG
= false;
49 * The name of the service, the <code>JavaLoader</code> accesses this through
52 private static final String __serviceName
= "com.sun.star.comp.connection.InstanceProvider";
55 * Gives a factory for creating the service.
56 * <p>This method is called by the <code>JavaLoader</code>.</p>
58 * @param implName the name of the implementation for which a service is desired.
59 * @param multiFactory the service manager to be uses if needed.
60 * @param regKey the registryKey.
61 * @return returns a <code>XSingleServiceFactory</code> for creating the component.
63 * @see com.sun.star.comp.loader.JavaLoader
65 public static XSingleServiceFactory
__getServiceFactory(String implName
,
66 XMultiServiceFactory multiFactory
,
69 XSingleServiceFactory xSingleServiceFactory
= null;
71 if (implName
.equals(ConstantInstanceProvider
.class.getName()) )
72 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(ConstantInstanceProvider
.class,
77 return xSingleServiceFactory
;
80 protected XMultiServiceFactory _serviceManager
;
81 protected String _serviceName
;
82 protected Object _instance
;
85 public void setInstance(String serviceName
) throws com
.sun
.star
.uno
.Exception
{
86 _instance
= _serviceManager
.createInstance(serviceName
);
87 _serviceName
= serviceName
;
91 * Constructs a new <code>ConstantInstanceProvider</code>.
92 * <p>Uses the provided ServiceManager as the provided instance.</p>
94 * @param serviceManager the provided service manager
96 public ConstantInstanceProvider(XMultiServiceFactory serviceManager
) {
97 _serviceManager
= serviceManager
;
99 _serviceName
= "SERVICEMANAGER";
100 _instance
= serviceManager
;
104 * Gives an object for the passed instance name.
106 * @return the desired instance
107 * @param sInstanceName the name of the desired instance
109 public Object
getInstance(String sInstanceName
) throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.uno
.RuntimeException
{
110 Object result
= sInstanceName
.equals(_serviceName
) ? _instance
: null;
112 if(DEBUG
) System
.err
.println("##### " + getClass().getName() + ".getInstance(" + sInstanceName
+ "):" + result
);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */