1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package com.sun.star.comp.loader; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import java.lang.reflect.Method; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import java.lang.reflect.InvocationTargetException; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import java.net.URLDecoder; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir import com.sun.star.loader.CannotActivateFactoryException; 37*cdf0e10cSrcweir import com.sun.star.loader.XImplementationLoader; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir import com.sun.star.registry.CannotRegisterImplementationException; 40*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory; 43*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 44*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 45*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 46*cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 49*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 50*cdf0e10cSrcweir import com.sun.star.util.XMacroExpander; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir import com.sun.star.uno.Type; 53*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir import com.sun.star.lib.util.StringHelper; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /** 61*cdf0e10cSrcweir * The <code>JavaLoader</code> class provides the functionality of the <code>com.sun.star.loader.Java</code> 62*cdf0e10cSrcweir * service. Therefor the <code>JavaLoader</code> activates external UNO components which are implemented in Java. 63*cdf0e10cSrcweir * The loader is used by the <code>ServiceManger</code>. 64*cdf0e10cSrcweir * <p> 65*cdf0e10cSrcweir * @version $Revision: 1.16 $ $ $Date: 2008-04-11 11:10:31 $ 66*cdf0e10cSrcweir * @author Markus Herzog 67*cdf0e10cSrcweir * @see com.sun.star.loader.XImplementationLoader 68*cdf0e10cSrcweir * @see com.sun.star.loader.Java 69*cdf0e10cSrcweir * @see com.sun.star.comp.servicemanager.ServiceManager 70*cdf0e10cSrcweir * @see com.sun.star.lang.ServiceManager 71*cdf0e10cSrcweir * @since UDK1.0 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir public class JavaLoader implements XImplementationLoader, 74*cdf0e10cSrcweir XServiceInfo, 75*cdf0e10cSrcweir XInitialization 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir private static final boolean DEBUG = false; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir private static final void DEBUG(String dbg) { 80*cdf0e10cSrcweir if (DEBUG) System.err.println( dbg ); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir private static String[] supportedServices = { 84*cdf0e10cSrcweir "com.sun.star.loader.Java" 85*cdf0e10cSrcweir }; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir protected XMultiServiceFactory multiServiceFactory = null; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir private XMacroExpander m_xMacroExpander = null; 90*cdf0e10cSrcweir private static final String EXPAND_PROTOCOL_PREFIX = "vnd.sun.star.expand:"; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir /** Expands macrofied url using the macro expander singleton. 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir private String expand_url( String url ) throws RuntimeException 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir if (url != null && url.startsWith( EXPAND_PROTOCOL_PREFIX )) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir try 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir if (m_xMacroExpander == null) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir XPropertySet xProps = 103*cdf0e10cSrcweir UnoRuntime.queryInterface( 104*cdf0e10cSrcweir XPropertySet.class, multiServiceFactory ); 105*cdf0e10cSrcweir if (xProps == null) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException( 108*cdf0e10cSrcweir "service manager does not support XPropertySet!", 109*cdf0e10cSrcweir this ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir XComponentContext xContext = (XComponentContext) 112*cdf0e10cSrcweir AnyConverter.toObject( 113*cdf0e10cSrcweir new Type( XComponentContext.class ), 114*cdf0e10cSrcweir xProps.getPropertyValue( "DefaultContext" ) ); 115*cdf0e10cSrcweir m_xMacroExpander = (XMacroExpander)AnyConverter.toObject( 116*cdf0e10cSrcweir new Type( XMacroExpander.class ), 117*cdf0e10cSrcweir xContext.getValueByName( 118*cdf0e10cSrcweir "/singletons/com.sun.star.util.theMacroExpander" ) 119*cdf0e10cSrcweir ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir // decode uric class chars 122*cdf0e10cSrcweir String macro = URLDecoder.decode( 123*cdf0e10cSrcweir StringHelper.replace( 124*cdf0e10cSrcweir url.substring( EXPAND_PROTOCOL_PREFIX.length() ), 125*cdf0e10cSrcweir '+', "%2B" ) ); 126*cdf0e10cSrcweir // expand macro string 127*cdf0e10cSrcweir String ret = m_xMacroExpander.expandMacros( macro ); 128*cdf0e10cSrcweir if (DEBUG) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir System.err.println( 131*cdf0e10cSrcweir "JavaLoader.expand_url(): " + url + " => " + 132*cdf0e10cSrcweir macro + " => " + ret ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir return ret; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exc) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException( 139*cdf0e10cSrcweir exc.getMessage(), this ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir catch (java.lang.Exception exc) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir throw new com.sun.star.uno.RuntimeException( 144*cdf0e10cSrcweir exc.getMessage(), this ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir return url; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /** default constructor 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir /** 154*cdf0e10cSrcweir * Creates a new instance of the <code>JavaLoader</code> class. 155*cdf0e10cSrcweir * <p> 156*cdf0e10cSrcweir * @return new instance 157*cdf0e10cSrcweir */ 158*cdf0e10cSrcweir public JavaLoader() {} 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** 161*cdf0e10cSrcweir * Creates a new <code>JavaLoader</code> object. The specified <code>com.sun.star.lang.XMultiServiceFactory</code> 162*cdf0e10cSrcweir * is the <code>ServiceManager</code> service which can be deliviert to all components the <code>JavaLoader</code> is 163*cdf0e10cSrcweir * loading. 164*cdf0e10cSrcweir * To set the <code>MultiServiceFactory</code> you can use the <code>com.sun.star.lang.XInitialization</code> interface, either. 165*cdf0e10cSrcweir * <p> 166*cdf0e10cSrcweir * @return new instance 167*cdf0e10cSrcweir * @param factory the <code>ServiceManager</code> 168*cdf0e10cSrcweir * @see com.sun.star.lang.ServiceManager 169*cdf0e10cSrcweir * @see com.sun.star.lang.ServiceManager 170*cdf0e10cSrcweir * @see com.sun.star.lang.XInitialization 171*cdf0e10cSrcweir */ 172*cdf0e10cSrcweir public JavaLoader(XMultiServiceFactory factory) { 173*cdf0e10cSrcweir multiServiceFactory = factory; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir /** 177*cdf0e10cSrcweir * Unlike the original intention, the method could be called every time a new 178*cdf0e10cSrcweir * <code>com.sun.star.lang.XMultiServiceFactory</code> should be set at the loader. 179*cdf0e10cSrcweir * <p> 180*cdf0e10cSrcweir * @param args - the first parameter (args[0]) specifices the <code>ServiceManager</code> 181*cdf0e10cSrcweir * @see com.sun.star.lang.XInitialization 182*cdf0e10cSrcweir * @see com.sun.star.lang.ServiceManager 183*cdf0e10cSrcweir */ 184*cdf0e10cSrcweir public void initialize( java.lang.Object[] args ) 185*cdf0e10cSrcweir throws com.sun.star.uno.Exception, 186*cdf0e10cSrcweir com.sun.star.uno.RuntimeException 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir if (args.length == 0) throw new com.sun.star.lang.IllegalArgumentException("No arguments specified"); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir try { 191*cdf0e10cSrcweir multiServiceFactory = (XMultiServiceFactory) AnyConverter.toObject( 192*cdf0e10cSrcweir new Type(XMultiServiceFactory.class), args[0]); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir catch (ClassCastException castEx) { 195*cdf0e10cSrcweir throw new com.sun.star.lang.IllegalArgumentException( 196*cdf0e10cSrcweir "The argument must be an instance of XMultiServiceFactory"); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir /** 201*cdf0e10cSrcweir * Supplies the implementation name of the component. 202*cdf0e10cSrcweir * <p> 203*cdf0e10cSrcweir * @return the implementation name - here the class name 204*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 205*cdf0e10cSrcweir */ 206*cdf0e10cSrcweir public String getImplementationName() 207*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir return getClass().getName(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir /** 213*cdf0e10cSrcweir * Verifies if a given service is supported by the component. 214*cdf0e10cSrcweir * <p> 215*cdf0e10cSrcweir * @return true,if service is suported - otherwise false 216*cdf0e10cSrcweir * @param serviceName the name of the service that should be checked 217*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 218*cdf0e10cSrcweir */ 219*cdf0e10cSrcweir public boolean supportsService(String serviceName) 220*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir for ( int i = 0; i < supportedServices.length; i++ ) { 223*cdf0e10cSrcweir if ( supportedServices[i].equals(serviceName) ) 224*cdf0e10cSrcweir return true; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir return false; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir /** 230*cdf0e10cSrcweir * Supplies a list of all service names supported by the component 231*cdf0e10cSrcweir * <p> 232*cdf0e10cSrcweir * @return a String array with all supported services 233*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 234*cdf0e10cSrcweir */ 235*cdf0e10cSrcweir public String[] getSupportedServiceNames() 236*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir return supportedServices; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir /** 242*cdf0e10cSrcweir * Provides a components factory. 243*cdf0e10cSrcweir * The <code>JavaLoader</code> tries to load the class first. If a loacation URL is given the 244*cdf0e10cSrcweir * RegistrationClassFinder is used to load the class. Otherwise the class is loaded thru the Class.forName 245*cdf0e10cSrcweir * method. 246*cdf0e10cSrcweir * To get the factory the inspects the class for the optional static member functions __getServiceFactory resp. 247*cdf0e10cSrcweir * getServiceFactory (DEPRECATED). 248*cdf0e10cSrcweir * If the function can not be found a default factory @see ComponentFactoryWrapper will be created. 249*cdf0e10cSrcweir * <p> 250*cdf0e10cSrcweir * @return the factory for the component (@see com.sun.star.lang.XSingleServiceFactory) 251*cdf0e10cSrcweir * @param implementationName the implementation (class) name of the component 252*cdf0e10cSrcweir * @param implementationLoaderUrl the URL of the implementation loader. Not used. 253*cdf0e10cSrcweir * @param locationUrl points to an archive (JAR file) which contains a component 254*cdf0e10cSrcweir * @param xKey 255*cdf0e10cSrcweir * @see com.sun.star.lang.XImplementationLoader 256*cdf0e10cSrcweir * @see com.sun.star.com.loader.RegistrationClassFinder 257*cdf0e10cSrcweir */ 258*cdf0e10cSrcweir public java.lang.Object activate( String implementationName, 259*cdf0e10cSrcweir String implementationLoaderUrl, 260*cdf0e10cSrcweir String locationUrl, 261*cdf0e10cSrcweir XRegistryKey xKey ) 262*cdf0e10cSrcweir throws CannotActivateFactoryException, 263*cdf0e10cSrcweir com.sun.star.uno.RuntimeException 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir locationUrl = expand_url( locationUrl ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir Object returnObject = null; 268*cdf0e10cSrcweir Class clazz ; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir DEBUG("try to get factory for " + implementationName); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // first we must get the class of the implementation 273*cdf0e10cSrcweir // 1. If a location URL is given it is assumed that this points to a JAR file. 274*cdf0e10cSrcweir // The components class name is stored in the manifest file. 275*cdf0e10cSrcweir // 2. If only the implementation name is given, the class is loaded with the 276*cdf0e10cSrcweir // Class.forName() method. This is a hack to load bootstrap components. 277*cdf0e10cSrcweir // Normally a string must no be null. 278*cdf0e10cSrcweir try { 279*cdf0e10cSrcweir if ( locationUrl != null ) { 280*cdf0e10cSrcweir // 1. 281*cdf0e10cSrcweir clazz = RegistrationClassFinder.find( locationUrl ); 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir else { 284*cdf0e10cSrcweir // 2. 285*cdf0e10cSrcweir clazz = Class.forName( implementationName ); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir catch (java.net.MalformedURLException e) { 289*cdf0e10cSrcweir CannotActivateFactoryException cae = new CannotActivateFactoryException( 290*cdf0e10cSrcweir "Can not activate factory because " + e.toString() ); 291*cdf0e10cSrcweir cae.fillInStackTrace(); 292*cdf0e10cSrcweir throw cae; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir catch (java.io.IOException e) { 295*cdf0e10cSrcweir CannotActivateFactoryException cae = new CannotActivateFactoryException( 296*cdf0e10cSrcweir "Can not activate factory because " + e.toString() ); 297*cdf0e10cSrcweir cae.fillInStackTrace(); 298*cdf0e10cSrcweir throw cae; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir catch (java.lang.ClassNotFoundException e) { 301*cdf0e10cSrcweir CannotActivateFactoryException cae = new CannotActivateFactoryException( 302*cdf0e10cSrcweir "Can not activate factory because " + e.toString() ); 303*cdf0e10cSrcweir cae.fillInStackTrace(); 304*cdf0e10cSrcweir throw cae; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir if (null == clazz) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir CannotActivateFactoryException cae = 310*cdf0e10cSrcweir new CannotActivateFactoryException( 311*cdf0e10cSrcweir "Cannot determine activation class!" ); 312*cdf0e10cSrcweir cae.fillInStackTrace(); 313*cdf0e10cSrcweir throw cae; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir Class[] paramTypes = {String.class, XMultiServiceFactory.class, XRegistryKey.class}; 317*cdf0e10cSrcweir Object[] params = { implementationName, multiServiceFactory, xKey }; 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // try to get factory from implemetation class 320*cdf0e10cSrcweir // latest style: use the public static method __getComponentFactory 321*cdf0e10cSrcweir // - new style: use the public static method __getServiceFactory 322*cdf0e10cSrcweir // - old style: use the public static method getServiceFactory ( DEPRECATED ) 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir Method compfac_method = null; 325*cdf0e10cSrcweir try 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir compfac_method = clazz.getMethod( 328*cdf0e10cSrcweir "__getComponentFactory", new Class [] { String.class } ); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir catch ( NoSuchMethodException noSuchMethodEx) {} 331*cdf0e10cSrcweir catch ( SecurityException secEx) {} 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir Method method = null; 334*cdf0e10cSrcweir if (null == compfac_method) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir try { 337*cdf0e10cSrcweir method = clazz.getMethod("__getServiceFactory", paramTypes); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir catch ( NoSuchMethodException noSuchMethodEx) { 340*cdf0e10cSrcweir method = null; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir catch ( SecurityException secEx) { 343*cdf0e10cSrcweir method = null; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir try { 348*cdf0e10cSrcweir if (null != compfac_method) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir Object ret = compfac_method.invoke( clazz, new Object [] { implementationName } ); 351*cdf0e10cSrcweir if (null == ret || !(ret instanceof XSingleComponentFactory)) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir throw new CannotActivateFactoryException( 354*cdf0e10cSrcweir "No factory object for " + implementationName ); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir return (XSingleComponentFactory)ret; 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir else 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir if ( method == null ) { 361*cdf0e10cSrcweir method = clazz.getMethod("getServiceFactory", paramTypes); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir Object oRet = method.invoke(clazz, params); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir if ( (oRet != null) && (oRet instanceof XSingleServiceFactory) ) { 367*cdf0e10cSrcweir returnObject = (XSingleServiceFactory) oRet; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir catch ( NoSuchMethodException e) { 372*cdf0e10cSrcweir throw new CannotActivateFactoryException("Can not activate the factory for " 373*cdf0e10cSrcweir + implementationName + " because " + e.toString() ); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir catch ( SecurityException e) { 376*cdf0e10cSrcweir throw new CannotActivateFactoryException("Can not activate the factory for " 377*cdf0e10cSrcweir + implementationName + " because " + e.toString() ); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir catch ( IllegalAccessException e ) { 380*cdf0e10cSrcweir throw new CannotActivateFactoryException("Can not activate the factory for " 381*cdf0e10cSrcweir + implementationName + " because " + e.toString() ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir catch ( IllegalArgumentException e ) { 384*cdf0e10cSrcweir throw new CannotActivateFactoryException("Can not activate the factory for " 385*cdf0e10cSrcweir + implementationName + " because " + e.toString() ); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir catch ( InvocationTargetException e ) { 388*cdf0e10cSrcweir throw new CannotActivateFactoryException("Can not activate the factory for " 389*cdf0e10cSrcweir + implementationName + " because " + e.getTargetException().toString() ); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir return returnObject; 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir /** 396*cdf0e10cSrcweir * Registers the component in a registry under a given root key. If the component supports the optional 397*cdf0e10cSrcweir * methods __writeRegistryServiceInfo, writeRegistryServiceInfo (DEPRECATED), the call is delegated to that 398*cdf0e10cSrcweir * method. Otherwise a default registration will be accomplished. 399*cdf0e10cSrcweir * <p> 400*cdf0e10cSrcweir * @return true if registration is successfully - otherwise false 401*cdf0e10cSrcweir * @param regKey the root key under that the component should be registred. 402*cdf0e10cSrcweir * @param implementationLoaderUrl specifies the loader, the component is loaded by. 403*cdf0e10cSrcweir * @param locationUrl points to an archive (JAR file) which contains a component 404*cdf0e10cSrcweir * @see ComponentFactoryWrapper 405*cdf0e10cSrcweir */ 406*cdf0e10cSrcweir public boolean writeRegistryInfo( XRegistryKey regKey, 407*cdf0e10cSrcweir String implementationLoaderUrl, 408*cdf0e10cSrcweir String locationUrl ) 409*cdf0e10cSrcweir throws CannotRegisterImplementationException, 410*cdf0e10cSrcweir com.sun.star.uno.RuntimeException 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir locationUrl = expand_url( locationUrl ); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir boolean success = false; 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir try { 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir Class clazz = RegistrationClassFinder.find(locationUrl); 419*cdf0e10cSrcweir if (null == clazz) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir throw new CannotRegisterImplementationException( 422*cdf0e10cSrcweir "Cannot determine registration class!" ); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir Class[] paramTypes = { XRegistryKey.class }; 426*cdf0e10cSrcweir Object[] params = { regKey }; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir Method method = clazz.getMethod("__writeRegistryServiceInfo", paramTypes); 429*cdf0e10cSrcweir Object oRet = method.invoke(clazz, params); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir if ( (oRet != null) && (oRet instanceof Boolean) ) 432*cdf0e10cSrcweir success = ((Boolean) oRet).booleanValue(); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir catch (Exception e) { 435*cdf0e10cSrcweir throw new CannotRegisterImplementationException( e.getMessage()); 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir return success; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir /** 442*cdf0e10cSrcweir * Supplies the factory for the <code>JavaLoader</code> 443*cdf0e10cSrcweir * <p> 444*cdf0e10cSrcweir * @return the factory for the <code>JavaLoader</code> 445*cdf0e10cSrcweir * @param implName the name of the desired component 446*cdf0e10cSrcweir * @param multiFactory the <code>ServiceManager</code> is delivered to the factory 447*cdf0e10cSrcweir * @param regKey not used - can be null 448*cdf0e10cSrcweir */ 449*cdf0e10cSrcweir public static XSingleServiceFactory getServiceFactory( String implName, 450*cdf0e10cSrcweir XMultiServiceFactory multiFactory, 451*cdf0e10cSrcweir XRegistryKey regKey) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir if ( implName.equals(JavaLoader.class.getName()) ) 454*cdf0e10cSrcweir return new JavaLoaderFactory( multiFactory ); 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir return null; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir /** 460*cdf0e10cSrcweir * Registers the <code>JavaLoader</code> at the registry. 461*cdf0e10cSrcweir * <p> 462*cdf0e10cSrcweir * @return true if registration succseeded - otherwise false 463*cdf0e10cSrcweir * @param regKey root key under which the <code>JavaLoader</code> should be regidstered 464*cdf0e10cSrcweir */ 465*cdf0e10cSrcweir public static boolean writeRegistryServiceInfo(XRegistryKey regKey) { 466*cdf0e10cSrcweir boolean result = false; 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir try { 469*cdf0e10cSrcweir XRegistryKey newKey = regKey.createKey("/" + JavaLoader.class.getName() + "/UNO/SERVICE"); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir for (int i=0; i<supportedServices.length; i++) 472*cdf0e10cSrcweir newKey.createKey(supportedServices[i]); 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir result = true; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir catch (Exception ex) { 477*cdf0e10cSrcweir if (DEBUG) System.err.println(">>>JavaLoader.writeRegistryServiceInfo " + ex); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir return result; 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484