1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package com.sun.star.comp.smoketest;
29 
30 import com.sun.star.lib.uno.helper.Factory;
31 import com.sun.star.lang.XMultiComponentFactory;
32 import com.sun.star.lang.XSingleComponentFactory;
33 import com.sun.star.lib.uno.helper.WeakBase;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XComponentContext;
36 import com.sun.star.registry.XRegistryKey;
37 import com.sun.star.lang.XInitialization;
38 import com.sun.star.lang.XTypeProvider;
39 import com.sun.star.lang.XServiceInfo;
40 import com.sun.star.uno.Type;
41 
42 /** This class capsulates the class, that implements the minimal component, a
43  * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
44  * method, that writes the information into the given registry key
45  * (<CODE>__writeRegistryServiceInfo</CODE>).
46  */
47 public class TestExtension {
48     /** This class implements the component. At least the interfaces XServiceInfo,
49      * XTypeProvider, and XInitialization should be provided by the service.
50      */
51     public static class _TestExtension extends WeakBase
52         implements XServiceInfo {
53         /** The service name, that must be used to get an instance of this service.
54          */
55         static private final String __serviceName =
56         "com.sun.star.comp.smoketest.TestExtension";
57 
58         /** The initial component contextr, that gives access to
59          * the service manager, supported singletons, ...
60          * It's often later used
61          */
62         private XComponentContext m_cmpCtx;
63 
64         /** The service manager, that gives access to all registered services.
65          * It's often later used
66          */
67         private XMultiComponentFactory m_xMCF;
68 
69         /** The constructor of the inner class has a XMultiServiceFactory parameter.
70          * @param xmultiservicefactoryInitialization A special service factory
71          * could be introduced while initializing.
72          */
73         public _TestExtension(XComponentContext xCompContext) {
74             try {
75                 m_cmpCtx = xCompContext;
76                 m_xMCF = m_cmpCtx.getServiceManager();
77             }
78             catch( Exception e ) {
79                 e.printStackTrace();
80             }
81         }
82 
83         /** This method returns an array of all supported service names.
84          * @return Array of supported service names.
85          */
86         public String[] getSupportedServiceNames() {
87             return getServiceNames();
88         }
89 
90         /** This method is a simple helper function to used in the
91          * static component initialisation functions as well as in
92          * getSupportedServiceNames.
93          */
94         public static String[] getServiceNames() {
95             String[] sSupportedServiceNames = { __serviceName };
96             return sSupportedServiceNames;
97         }
98 
99         /** This method returns true, if the given service will be
100          * supported by the component.
101          * @param sServiceName Service name.
102          * @return True, if the given service name will be supported.
103          */
104         public boolean supportsService( String sServiceName ) {
105             return sServiceName.equals( __serviceName );
106         }
107 
108         /** Return the class name of the component.
109          * @return Class name of the component.
110          */
111         public String getImplementationName() {
112             return  _TestExtension.class.getName();
113         }
114     }
115 
116 
117     /**
118      * Gives a factory for creating the service.
119      * This method is called by the <code>JavaLoader</code>
120      * <p>
121      * @return  returns a <code>XSingleComponentFactory</code> for creating
122      *          the component
123      * @param   sImplName the name of the implementation for which a
124      *          service is desired
125      * @see     com.sun.star.comp.loader.JavaLoader
126      */
127     public static XSingleComponentFactory __getComponentFactory(String sImplName)
128     {
129         XSingleComponentFactory xFactory = null;
130 
131         if ( sImplName.equals( _TestExtension.class.getName() ) )
132             xFactory = Factory.createComponentFactory(_TestExtension.class,
133                                              _TestExtension.getServiceNames());
134 
135         return xFactory;
136     }
137 
138     /**
139      * Writes the service information into the given registry key.
140      * This method is called by the <code>JavaLoader</code>
141      * <p>
142      * @return  returns true if the operation succeeded
143      * @param   regKey the registryKey
144      * @see     com.sun.star.comp.loader.JavaLoader
145      */
146     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
147         return Factory.writeRegistryServiceInfo(_TestExtension.class.getName(),
148                                                 _TestExtension.getServiceNames(),
149                                                 regKey);
150     }
151         /** This method is a member of the interface for initializing an object
152          * directly after its creation.
153          * @param object This array of arbitrary objects will be passed to the
154          * component after its creation.
155          * @throws Exception Every exception will not be handled, but will be
156          * passed to the caller.
157          */
158         public void initialize( Object[] object )
159             throws com.sun.star.uno.Exception {
160             /* The component describes what arguments its expected and in which
161              * order!At this point you can read the objects and can intialize
162              * your component using these objects.
163              */
164         }
165 
166 }
167