KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > loader > enhancer > EnhancingClassLoader


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.loader.enhancer;
31
32 import com.caucho.java.WorkDir;
33 import com.caucho.loader.EnvironmentClassLoader;
34 import com.caucho.util.L10N;
35 import com.caucho.vfs.Path;
36
37 /**
38  * Class loader which checks for changes in class files and automatically
39  * picks up new jars.
40  *
41  * <p>DynamicClassLoaders can be chained creating one virtual class loader.
42  * From the perspective of the JDK, it's all one classloader. Internally,
43  * the class loader chain searches like a classpath.
44  */

45 public class EnhancingClassLoader extends EnvironmentClassLoader {
46   private static final L10N L = new L10N(EnhancingClassLoader.class);
47
48   private Path _workPath;
49
50   /**
51    * Creates a new environment class loader.
52    */

53   public EnhancingClassLoader()
54   {
55     this(Thread.currentThread().getContextClassLoader());
56   }
57
58   /**
59    * Creates a new environment class loader.
60    */

61   public EnhancingClassLoader(ClassLoader JavaDoc parent)
62   {
63     super(parent);
64   }
65
66   /**
67    * Gets the work path.
68    */

69   public Path getWorkPath()
70   {
71     if (_workPath != null)
72       return _workPath;
73     else
74       return WorkDir.getLocalWorkDir(this);
75   }
76
77   /**
78    * Sets the work path.
79    */

80   public void setWorkPath(Path workPath)
81   {
82     _workPath = workPath;
83   }
84
85   /**
86    * Gets the work path.
87    */

88   public final Path getPreWorkPath()
89   {
90     return getWorkPath().lookup("pre-enhance");
91   }
92
93   /**
94    * Gets the work path.
95    */

96   public final Path getPostWorkPath()
97   {
98     return getWorkPath().lookup("post-enhance");
99   }
100
101   /**
102    * Initialize the loader.
103    */

104   public void init()
105   {
106     super.init();
107
108     if (getTransformerList() == null
109     && EnhancerManager.getLocalEnhancer(this) != null) {
110       EnhancerManager.create(this);
111     }
112   }
113
114   public String JavaDoc toString()
115   {
116     if (getId() != null)
117       return "EnhancingClassLoader[" + getId() + "]";
118     else
119       return "EnhancingClassLoader" + getLoaders();
120   }
121 }
122
Popular Tags