diff options
Diffstat (limited to 'jurt/com/sun/star/comp/loader/JavaLoader.java')
-rw-r--r-- | jurt/com/sun/star/comp/loader/JavaLoader.java | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/jurt/com/sun/star/comp/loader/JavaLoader.java b/jurt/com/sun/star/comp/loader/JavaLoader.java index 47723b208497..2fec17bfe6d4 100644 --- a/jurt/com/sun/star/comp/loader/JavaLoader.java +++ b/jurt/com/sun/star/comp/loader/JavaLoader.java @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -62,30 +62,30 @@ import com.sun.star.uno.AnyConverter; * service. Therefor the <code>JavaLoader</code> activates external UNO components which are implemented in Java. * The loader is used by the <code>ServiceManger</code>. * <p> - * @version $Revision: 1.16 $ $ $Date: 2008-04-11 11:10:31 $ - * @author Markus Herzog + * @version $Revision: 1.16 $ $ $Date: 2008-04-11 11:10:31 $ + * @author Markus Herzog * @see com.sun.star.loader.XImplementationLoader * @see com.sun.star.loader.Java * @see com.sun.star.comp.servicemanager.ServiceManager - * @see com.sun.star.lang.ServiceManager + * @see com.sun.star.lang.ServiceManager * @since UDK1.0 - */ -public class JavaLoader implements XImplementationLoader, + */ +public class JavaLoader implements XImplementationLoader, XServiceInfo, XInitialization { private static final boolean DEBUG = false; - + private static final void DEBUG(String dbg) { if (DEBUG) System.err.println( dbg ); } - + private static String[] supportedServices = { "com.sun.star.loader.Java" }; - + protected XMultiServiceFactory multiServiceFactory = null; - + private XMacroExpander m_xMacroExpander = null; private static final String EXPAND_PROTOCOL_PREFIX = "vnd.sun.star.expand:"; @@ -146,51 +146,51 @@ public class JavaLoader implements XImplementationLoader, } return url; } - + /** default constructor */ - + /** * Creates a new instance of the <code>JavaLoader</code> class. * <p> - * @return new instance + * @return new instance */ public JavaLoader() {} - + /** * Creates a new <code>JavaLoader</code> object. The specified <code>com.sun.star.lang.XMultiServiceFactory</code> * is the <code>ServiceManager</code> service which can be deliviert to all components the <code>JavaLoader</code> is - * loading. + * loading. * To set the <code>MultiServiceFactory</code> you can use the <code>com.sun.star.lang.XInitialization</code> interface, either. * <p> - * @return new instance - * @param factory the <code>ServiceManager</code> - * @see com.sun.star.lang.ServiceManager - * @see com.sun.star.lang.ServiceManager - * @see com.sun.star.lang.XInitialization + * @return new instance + * @param factory the <code>ServiceManager</code> + * @see com.sun.star.lang.ServiceManager + * @see com.sun.star.lang.ServiceManager + * @see com.sun.star.lang.XInitialization */ public JavaLoader(XMultiServiceFactory factory) { multiServiceFactory = factory; } /** - * Unlike the original intention, the method could be called every time a new + * Unlike the original intention, the method could be called every time a new * <code>com.sun.star.lang.XMultiServiceFactory</code> should be set at the loader. * <p> - * @param args - the first parameter (args[0]) specifices the <code>ServiceManager</code> - * @see com.sun.star.lang.XInitialization - * @see com.sun.star.lang.ServiceManager + * @param args - the first parameter (args[0]) specifices the <code>ServiceManager</code> + * @see com.sun.star.lang.XInitialization + * @see com.sun.star.lang.ServiceManager */ - public void initialize( java.lang.Object[] args ) - throws com.sun.star.uno.Exception, + public void initialize( java.lang.Object[] args ) + throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException - { + { if (args.length == 0) throw new com.sun.star.lang.IllegalArgumentException("No arguments specified"); - + try { multiServiceFactory = (XMultiServiceFactory) AnyConverter.toObject( new Type(XMultiServiceFactory.class), args[0]); - } + } catch (ClassCastException castEx) { throw new com.sun.star.lang.IllegalArgumentException( "The argument must be an instance of XMultiServiceFactory"); @@ -201,23 +201,23 @@ public class JavaLoader implements XImplementationLoader, * Supplies the implementation name of the component. * <p> * @return the implementation name - here the class name - * @see com.sun.star.lang.XServiceInfo + * @see com.sun.star.lang.XServiceInfo */ - public String getImplementationName() - throws com.sun.star.uno.RuntimeException + public String getImplementationName() + throws com.sun.star.uno.RuntimeException { return getClass().getName(); } - + /** * Verifies if a given service is supported by the component. * <p> - * @return true,if service is suported - otherwise false - * @param serviceName the name of the service that should be checked - * @see com.sun.star.lang.XServiceInfo + * @return true,if service is suported - otherwise false + * @param serviceName the name of the service that should be checked + * @see com.sun.star.lang.XServiceInfo */ - public boolean supportsService(String serviceName) - throws com.sun.star.uno.RuntimeException + public boolean supportsService(String serviceName) + throws com.sun.star.uno.RuntimeException { for ( int i = 0; i < supportedServices.length; i++ ) { if ( supportedServices[i].equals(serviceName) ) @@ -225,50 +225,50 @@ public class JavaLoader implements XImplementationLoader, } return false; } - + /** * Supplies a list of all service names supported by the component * <p> - * @return a String array with all supported services - * @see com.sun.star.lang.XServiceInfo + * @return a String array with all supported services + * @see com.sun.star.lang.XServiceInfo */ - public String[] getSupportedServiceNames() - throws com.sun.star.uno.RuntimeException + public String[] getSupportedServiceNames() + throws com.sun.star.uno.RuntimeException { return supportedServices; } - + /** * Provides a components factory. - * The <code>JavaLoader</code> tries to load the class first. If a loacation URL is given the + * The <code>JavaLoader</code> tries to load the class first. If a loacation URL is given the * RegistrationClassFinder is used to load the class. Otherwise the class is loaded thru the Class.forName * method. - * To get the factory the inspects the class for the optional static member functions __getServiceFactory resp. + * To get the factory the inspects the class for the optional static member functions __getServiceFactory resp. * getServiceFactory (DEPRECATED). * If the function can not be found a default factory @see ComponentFactoryWrapper will be created. * <p> - * @return the factory for the component (@see com.sun.star.lang.XSingleServiceFactory) - * @param implementationName the implementation (class) name of the component - * @param implementationLoaderUrl the URL of the implementation loader. Not used. - * @param locationUrl points to an archive (JAR file) which contains a component - * @param xKey - * @see com.sun.star.lang.XImplementationLoader - * @see com.sun.star.com.loader.RegistrationClassFinder + * @return the factory for the component (@see com.sun.star.lang.XSingleServiceFactory) + * @param implementationName the implementation (class) name of the component + * @param implementationLoaderUrl the URL of the implementation loader. Not used. + * @param locationUrl points to an archive (JAR file) which contains a component + * @param xKey + * @see com.sun.star.lang.XImplementationLoader + * @see com.sun.star.com.loader.RegistrationClassFinder */ - public java.lang.Object activate( String implementationName, - String implementationLoaderUrl, - String locationUrl, - XRegistryKey xKey ) - throws CannotActivateFactoryException, - com.sun.star.uno.RuntimeException + public java.lang.Object activate( String implementationName, + String implementationLoaderUrl, + String locationUrl, + XRegistryKey xKey ) + throws CannotActivateFactoryException, + com.sun.star.uno.RuntimeException { locationUrl = expand_url( locationUrl ); - + Object returnObject = null; Class clazz = null; - + DEBUG("try to get factory for " + implementationName); - + // first we must get the class of the implementation // 1. If a location URL is given it is assumed that this points to a JAR file. // The components class name is stored in the manifest file. @@ -283,7 +283,7 @@ public class JavaLoader implements XImplementationLoader, else { // 2. clazz = Class.forName( implementationName ); - } + } } catch (java.net.MalformedURLException e) { CannotActivateFactoryException cae = new CannotActivateFactoryException( @@ -312,10 +312,10 @@ public class JavaLoader implements XImplementationLoader, cae.fillInStackTrace(); throw cae; } - - Class[] paramTypes = {String.class, XMultiServiceFactory.class, XRegistryKey.class}; + + Class[] paramTypes = {String.class, XMultiServiceFactory.class, XRegistryKey.class}; Object[] params = { implementationName, multiServiceFactory, xKey }; - + // try to get factory from implemetation class // latest style: use the public static method __getComponentFactory // - new style: use the public static method __getServiceFactory @@ -327,23 +327,23 @@ public class JavaLoader implements XImplementationLoader, compfac_method = clazz.getMethod( "__getComponentFactory", new Class [] { String.class } ); } - catch ( NoSuchMethodException noSuchMethodEx) {} + catch ( NoSuchMethodException noSuchMethodEx) {} catch ( SecurityException secEx) {} - + Method method = null; if (null == compfac_method) { try { method = clazz.getMethod("__getServiceFactory", paramTypes); - } + } catch ( NoSuchMethodException noSuchMethodEx) { method = null; - } + } catch ( SecurityException secEx) { method = null; } } - + try { if (null != compfac_method) { @@ -360,35 +360,35 @@ public class JavaLoader implements XImplementationLoader, if ( method == null ) { method = clazz.getMethod("getServiceFactory", paramTypes); } - + Object oRet = method.invoke(clazz, params); - + if ( (oRet != null) && (oRet instanceof XSingleServiceFactory) ) { - returnObject = (XSingleServiceFactory) oRet; + returnObject = (XSingleServiceFactory) oRet; } } } catch ( NoSuchMethodException e) { - throw new CannotActivateFactoryException("Can not activate the factory for " + throw new CannotActivateFactoryException("Can not activate the factory for " + implementationName + " because " + e.toString() ); - } + } catch ( SecurityException e) { - throw new CannotActivateFactoryException("Can not activate the factory for " + throw new CannotActivateFactoryException("Can not activate the factory for " + implementationName + " because " + e.toString() ); } catch ( IllegalAccessException e ) { - throw new CannotActivateFactoryException("Can not activate the factory for " + throw new CannotActivateFactoryException("Can not activate the factory for " + implementationName + " because " + e.toString() ); } catch ( IllegalArgumentException e ) { - throw new CannotActivateFactoryException("Can not activate the factory for " + throw new CannotActivateFactoryException("Can not activate the factory for " + implementationName + " because " + e.toString() ); } catch ( InvocationTargetException e ) { - throw new CannotActivateFactoryException("Can not activate the factory for " + throw new CannotActivateFactoryException("Can not activate the factory for " + implementationName + " because " + e.getTargetException().toString() ); } - + return returnObject; } @@ -397,24 +397,24 @@ public class JavaLoader implements XImplementationLoader, * methods __writeRegistryServiceInfo, writeRegistryServiceInfo (DEPRECATED), the call is delegated to that * method. Otherwise a default registration will be accomplished. * <p> - * @return true if registration is successfully - otherwise false - * @param regKey the root key under that the component should be registred. - * @param implementationLoaderUrl specifies the loader, the component is loaded by. - * @param locationUrl points to an archive (JAR file) which contains a component - * @see ComponentFactoryWrapper + * @return true if registration is successfully - otherwise false + * @param regKey the root key under that the component should be registred. + * @param implementationLoaderUrl specifies the loader, the component is loaded by. + * @param locationUrl points to an archive (JAR file) which contains a component + * @see ComponentFactoryWrapper */ - public boolean writeRegistryInfo( XRegistryKey regKey, - String implementationLoaderUrl, + public boolean writeRegistryInfo( XRegistryKey regKey, + String implementationLoaderUrl, String locationUrl ) - throws CannotRegisterImplementationException, + throws CannotRegisterImplementationException, com.sun.star.uno.RuntimeException { locationUrl = expand_url( locationUrl ); - - boolean success = false; - + + boolean success = false; + try { - + Class clazz = RegistrationClassFinder.find(locationUrl); if (null == clazz) { @@ -426,57 +426,57 @@ public class JavaLoader implements XImplementationLoader, Object[] params = { regKey }; Method method = clazz.getMethod("__writeRegistryServiceInfo", paramTypes); - Object oRet = method.invoke(clazz, params); + Object oRet = method.invoke(clazz, params); if ( (oRet != null) && (oRet instanceof Boolean) ) success = ((Boolean) oRet).booleanValue(); - } + } catch (Exception e) { throw new CannotRegisterImplementationException( e.getMessage()); } - + return success; } - + /** * Supplies the factory for the <code>JavaLoader</code> * <p> - * @return the factory for the <code>JavaLoader</code> - * @param implName the name of the desired component - * @param multiFactory the <code>ServiceManager</code> is delivered to the factory - * @param regKey not used - can be null + * @return the factory for the <code>JavaLoader</code> + * @param implName the name of the desired component + * @param multiFactory the <code>ServiceManager</code> is delivered to the factory + * @param regKey not used - can be null */ - public static XSingleServiceFactory getServiceFactory( String implName, - XMultiServiceFactory multiFactory, + public static XSingleServiceFactory getServiceFactory( String implName, + XMultiServiceFactory multiFactory, XRegistryKey regKey) - { + { if ( implName.equals(JavaLoader.class.getName()) ) return new JavaLoaderFactory( multiFactory ); - + return null; } - + /** * Registers the <code>JavaLoader</code> at the registry. * <p> * @return true if registration succseeded - otherwise false - * @param regKey root key under which the <code>JavaLoader</code> should be regidstered + * @param regKey root key under which the <code>JavaLoader</code> should be regidstered */ public static boolean writeRegistryServiceInfo(XRegistryKey regKey) { boolean result = false; - + try { XRegistryKey newKey = regKey.createKey("/" + JavaLoader.class.getName() + "/UNO/SERVICE"); - + for (int i=0; i<supportedServices.length; i++) newKey.createKey(supportedServices[i]); - + result = true; } catch (Exception ex) { if (DEBUG) System.err.println(">>>JavaLoader.writeRegistryServiceInfo " + ex); } - + return result; } } |