Update ooo320-m1
[ooovba.git] / odk / examples / DevelopersGuide / Components / SimpleLicense / LicenseTest.java
blobaec441c133017719d9942a6e659562c9af5e8970
1 /*************************************************************************
3 * $RCSfile: LicenseTest.java,v $
5 * $Revision: 1.2 $
7 * last change: $Author: kz $ $Date: 2006-10-04 16:21:15 $
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 LicenseTest {
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 _LicenseTest extends WeakBase
63 implements 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.LicenseTest";
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 _LicenseTest(XComponentContext xCompContext) {
85 try {
86 m_cmpCtx = xCompContext;
87 m_xMCF = m_cmpCtx.getServiceManager();
89 catch( Exception e ) {
90 e.printStackTrace();
94 /** This method returns an array of all supported service names.
95 * @return Array of supported service names.
97 public String[] getSupportedServiceNames() {
98 return getServiceNames();
101 /** This method is a simple helper function to used in the
102 * static component initialisation functions as well as in
103 * getSupportedServiceNames.
105 public static String[] getServiceNames() {
106 String[] sSupportedServiceNames = { __serviceName };
107 return sSupportedServiceNames;
110 /** This method returns true, if the given service will be
111 * supported by the component.
112 * @param sServiceName Service name.
113 * @return True, if the given service name will be supported.
115 public boolean supportsService( String sServiceName ) {
116 return sServiceName.equals( __serviceName );
119 /** Return the class name of the component.
120 * @return Class name of the component.
122 public String getImplementationName() {
123 return _LicenseTest.class.getName();
129 * Gives a factory for creating the service.
130 * This method is called by the <code>JavaLoader</code>
131 * <p>
132 * @return returns a <code>XSingleComponentFactory</code> for creating
133 * the component
134 * @param sImplName the name of the implementation for which a
135 * service is desired
136 * @see com.sun.star.comp.loader.JavaLoader
138 public static XSingleComponentFactory __getComponentFactory(String sImplName)
140 XSingleComponentFactory xFactory = null;
142 if ( sImplName.equals( _LicenseTest.class.getName() ) )
143 xFactory = Factory.createComponentFactory(_LicenseTest.class,
144 _LicenseTest.getServiceNames());
146 return xFactory;
150 * Writes the service information into the given registry key.
151 * This method is called by the <code>JavaLoader</code>
152 * <p>
153 * @return returns true if the operation succeeded
154 * @param regKey the registryKey
155 * @see com.sun.star.comp.loader.JavaLoader
157 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
158 return Factory.writeRegistryServiceInfo(_LicenseTest.class.getName(),
159 _LicenseTest.getServiceNames(),
160 regKey);
162 /** This method is a member of the interface for initializing an object
163 * directly after its creation.
164 * @param object This array of arbitrary objects will be passed to the
165 * component after its creation.
166 * @throws Exception Every exception will not be handled, but will be
167 * passed to the caller.
169 public void initialize( Object[] object )
170 throws com.sun.star.uno.Exception {
171 /* The component describes what arguments its expected and in which
172 * order!At this point you can read the objects and can intialize
173 * your component using these objects.