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