KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > container > ClassLoaderContainer


1 /*
2  * $Id: ClassLoaderContainer.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.base.container;
26
27 import org.ofbiz.base.util.CachedClassLoader;
28 import org.ofbiz.base.util.Debug;
29 import org.ofbiz.base.start.Classpath;
30
31 import java.net.URL JavaDoc;
32
33 /**
34  * ClassLoader Container; Created a CachedClassLoader for use by all following containers
35  *
36  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
37  * @version $Rev: 5462 $
38  * @since 3.0
39  */

40 public class ClassLoaderContainer implements Container {
41
42     public static final String JavaDoc module = ClassLoaderContainer.class.getName();
43     protected static CachedClassLoader cl = null;
44
45     /**
46      * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)
47      */

48     public void init(String JavaDoc[] args, String JavaDoc configFile) throws ContainerException {
49         ClassLoader JavaDoc parent = Thread.currentThread().getContextClassLoader();
50         if (parent == null) {
51             parent = Classpath.class.getClassLoader();
52         }
53         if (parent == null) {
54             parent = ClassLoader.getSystemClassLoader();
55         }
56
57         cl = new CachedClassLoader(new URL JavaDoc[0], parent);
58         Thread.currentThread().setContextClassLoader(cl);
59         Debug.logInfo("CachedClassLoader created", module);
60     }
61
62     /**
63      * @see org.ofbiz.base.container.Container#start()
64      */

65     public boolean start() throws ContainerException {
66         return true;
67     }
68
69     /**
70      * @see org.ofbiz.base.container.Container#stop()
71      */

72     public void stop() throws ContainerException {
73     }
74
75     public static ClassLoader JavaDoc getClassLoader() {
76         if (cl != null) {
77             return cl;
78         } else {
79             return ClassLoader.getSystemClassLoader();
80         }
81     }
82 }
83
Popular Tags