Update ooo320-m1
[ooovba.git] / odk / examples / java / MinimalComponent / MinimalComponent.java
blob10dd4989562690eda0a155ef96dd1e331e0e64a8
1 /*************************************************************************
3 * $RCSfile: MinimalComponent.java,v $
5 * $Revision: 1.6 $
7 * last change: $Author: rt $ $Date: 2005-01-31 17:13:05 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 import com.sun.star.lib.uno.helper.Factory;
42 import com.sun.star.lang.XMultiComponentFactory;
43 import com.sun.star.lang.XSingleComponentFactory;
44 import com.sun.star.lib.uno.helper.WeakBase;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XComponentContext;
47 import com.sun.star.registry.XRegistryKey;
48 import com.sun.star.lang.XInitialization;
49 import com.sun.star.lang.XTypeProvider;
50 import com.sun.star.lang.XServiceInfo;
51 import com.sun.star.uno.Type;
53 /** This class capsulates the class, that implements the minimal component, a
54 * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
55 * method, that writes the information into the given registry key
56 * (<CODE>__writeRegistryServiceInfo</CODE>).
58 public class MinimalComponent {
59 /** This class implements the component. At least the interfaces XServiceInfo,
60 * XTypeProvider, and XInitialization should be provided by the service.
62 public static class _MinimalComponent extends WeakBase
63 implements XInitialization, XServiceInfo {
64 /** The service name, that must be used to get an instance of this service.
66 static private final String __serviceName =
67 "org.openoffice.MinimalComponent";
69 /** The initial component contextr, that gives access to
70 * the service manager, supported singletons, ...
71 * It's often later used
73 private XComponentContext m_cmpCtx;
75 /** The service manager, that gives access to all registered services.
76 * It's often later used
78 private XMultiComponentFactory m_xMCF;
80 /** The constructor of the inner class has a XMultiServiceFactory parameter.
81 * @param xmultiservicefactoryInitialization A special service factory
82 * could be introduced while initializing.
84 public _MinimalComponent(XComponentContext xCompContext) {
85 try {
86 m_cmpCtx = xCompContext;
87 m_xMCF = m_cmpCtx.getServiceManager();
89 catch( Exception e ) {
90 e.printStackTrace();
94 /** This method is a member of the interface for initializing an object
95 * directly after its creation.
96 * @param object This array of arbitrary objects will be passed to the
97 * component after its creation.
98 * @throws Exception Every exception will not be handled, but will be
99 * passed to the caller.
101 public void initialize( Object[] object )
102 throws com.sun.star.uno.Exception {
103 /* The component describes what arguments its expected and in which
104 * order!At this point you can read the objects and can intialize
105 * your component using these objects.
109 /** This method returns an array of all supported service names.
110 * @return Array of supported service names.
112 public String[] getSupportedServiceNames() {
113 return getServiceNames();
116 /** This method is a simple helper function to used in the
117 * static component initialisation functions as well as in
118 * getSupportedServiceNames.
120 public static String[] getServiceNames() {
121 String[] sSupportedServiceNames = { __serviceName };
122 return sSupportedServiceNames;
125 /** This method returns true, if the given service will be
126 * supported by the component.
127 * @param sServiceName Service name.
128 * @return True, if the given service name will be supported.
130 public boolean supportsService( String sServiceName ) {
131 return sServiceName.equals( __serviceName );
134 /** Return the class name of the component.
135 * @return Class name of the component.
137 public String getImplementationName() {
138 return _MinimalComponent.class.getName();
144 * Gives a factory for creating the service.
145 * This method is called by the <code>JavaLoader</code>
146 * <p>
147 * @return returns a <code>XSingleComponentFactory</code> for creating
148 * the component
149 * @param sImplName the name of the implementation for which a
150 * service is desired
151 * @see com.sun.star.comp.loader.JavaLoader
153 public static XSingleComponentFactory __getComponentFactory(String sImplName)
155 XSingleComponentFactory xFactory = null;
157 if ( sImplName.equals( _MinimalComponent.class.getName() ) )
158 xFactory = Factory.createComponentFactory(_MinimalComponent.class,
159 _MinimalComponent.getServiceNames());
161 return xFactory;
165 * Writes the service information into the given registry key.
166 * This method is called by the <code>JavaLoader</code>
167 * <p>
168 * @return returns true if the operation succeeded
169 * @param regKey the registryKey
170 * @see com.sun.star.comp.loader.JavaLoader
172 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
173 return Factory.writeRegistryServiceInfo(_MinimalComponent.class.getName(),
174 _MinimalComponent.getServiceNames(),
175 regKey);