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