KickJava   Java API By Example, From Geeks To Geeks.

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


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 context class loader
30  * of the thread that initialized Quartz.
31  *
32  * @see org.quartz.spi.ClassLoadHelper
33  * @see org.quartz.simpl.ThreadContextClassLoadHelper
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 InitThreadContextClassLoadHelper implements ClassLoadHelper {
41
42     
43     /*
44      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45      *
46      * Data members.
47      *
48      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49      */

50
51     private ClassLoader JavaDoc initClassLoader;
52
53     /*
54      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55      *
56      * Interface.
57      *
58      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59      */

60
61     /**
62      * Called to give the ClassLoadHelper a chance to initialize itself,
63      * including the oportunity to "steal" the class loader off of the calling
64      * thread, which is the thread that is initializing Quartz.
65      */

66     public void initialize() {
67         initClassLoader = Thread.currentThread().getContextClassLoader();
68     }
69
70     /**
71      * Return the class with the given name.
72      */

73     public Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
74         return initClassLoader.loadClass(name);
75     }
76
77     /**
78      * Finds a resource with a given name. This method returns null if no
79      * resource with this name is found.
80      * @param name name of the desired resource
81      * @return a java.net.URL object
82      */

83     public URL JavaDoc getResource(String JavaDoc name) {
84         return initClassLoader.getResource(name);
85     }
86
87     /**
88      * Finds a resource with a given name. This method returns null if no
89      * resource with this name is found.
90      * @param name name of the desired resource
91      * @return a java.io.InputStream object
92      */

93     public InputStream JavaDoc getResourceAsStream(String JavaDoc name) {
94         return initClassLoader.getResourceAsStream(name);
95     }
96 }
97
Popular Tags