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