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 28*cdf0e10cSrcweir package com.sun.star.comp.smoketest; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory; 31*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 32*cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory; 33*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase; 34*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 36*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 37*cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 38*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 39*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 40*cdf0e10cSrcweir import com.sun.star.uno.Type; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** This class capsulates the class, that implements the minimal component, a 43*cdf0e10cSrcweir * factory for creating the service (<CODE>__getComponentFactory</CODE>) and a 44*cdf0e10cSrcweir * method, that writes the information into the given registry key 45*cdf0e10cSrcweir * (<CODE>__writeRegistryServiceInfo</CODE>). 46*cdf0e10cSrcweir */ 47*cdf0e10cSrcweir public class TestExtension { 48*cdf0e10cSrcweir /** This class implements the component. At least the interfaces XServiceInfo, 49*cdf0e10cSrcweir * XTypeProvider, and XInitialization should be provided by the service. 50*cdf0e10cSrcweir */ 51*cdf0e10cSrcweir public static class _TestExtension extends WeakBase 52*cdf0e10cSrcweir implements XServiceInfo { 53*cdf0e10cSrcweir /** The service name, that must be used to get an instance of this service. 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir static private final String __serviceName = 56*cdf0e10cSrcweir "com.sun.star.comp.smoketest.TestExtension"; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** The initial component contextr, that gives access to 59*cdf0e10cSrcweir * the service manager, supported singletons, ... 60*cdf0e10cSrcweir * It's often later used 61*cdf0e10cSrcweir */ 62*cdf0e10cSrcweir private XComponentContext m_cmpCtx; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir /** The service manager, that gives access to all registered services. 65*cdf0e10cSrcweir * It's often later used 66*cdf0e10cSrcweir */ 67*cdf0e10cSrcweir private XMultiComponentFactory m_xMCF; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /** The constructor of the inner class has a XMultiServiceFactory parameter. 70*cdf0e10cSrcweir * @param xmultiservicefactoryInitialization A special service factory 71*cdf0e10cSrcweir * could be introduced while initializing. 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir public _TestExtension(XComponentContext xCompContext) { 74*cdf0e10cSrcweir try { 75*cdf0e10cSrcweir m_cmpCtx = xCompContext; 76*cdf0e10cSrcweir m_xMCF = m_cmpCtx.getServiceManager(); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir catch( Exception e ) { 79*cdf0e10cSrcweir e.printStackTrace(); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** This method returns an array of all supported service names. 84*cdf0e10cSrcweir * @return Array of supported service names. 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir public String[] getSupportedServiceNames() { 87*cdf0e10cSrcweir return getServiceNames(); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir /** This method is a simple helper function to used in the 91*cdf0e10cSrcweir * static component initialisation functions as well as in 92*cdf0e10cSrcweir * getSupportedServiceNames. 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir public static String[] getServiceNames() { 95*cdf0e10cSrcweir String[] sSupportedServiceNames = { __serviceName }; 96*cdf0e10cSrcweir return sSupportedServiceNames; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir /** This method returns true, if the given service will be 100*cdf0e10cSrcweir * supported by the component. 101*cdf0e10cSrcweir * @param sServiceName Service name. 102*cdf0e10cSrcweir * @return True, if the given service name will be supported. 103*cdf0e10cSrcweir */ 104*cdf0e10cSrcweir public boolean supportsService( String sServiceName ) { 105*cdf0e10cSrcweir return sServiceName.equals( __serviceName ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir /** Return the class name of the component. 109*cdf0e10cSrcweir * @return Class name of the component. 110*cdf0e10cSrcweir */ 111*cdf0e10cSrcweir public String getImplementationName() { 112*cdf0e10cSrcweir return _TestExtension.class.getName(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir /** 118*cdf0e10cSrcweir * Gives a factory for creating the service. 119*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 120*cdf0e10cSrcweir * <p> 121*cdf0e10cSrcweir * @return returns a <code>XSingleComponentFactory</code> for creating 122*cdf0e10cSrcweir * the component 123*cdf0e10cSrcweir * @param sImplName the name of the implementation for which a 124*cdf0e10cSrcweir * service is desired 125*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 126*cdf0e10cSrcweir */ 127*cdf0e10cSrcweir public static XSingleComponentFactory __getComponentFactory(String sImplName) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir XSingleComponentFactory xFactory = null; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if ( sImplName.equals( _TestExtension.class.getName() ) ) 132*cdf0e10cSrcweir xFactory = Factory.createComponentFactory(_TestExtension.class, 133*cdf0e10cSrcweir _TestExtension.getServiceNames()); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir return xFactory; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir /** 139*cdf0e10cSrcweir * Writes the service information into the given registry key. 140*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 141*cdf0e10cSrcweir * <p> 142*cdf0e10cSrcweir * @return returns true if the operation succeeded 143*cdf0e10cSrcweir * @param regKey the registryKey 144*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 145*cdf0e10cSrcweir */ 146*cdf0e10cSrcweir public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 147*cdf0e10cSrcweir return Factory.writeRegistryServiceInfo(_TestExtension.class.getName(), 148*cdf0e10cSrcweir _TestExtension.getServiceNames(), 149*cdf0e10cSrcweir regKey); 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*cdf0e10cSrcweir } 167