001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.loader;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.loader.enhancer.EnhancerManager;
034: import com.caucho.util.L10N;
035: import com.caucho.vfs.Path;
036:
037: import javax.annotation.PostConstruct;
038: import java.util.ArrayList;
039:
040: /**
041: * Class for configuration.
042: */
043: public class ClassLoaderConfig {
044: private final static L10N L = new L10N(ClassLoaderConfig.class);
045:
046: private EnvironmentClassLoader _classLoader;
047: private EnvironmentBean _owner;
048:
049: private Path _source;
050: private boolean _servletHack;
051:
052: private int _index;
053:
054: private ArrayList<String> _priorityPackages;
055:
056: public ClassLoaderConfig() throws ConfigException {
057: Thread thread = Thread.currentThread();
058:
059: ClassLoader loader = thread.getContextClassLoader();
060:
061: if (!(loader instanceof EnvironmentClassLoader)) {
062: throw new ConfigException(
063: L
064: .l("<class-loader> requires an EnvironmentClassLoader."));
065: }
066:
067: _classLoader = (EnvironmentClassLoader) loader;
068:
069: /*
070: _owner = _classLoader.getOwner();
071:
072: if (_owner == null)
073: throw new ConfigException(L.l("<class-loader> requires an environment with an EnvironmentBean owner."));
074: */
075: }
076:
077: /**
078: * Sets the servlet classloader hack.
079: */
080: public void setServletHack(boolean hack) {
081: _classLoader.setServletHack(hack);
082: }
083:
084: /**
085: * Adds a simple class loader.
086: */
087: public void addSimpleLoader(SimpleLoader loader) {
088: _classLoader.addLoader(loader, _index++);
089: }
090:
091: /**
092: * Adds a directory class loader.
093: */
094: public void addLibraryLoader(LibraryLoader loader) {
095: _classLoader.addLoader(loader, _index++);
096: }
097:
098: /**
099: * Adds a compiling class loader.
100: */
101: public void addCompilingLoader(CompilingLoader loader) {
102: _classLoader.addLoader(loader, _index++);
103: }
104:
105: /**
106: * Adds a tree loader.
107: */
108: public void addTreeLoader(TreeLoader loader) {
109: _classLoader.addLoader(loader, _index++);
110: }
111:
112: /**
113: * Adds an enhancing loader.
114: */
115: public EnhancerManager createEnhancer() throws ConfigException {
116: return EnhancerManager.create();
117: }
118:
119: /**
120: * Creates the aop.
121: */
122: /*
123: public AopClassEnhancer createAop()
124: throws ConfigException
125: {
126: return AopClassEnhancer.create();
127: }
128: */
129:
130: /**
131: * Add a package for which this class loader will
132: * take precendence over the parent. Any class that
133: * has a qualified name that starts with the passed value
134: * will be loaded from this classloader instead of the
135: * parent classloader.
136: */
137: public void addPriorityPackage(String priorityPackage) {
138: _classLoader.addPriorityPackage(priorityPackage);
139: }
140:
141: /**
142: * init
143: */
144: @PostConstruct
145: public void init() throws ConfigException {
146: _classLoader.init();
147:
148: _classLoader.validate();
149: }
150:
151: public String toString() {
152: return "ClassLoaderConfig[]";
153: }
154: }
|