update dev300-m58
[ooovba.git] / qadevOOo / runner / lib / DynamicClassLoader.java
blobff2f3a0c419c86ff60d90934cc70dde68892f4d4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DynamicClassLoader.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package lib ;
33 import java.lang.reflect.Constructor;
35 /**
36 * @deprecated: moved to util package.
38 public class DynamicClassLoader {
40 /**
41 * This method returns a class created by it's name
42 * created by call to <code>Class.forName()</code>.<p>
43 * This method must be overloaded if another loading
44 * policy is required for Component and Interface
45 * testing classes.
47 public static Class forName(String className)
48 throws ClassNotFoundException {
50 return Class.forName(className) ;
53 public Object getInstance(String className)
54 throws IllegalArgumentException {
55 try {
56 Class cls = DynamicClassLoader.forName(className);
57 return cls.newInstance();
58 } catch ( ClassNotFoundException e ) {
59 throw new IllegalArgumentException("Couldn't find " + className
60 + " " + e);
61 } catch ( IllegalAccessException e ) {
62 throw new IllegalArgumentException("Couldn't access " + className
63 + " " + e);
64 } catch ( InstantiationException e ) {
65 throw new IllegalArgumentException("Couldn't instantiate " +
66 className + " " + e);
70 public Object getInstance(String className, Object[] ctorArgs)
71 throws IllegalArgumentException {
72 try {
73 Class cls = DynamicClassLoader.forName(className);
74 Class[] ctorType = new Class[ctorArgs.length];
75 for(int i=0; i<ctorType.length; i++) {
76 ctorType[i] = ctorArgs[i].getClass();
78 Constructor ctor = cls.getConstructor(ctorType);
79 return ctor.newInstance(ctorArgs);
80 } catch ( ClassNotFoundException e ) {
81 throw new IllegalArgumentException("Couldn't find " + className
82 + " " + e);
83 } catch ( IllegalAccessException e ) {
84 throw new IllegalArgumentException("Couldn't access " + className
85 + " " + e);
86 } catch ( NoSuchMethodException e ) {
87 throw new IllegalArgumentException("Couldn't find constructor for " + className
88 + " " + e);
89 } catch ( java.lang.reflect.InvocationTargetException e ) {
90 throw new IllegalArgumentException("Couldn't invoke " +
91 className + " " + e);
92 } catch ( InstantiationException e ) {
93 throw new IllegalArgumentException("Couldn't instantiate " +
94 className + " " + e);