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