KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > plugin > ClassLoaderHelper


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.plugin;
19
20 import java.lang.reflect.Constructor JavaDoc;
21
22 /**
23  * @author fdietz
24  *
25  */

26 public class ClassLoaderHelper {
27
28     /**
29      * @param args
30      * @param actClass
31      * @return @throws
32      * NoSuchMethodException
33      */

34     public static Constructor JavaDoc findConstructor(Object JavaDoc[] args, Class JavaDoc actClass)
35             throws NoSuchMethodException JavaDoc {
36
37         Constructor JavaDoc constructor = null;
38
39         Constructor JavaDoc[] list = actClass.getConstructors();
40
41         for (int i = 0; i < list.length; i++) {
42             Constructor JavaDoc c = list[i];
43
44             Class JavaDoc[] parameterTypes = c.getParameterTypes();
45
46             // this constructor has the correct number
47
// of arguments
48
if (parameterTypes.length == args.length) {
49                 boolean success = true;
50
51                 for (int j = 0; j < parameterTypes.length; j++) {
52                     Class JavaDoc parameter = parameterTypes[j];
53
54                     if (args[j] == null) {
55                         success = true;
56                     } else if (!parameter.isAssignableFrom(args[j].getClass())) {
57                         success = false;
58                     }
59                 }
60
61                 // ok, we found a matching constructor
62
// -> create correct list of arguments
63
if (success) {
64                     constructor = actClass.getConstructor(parameterTypes);
65                 }
66             }
67         }
68         return constructor;
69     }
70 }
Popular Tags