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