KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > loader > ClassLoaderConfig


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;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.loader.enhancer.EnhancerManager;
34 import com.caucho.make.MakeLoader;
35 import com.caucho.util.L10N;
36 import com.caucho.vfs.Path;
37
38 import javax.annotation.PostConstruct;
39 import java.util.ArrayList JavaDoc;
40
41 /**
42  * Class for configuration.
43  */

44 public class ClassLoaderConfig {
45   private final static L10N L = new L10N(ClassLoaderConfig.class);
46
47   private EnvironmentClassLoader _classLoader;
48   private EnvironmentBean _owner;
49
50   private Path _source;
51   private boolean _servletHack;
52
53   private int _index;
54
55   private ArrayList JavaDoc<String JavaDoc> _priorityPackages;
56
57   public ClassLoaderConfig()
58     throws ConfigException
59   {
60     Thread JavaDoc thread = Thread.currentThread();
61
62     ClassLoader JavaDoc loader = thread.getContextClassLoader();
63
64     if (! (loader instanceof EnvironmentClassLoader))
65       throw new ConfigException(L.l("<class-loader> requires an EnvironmentClassLoader."));
66
67     _classLoader = (EnvironmentClassLoader) loader;
68
69     /*
70     _owner = _classLoader.getOwner();
71
72     if (_owner == null)
73       throw new ConfigException(L.l("<class-loader> requires an environment with an EnvironmentBean owner."));
74     */

75   }
76
77   /**
78    * Sets the servlet classloader hack.
79    */

80   public void setServletHack(boolean hack)
81   {
82     _classLoader.setServletHack(hack);
83   }
84
85   /**
86    * Adds a simple class loader.
87    */

88   public void addSimpleLoader(SimpleLoader loader)
89   {
90     _classLoader.addLoader(loader, _index++);
91   }
92
93   /**
94    * Adds a directory class loader.
95    */

96   public void addLibraryLoader(LibraryLoader loader)
97   {
98     _classLoader.addLoader(loader, _index++);
99   }
100
101   /**
102    * Adds a compiling class loader.
103    */

104   public void addCompilingLoader(CompilingLoader loader)
105   {
106     _classLoader.addLoader(loader, _index++);
107   }
108
109   /**
110    * Adds a tree loader.
111    */

112   public void addTreeLoader(TreeLoader loader)
113   {
114     _classLoader.addLoader(loader, _index++);
115   }
116
117   /**
118    * Adds a make class loader.
119    */

120   public void addMakeLoader(MakeLoader loader)
121   {
122     _classLoader.addLoader(loader, _index++);
123   }
124
125   /**
126    * Adds an enhancing loader.
127    */

128   public EnhancerManager createEnhancer()
129     throws ConfigException
130   {
131     return EnhancerManager.create();
132   }
133
134   /**
135    * Creates the aop.
136    */

137   /*
138   public AopClassEnhancer createAop()
139     throws ConfigException
140   {
141     return AopClassEnhancer.create();
142   }
143   */

144
145   /**
146    * Add a package for which this class loader will
147    * take precendence over the parent. Any class that
148    * has a qualified name that starts with the passed value
149    * will be loaded from this classloader instead of the
150    * parent classloader.
151    */

152   public void addPriorityPackage(String JavaDoc priorityPackage)
153   {
154     _classLoader.addPriorityPackage(priorityPackage);
155   }
156
157   /**
158    * init
159    */

160   @PostConstruct
161   public void init()
162     throws ConfigException
163   {
164     _classLoader.init();
165
166     _classLoader.validate();
167   }
168
169   public String JavaDoc toString()
170   {
171     return "ClassLoaderConfig[]";
172   }
173 }
174
175
176
Popular Tags