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