2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package com
.sun
.star
.comp
.smoketest
;
20 import com
.sun
.star
.lib
.uno
.helper
.Factory
;
21 import com
.sun
.star
.lang
.XMultiComponentFactory
;
22 import com
.sun
.star
.lang
.XSingleComponentFactory
;
23 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import com
.sun
.star
.uno
.XComponentContext
;
26 import com
.sun
.star
.registry
.XRegistryKey
;
27 import com
.sun
.star
.lang
.XInitialization
;
28 import com
.sun
.star
.lang
.XTypeProvider
;
29 import com
.sun
.star
.lang
.XServiceInfo
;
30 import com
.sun
.star
.uno
.Type
;
32 /** This class capsulates the class, that implements the minimal component, a
33 * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
34 * method, that writes the information into the given registry key
35 * (<CODE>__writeRegistryServiceInfo</CODE>).
37 public class LocationTest
{
38 /** This class implements the component. At least the interfaces XServiceInfo,
39 * XTypeProvider, and XInitialization should be provided by the service.
41 public static class _LocationTest
extends WeakBase
42 implements XServiceInfo
{
43 /** The service name, that must be used to get an instance of this service.
45 private static final String __serviceName
=
46 "com.sun.star.comp.smoketest.LocationTest";
48 /** The initial component contextr, that gives access to
49 * the service manager, supported singletons, ...
50 * It's often later used
52 private XComponentContext m_cmpCtx
;
54 /** The service manager, that gives access to all registered services.
55 * It's often later used
57 private XMultiComponentFactory m_xMCF
;
59 /** The constructor of the inner class has a XMultiServiceFactory parameter.
60 * @param xmultiservicefactoryInitialization A special service factory
61 * could be introduced while initializing.
63 public _LocationTest(XComponentContext xCompContext
) {
65 m_cmpCtx
= xCompContext
;
66 m_xMCF
= m_cmpCtx
.getServiceManager();
68 catch( Exception e
) {
73 /** This method returns an array of all supported service names.
74 * @return Array of supported service names.
76 public String
[] getSupportedServiceNames() {
77 return getServiceNames();
80 /** This method is a simple helper function to used in the
81 * static component initialisation functions as well as in
82 * getSupportedServiceNames.
84 public static String
[] getServiceNames() {
85 String
[] sSupportedServiceNames
= { __serviceName
};
86 return sSupportedServiceNames
;
89 /** This method returns true, if the given service will be
90 * supported by the component.
91 * @param sServiceName Service name.
92 * @return True, if the given service name will be supported.
94 public boolean supportsService( String sServiceName
) {
95 return sServiceName
.equals( __serviceName
);
98 /** Return the class name of the component.
99 * @return Class name of the component.
101 public String
getImplementationName() {
102 return _LocationTest
.class.getName();
108 * Gives a factory for creating the service.
109 * This method is called by the <code>JavaLoader</code>
111 * @return returns a <code>XSingleComponentFactory</code> for creating
113 * @param sImplName the name of the implementation for which a
115 * @see com.sun.star.comp.loader.JavaLoader
117 public static XSingleComponentFactory
__getComponentFactory(String sImplName
)
119 XSingleComponentFactory xFactory
= null;
121 if ( sImplName
.equals( _LocationTest
.class.getName() ) )
122 xFactory
= Factory
.createComponentFactory(_LocationTest
.class,
123 _LocationTest
.getServiceNames());
129 * Writes the service information into the given registry key.
130 * This method is called by the <code>JavaLoader</code>
132 * @return returns true if the operation succeeded
133 * @param regKey the registryKey
134 * @see com.sun.star.comp.loader.JavaLoader
136 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
137 return Factory
.writeRegistryServiceInfo(_LocationTest
.class.getName(),
138 _LocationTest
.getServiceNames(),
142 /** This method is a member of the interface for initializing an object
143 * directly after its creation.
144 * @param object This array of arbitrary objects will be passed to the
145 * component after its creation.
146 * @throws Exception Every exception will not be handled, but will be
147 * passed to the caller.
149 public void initialize( Object
[] object
)
150 throws com
.sun
.star
.uno
.Exception
{
151 /* The component describes what arguments are expected and in which
152 * order! At this point you can read the objects and initialize
153 * your component using these objects.