1*b0c15f6dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0c15f6dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0c15f6dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0c15f6dSAndrew Rist  * distributed with this work for additional information
6*b0c15f6dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0c15f6dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0c15f6dSAndrew Rist  * "License"); you may not use this file except in compliance
9*b0c15f6dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0c15f6dSAndrew Rist  *
11*b0c15f6dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0c15f6dSAndrew Rist  *
13*b0c15f6dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0c15f6dSAndrew Rist  * software distributed under the License is distributed on an
15*b0c15f6dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0c15f6dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0c15f6dSAndrew Rist  * specific language governing permissions and limitations
18*b0c15f6dSAndrew Rist  * under the License.
19*b0c15f6dSAndrew Rist  *
20*b0c15f6dSAndrew Rist  *************************************************************/
21*b0c15f6dSAndrew Rist 
22*b0c15f6dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.smoketest;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory;
27cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
28cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory;
29cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
31cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
32cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
33cdf0e10cSrcweir import com.sun.star.lang.XInitialization;
34cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
35cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
36cdf0e10cSrcweir import com.sun.star.uno.Type;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** This class capsulates the class, that implements the minimal component, a
39cdf0e10cSrcweir  * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a
40cdf0e10cSrcweir  * method, that writes the information into the given registry key
41cdf0e10cSrcweir  * (<CODE>__writeRegistryServiceInfo</CODE>).
42cdf0e10cSrcweir  */
43cdf0e10cSrcweir public class TestExtension {
44cdf0e10cSrcweir     /** This class implements the component. At least the interfaces XServiceInfo,
45cdf0e10cSrcweir      * XTypeProvider, and XInitialization should be provided by the service.
46cdf0e10cSrcweir      */
47cdf0e10cSrcweir     public static class _TestExtension extends WeakBase
48cdf0e10cSrcweir         implements XServiceInfo {
49cdf0e10cSrcweir         /** The service name, that must be used to get an instance of this service.
50cdf0e10cSrcweir          */
51cdf0e10cSrcweir         static private final String __serviceName =
52cdf0e10cSrcweir         "com.sun.star.comp.smoketest.TestExtension";
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         /** The initial component contextr, that gives access to
55cdf0e10cSrcweir          * the service manager, supported singletons, ...
56cdf0e10cSrcweir          * It's often later used
57cdf0e10cSrcweir          */
58cdf0e10cSrcweir         private XComponentContext m_cmpCtx;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         /** The service manager, that gives access to all registered services.
61cdf0e10cSrcweir          * It's often later used
62cdf0e10cSrcweir          */
63cdf0e10cSrcweir         private XMultiComponentFactory m_xMCF;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         /** The constructor of the inner class has a XMultiServiceFactory parameter.
66cdf0e10cSrcweir          * @param xmultiservicefactoryInitialization A special service factory
67cdf0e10cSrcweir          * could be introduced while initializing.
68cdf0e10cSrcweir          */
69cdf0e10cSrcweir         public _TestExtension(XComponentContext xCompContext) {
70cdf0e10cSrcweir             try {
71cdf0e10cSrcweir                 m_cmpCtx = xCompContext;
72cdf0e10cSrcweir                 m_xMCF = m_cmpCtx.getServiceManager();
73cdf0e10cSrcweir             }
74cdf0e10cSrcweir             catch( Exception e ) {
75cdf0e10cSrcweir                 e.printStackTrace();
76cdf0e10cSrcweir             }
77cdf0e10cSrcweir         }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         /** This method returns an array of all supported service names.
80cdf0e10cSrcweir          * @return Array of supported service names.
81cdf0e10cSrcweir          */
82cdf0e10cSrcweir         public String[] getSupportedServiceNames() {
83cdf0e10cSrcweir             return getServiceNames();
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         /** This method is a simple helper function to used in the
87cdf0e10cSrcweir          * static component initialisation functions as well as in
88cdf0e10cSrcweir          * getSupportedServiceNames.
89cdf0e10cSrcweir          */
90cdf0e10cSrcweir         public static String[] getServiceNames() {
91cdf0e10cSrcweir             String[] sSupportedServiceNames = { __serviceName };
92cdf0e10cSrcweir             return sSupportedServiceNames;
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         /** This method returns true, if the given service will be
96cdf0e10cSrcweir          * supported by the component.
97cdf0e10cSrcweir          * @param sServiceName Service name.
98cdf0e10cSrcweir          * @return True, if the given service name will be supported.
99cdf0e10cSrcweir          */
100cdf0e10cSrcweir         public boolean supportsService( String sServiceName ) {
101cdf0e10cSrcweir             return sServiceName.equals( __serviceName );
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         /** Return the class name of the component.
105cdf0e10cSrcweir          * @return Class name of the component.
106cdf0e10cSrcweir          */
107cdf0e10cSrcweir         public String getImplementationName() {
108cdf0e10cSrcweir             return  _TestExtension.class.getName();
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /**
114cdf0e10cSrcweir      * Gives a factory for creating the service.
115cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
116cdf0e10cSrcweir      * <p>
117cdf0e10cSrcweir      * @return  returns a <code>XSingleComponentFactory</code> for creating
118cdf0e10cSrcweir      *          the component
119cdf0e10cSrcweir      * @param   sImplName the name of the implementation for which a
120cdf0e10cSrcweir      *          service is desired
121cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
122cdf0e10cSrcweir      */
123cdf0e10cSrcweir     public static XSingleComponentFactory __getComponentFactory(String sImplName)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         XSingleComponentFactory xFactory = null;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         if ( sImplName.equals( _TestExtension.class.getName() ) )
128cdf0e10cSrcweir             xFactory = Factory.createComponentFactory(_TestExtension.class,
129cdf0e10cSrcweir                                              _TestExtension.getServiceNames());
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         return xFactory;
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     /**
135cdf0e10cSrcweir      * Writes the service information into the given registry key.
136cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
137cdf0e10cSrcweir      * <p>
138cdf0e10cSrcweir      * @return  returns true if the operation succeeded
139cdf0e10cSrcweir      * @param   regKey the registryKey
140cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
141cdf0e10cSrcweir      */
142cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
143cdf0e10cSrcweir         return Factory.writeRegistryServiceInfo(_TestExtension.class.getName(),
144cdf0e10cSrcweir                                                 _TestExtension.getServiceNames(),
145cdf0e10cSrcweir                                                 regKey);
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir         /** This method is a member of the interface for initializing an object
148cdf0e10cSrcweir          * directly after its creation.
149cdf0e10cSrcweir          * @param object This array of arbitrary objects will be passed to the
150cdf0e10cSrcweir          * component after its creation.
151cdf0e10cSrcweir          * @throws Exception Every exception will not be handled, but will be
152cdf0e10cSrcweir          * passed to the caller.
153cdf0e10cSrcweir          */
154cdf0e10cSrcweir         public void initialize( Object[] object )
155cdf0e10cSrcweir             throws com.sun.star.uno.Exception {
156cdf0e10cSrcweir             /* The component describes what arguments its expected and in which
157cdf0e10cSrcweir              * order!At this point you can read the objects and can intialize
158cdf0e10cSrcweir              * your component using these objects.
159cdf0e10cSrcweir              */
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir }
163