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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.loader;
030:
031: import com.caucho.vfs.Path;
032:
033: import javax.annotation.PostConstruct;
034:
035: /**
036: * Class for configuration.
037: */
038: public class ClasspathConfig {
039: private Path _classDir;
040: private Path _source;
041: private boolean _compile = true;
042: private boolean _isLibraryDir = false;
043:
044: /**
045: * Sets the id.
046: */
047: public void setId(Path id) {
048: _classDir = id;
049: }
050:
051: /**
052: * Sets the source.
053: */
054: public void setSource(Path source) {
055: _source = source;
056: }
057:
058: /**
059: * Sets true if compilation is allowed.
060: */
061: public void setCompile(boolean compile) {
062: _compile = compile;
063: }
064:
065: /**
066: * Sets true if it's a jar library direcotyr
067: */
068: public void setLibraryDir(boolean libraryDir) {
069: _isLibraryDir = libraryDir;
070: }
071:
072: /**
073: * Initialize
074: */
075: @PostConstruct
076: public void init() {
077: DynamicClassLoader classLoader;
078: classLoader = (DynamicClassLoader) Thread.currentThread()
079: .getContextClassLoader();
080:
081: Loader loader = null;
082:
083: if (_isLibraryDir)
084: loader = new DirectoryLoader(_classDir);
085: else if (!_compile)
086: loader = new SimpleLoader(_classDir);
087: else if (_classDir.getPath().endsWith(".jar")
088: || _classDir.getPath().endsWith(".zip"))
089: loader = new SimpleLoader(_classDir);
090: else if (_source != null)
091: loader = new CompilingLoader(_classDir, _source, null, null);
092: else
093: loader = new CompilingLoader(_classDir);
094:
095: classLoader.addLoader(loader);
096:
097: classLoader.init();
098: }
099:
100: public String toString() {
101: return "ClasspathConfig[" + _classDir + "]";
102: }
103: }
|