KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > simpl > ThreadContextClassLoadHelper


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.simpl;
22
23 import org.quartz.spi.ClassLoadHelper;
24
25 import java.net.URL JavaDoc;
26 import java.io.InputStream JavaDoc;
27
28 /**
29  * A <code>ClassLoadHelper</code> that uses either the current thread's
30  * context class loader (<code>Thread.currentThread().getContextClassLoader().loadClass( .. )</code>).
31  *
32  * @see org.quartz.spi.ClassLoadHelper
33  * @see org.quartz.simpl.InitThreadContextClassLoadHelper
34  * @see org.quartz.simpl.SimpleClassLoadHelper
35  * @see org.quartz.simpl.CascadingClassLoadHelper
36  * @see org.quartz.simpl.LoadingLoaderClassLoadHelper
37  *
38  * @author jhouse
39  */

40 public class ThreadContextClassLoadHelper implements ClassLoadHelper {
41
42     /*
43      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44      *
45      * Interface.
46      *
47      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48      */

49
50     /**
51      * Called to give the ClassLoadHelper a chance to initialize itself,
52      * including the oportunity to "steal" the class loader off of the calling
53      * thread, which is the thread that is initializing Quartz.
54      */

55     public void initialize() {
56     }
57
58     /**
59      * Return the class with the given name.
60      */

61     public Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
62         return getClassLoader().loadClass(name);
63     }
64
65     /**
66      * Finds a resource with a given name. This method returns null if no
67      * resource with this name is found.
68      * @param name name of the desired resource
69      * @return a java.net.URL object
70      */

71     public URL JavaDoc getResource(String JavaDoc name) {
72         return getClassLoader().getResource(name);
73     }
74
75     /**
76      * Finds a resource with a given name. This method returns null if no
77      * resource with this name is found.
78      * @param name name of the desired resource
79      * @return a java.io.InputStream object
80      */

81     public InputStream JavaDoc getResourceAsStream(String JavaDoc name) {
82         return getClassLoader().getResourceAsStream(name);
83     }
84
85
86     private ClassLoader JavaDoc getClassLoader() {
87         return Thread.currentThread().getContextClassLoader();
88     }
89 }
90
Popular Tags