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