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 ************************************************************************/
30 import java
.lang
.reflect
.Constructor
;
33 * @deprecated: moved to util package.
35 public class DynamicClassLoader
{
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
44 public static Class
forName(String className
)
45 throws ClassNotFoundException
{
47 return Class
.forName(className
) ;
50 public Object
getInstance(String className
)
51 throws IllegalArgumentException
{
53 Class cls
= DynamicClassLoader
.forName(className
);
54 return cls
.newInstance();
55 } catch ( ClassNotFoundException e
) {
56 throw new IllegalArgumentException("Couldn't find " + className
58 } catch ( IllegalAccessException e
) {
59 throw new IllegalArgumentException("Couldn't access " + className
61 } catch ( InstantiationException e
) {
62 throw new IllegalArgumentException("Couldn't instantiate " +
67 public Object
getInstance(String className
, Object
[] ctorArgs
)
68 throws IllegalArgumentException
{
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
80 } catch ( IllegalAccessException e
) {
81 throw new IllegalArgumentException("Couldn't access " + className
83 } catch ( NoSuchMethodException e
) {
84 throw new IllegalArgumentException("Couldn't find constructor for " + className
86 } catch ( java
.lang
.reflect
.InvocationTargetException e
) {
87 throw new IllegalArgumentException("Couldn't invoke " +
89 } catch ( InstantiationException e
) {
90 throw new IllegalArgumentException("Couldn't instantiate " +