Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / odk / examples / java / MinimalComponent / MinimalComponent.java
blobb18a777eb3738a66d19d8918e53b44687d789b4b
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import com.sun.star.lib.uno.helper.Factory;
37 import com.sun.star.lang.XMultiComponentFactory;
38 import com.sun.star.lang.XSingleComponentFactory;
39 import com.sun.star.lib.uno.helper.WeakBase;
40 import com.sun.star.uno.XComponentContext;
41 import com.sun.star.lang.XInitialization;
42 import com.sun.star.lang.XServiceInfo;
44 /** This class capsulates the class, that implements the minimal component, a
45 * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
46 * method, that writes the information into the given registry key
47 * (<CODE>__writeRegistryServiceInfo</CODE>).
49 public class MinimalComponent {
50 /** This class implements the component. At least the interfaces XServiceInfo,
51 * XTypeProvider, and XInitialization should be provided by the service.
53 public static class _MinimalComponent extends WeakBase
54 implements XInitialization, XServiceInfo {
55 /** The service name, that must be used to get an instance of this service.
57 private static final String __serviceName =
58 "org.openoffice.MinimalComponent";
60 /** The initial component contextr, that gives access to
61 * the service manager, supported singletons, ...
62 * It's often later used
64 private XComponentContext m_cmpCtx;
66 /** The service manager, that gives access to all registered services.
67 * It's often later used
69 private XMultiComponentFactory m_xMCF;
71 /** The constructor of the inner class has a XMultiServiceFactory parameter.
72 * @param xCompContext A special service factory
73 * could be introduced while initializing.
75 public _MinimalComponent(XComponentContext xCompContext) {
76 try {
77 m_cmpCtx = xCompContext;
78 m_xMCF = m_cmpCtx.getServiceManager();
80 catch( Exception e ) {
81 e.printStackTrace();
85 /** This method is a member of the interface for initializing an object
86 * directly after its creation.
87 * @param object This array of arbitrary objects will be passed to the
88 * component after its creation.
89 * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be
90 * passed to the caller.
92 public void initialize( Object[] object )
93 throws com.sun.star.uno.Exception {
94 /* The component describes what arguments its expected and in which
95 * order!At this point you can read the objects and can initialize
96 * your component using these objects.
100 /** This method returns an array of all supported service names.
101 * @return Array of supported service names.
103 public String[] getSupportedServiceNames() {
104 return getServiceNames();
107 /** This method is a simple helper function to used in the
108 * static component initialisation functions as well as in
109 * getSupportedServiceNames.
111 private static String[] getServiceNames() {
112 String[] sSupportedServiceNames = { __serviceName };
113 return sSupportedServiceNames;
116 /** This method returns true, if the given service will be
117 * supported by the component.
118 * @param sServiceName Service name.
119 * @return True, if the given service name will be supported.
121 public boolean supportsService( String sServiceName ) {
122 return sServiceName.equals( __serviceName );
125 /** Return the class name of the component.
126 * @return Class name of the component.
128 public String getImplementationName() {
129 return _MinimalComponent.class.getName();
135 * Gives a factory for creating the service.
136 * This method is called by the <code>JavaLoader</code>
137 * <p>
138 * @return returns a <code>XSingleComponentFactory</code> for creating
139 * the component
140 * @param sImplName the name of the implementation for which a
141 * service is desired
142 * @see com.sun.star.comp.loader.JavaLoader
144 public static XSingleComponentFactory __getComponentFactory(String sImplName)
146 XSingleComponentFactory xFactory = null;
148 if ( sImplName.equals( _MinimalComponent.class.getName() ) )
149 xFactory = Factory.createComponentFactory(_MinimalComponent.class,
150 _MinimalComponent.getServiceNames());
152 return xFactory;
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */