|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ClassFactoryClassLoader.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.hivemind.service.impl; | |
16 | ||
17 | import java.util.ArrayList; | |
18 | import java.util.List; | |
19 | ||
20 | /** | |
21 | * ClassLoader used to properly instantiate newly created classes. | |
22 | * | |
23 | * @author Howard Lewis Ship / Essl Christian | |
24 | * @see org.apache.hivemind.service.impl.CtClassSource | |
25 | */ | |
26 | class ClassFactoryClassLoader extends ClassLoader | |
27 | { | |
28 | private List _loaders = new ArrayList(); | |
29 | ||
30 | /** | |
31 | * Adds a delegate class loader to the list of delegate class loaders. | |
32 | */ | |
33 | 145 | public synchronized void addDelegateLoader(ClassLoader loader) |
34 | { | |
35 | 145 | _loaders.add(loader); |
36 | } | |
37 | ||
38 | /** | |
39 | * Searches each of the delegate class loaders for the given class. | |
40 | */ | |
41 | 7 | protected synchronized Class findClass(String name) throws ClassNotFoundException |
42 | { | |
43 | 7 | ClassNotFoundException cnfex = null; |
44 | ||
45 | 7 | try |
46 | { | |
47 | 7 | return super.findClass(name); |
48 | } | |
49 | catch (ClassNotFoundException ex) | |
50 | { | |
51 | 7 | cnfex = ex; |
52 | } | |
53 | ||
54 | 7 | int count = _loaders.size(); |
55 | 7 | for (int i = 0; i < count; i++) |
56 | { | |
57 | 7 | ClassLoader l = (ClassLoader) _loaders.get(i); |
58 | ||
59 | 7 | try |
60 | { | |
61 | 7 | return l.loadClass(name); |
62 | } | |
63 | catch (ClassNotFoundException ex) | |
64 | { | |
65 | // | |
66 | } | |
67 | } | |
68 | ||
69 | // Not found .. through the first exception | |
70 | ||
71 | 7 | throw cnfex; |
72 | } | |
73 | ||
74 | } |
|