Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ClassFactoryClassLoader |
|
| 4.0;4 |
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 | package org.apache.tapestry.enhance; |
|
15 | ||
16 | import java.util.ArrayList; |
|
17 | import java.util.List; |
|
18 | ||
19 | /** |
|
20 | * ClassLoader used to properly instantiate newly created classes. |
|
21 | * |
|
22 | * @author Howard Lewis Ship / Essl Christian |
|
23 | * @see org.apache.hivemind.service.impl.CtClassSource |
|
24 | */ |
|
25 | 35 | class ClassFactoryClassLoader extends ClassLoader |
26 | { |
|
27 | 35 | private List _loaders = new ArrayList(); |
28 | ||
29 | /** |
|
30 | * Adds a delegate class loader to the list of delegate class loaders. |
|
31 | */ |
|
32 | public synchronized void addDelegateLoader(ClassLoader loader) |
|
33 | { |
|
34 | 35 | _loaders.add(loader); |
35 | 35 | } |
36 | ||
37 | /** |
|
38 | * Searches each of the delegate class loaders for the given class. |
|
39 | */ |
|
40 | protected synchronized Class findClass(String name) throws ClassNotFoundException |
|
41 | { |
|
42 | 94 | ClassNotFoundException cnfex = null; |
43 | ||
44 | try |
|
45 | { |
|
46 | 94 | return super.findClass(name); |
47 | } |
|
48 | 94 | catch (ClassNotFoundException ex) |
49 | { |
|
50 | 94 | cnfex = ex; |
51 | } |
|
52 | ||
53 | 94 | int count = _loaders.size(); |
54 | 94 | for (int i = 0; i < count; i++) |
55 | { |
|
56 | 94 | ClassLoader l = (ClassLoader) _loaders.get(i); |
57 | ||
58 | try |
|
59 | { |
|
60 | 94 | return l.loadClass(name); |
61 | } |
|
62 | 0 | catch (ClassNotFoundException ex) |
63 | { |
|
64 | // |
|
65 | } |
|
66 | } |
|
67 | ||
68 | // Not found .. throw the first exception |
|
69 | ||
70 | 0 | throw cnfex; |
71 | } |
|
72 | } |