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.lib.unoloader; 25 26 import java.io.IOException; 27 import java.lang.reflect.InvocationTargetException; 28 import java.net.MalformedURLException; 29 import java.net.URL; 30 import java.security.AccessController; 31 import java.security.PrivilegedActionException; 32 import java.security.PrivilegedExceptionAction; 33 34 /** 35 * A helper class for executing UNO JARs. 36 * 37 * <p><em>This class is not yet stable.</em></p> 38 * 39 * @since UDK 3.2.0 40 */ 41 public final class UnoLoader { 42 /** 43 * Executes a UNO JAR. 44 * 45 * @param base a base URL relative to which the URE JARs 46 * (<code>jurt.jar</code>, <code>ridl.jar</code>, etc.) can be found; must 47 * not be <code>null</code>. 48 * 49 * @param jar the URL of a UNO JAR that specifies a Main-Class; must not be 50 * <code>null</code>. 51 * 52 * @param arguments any arguments passed to the <code>main</code> method of 53 * the specified Main-Class of the given JAR <code>jar</code>; must not be 54 * <code>null</code>. 55 * 56 * @throws IOException if the given <code>base</code> URL is malformed, or 57 * if there are any problems processing the given JAR <code>jar</code>. 58 * 59 * @throws ClassNotFoundException if the given JAR <code>jar</code> does not 60 * specify a Main-Class, or if the specified Main-Class cannot be found. 61 * 62 * @throws NoSuchMethodException if the specified Main-Class of the given 63 * JAR <code>jar</code> does not have an appropriate <code>main</code> 64 * method. 65 * 66 * @throws InvocationTargetException if an exception occurs while executing 67 * the <code>main</code> method of the specified Main-Class of the given JAR 68 * <code>jar</code>. 69 */ execute(final URL base, URL jar, String[] arguments)70 public static void execute(final URL base, URL jar, String[] arguments) 71 throws IOException, ClassNotFoundException, NoSuchMethodException, 72 InvocationTargetException 73 { 74 UnoClassLoader cl; 75 try { 76 cl = (UnoClassLoader) AccessController.doPrivileged( 77 new PrivilegedExceptionAction() { 78 public Object run() throws MalformedURLException { 79 return new UnoClassLoader( 80 base, null, UnoLoader.class.getClassLoader()); 81 } 82 }); 83 } catch (PrivilegedActionException e) { 84 throw (MalformedURLException) e.getException(); 85 } 86 cl.execute(jar, arguments); 87 } 88 UnoLoader()89 private UnoLoader() {} 90 } 91