KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > service > impl > ClassFactoryClassLoader


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 JavaDoc;
18 import java.util.List JavaDoc;
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 JavaDoc
27 {
28     private List JavaDoc _loaders = new ArrayList JavaDoc();
29
30     public ClassFactoryClassLoader(ClassLoader JavaDoc parent)
31     {
32         super(parent);
33     }
34
35     /**
36      * Adds a delegate class loader to the list of delegate class loaders.
37      */

38     public synchronized void addDelegateLoader(ClassLoader JavaDoc loader)
39     {
40         _loaders.add(loader);
41     }
42
43     /**
44      * Searches each of the delegate class loaders for the given class.
45      */

46     protected synchronized Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc
47     {
48         int count = _loaders.size();
49         for (int i = 0; i < count; i++)
50         {
51             ClassLoader JavaDoc l = (ClassLoader JavaDoc) _loaders.get(i);
52
53             try
54             {
55                 return l.loadClass(name);
56             }
57             catch (ClassNotFoundException JavaDoc ex)
58             {
59                 //
60
}
61         }
62
63         throw new ClassNotFoundException JavaDoc(name);
64     }}
Popular Tags