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