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.log.Log;
033: import com.caucho.vfs.Dependency;
034: import com.caucho.vfs.Path;
035:
036: import java.net.URL;
037: import java.util.HashMap;
038: import java.util.Vector;
039: import java.util.logging.Logger;
040:
041: /**
042: * Class loader which loads specific paths.
043: */
044: public class PathLoader extends Loader implements Dependency {
045: private static final Logger log = Log.open(PathLoader.class);
046:
047: private HashMap<String, Path> _pathMap = new HashMap<String, Path>();
048:
049: /**
050: * Creates a new directory loader.
051: */
052: public PathLoader() {
053: }
054:
055: /**
056: * Initialize
057: */
058: public void init() {
059: }
060:
061: /**
062: * Returns the modified
063: */
064: public boolean isModified() {
065: return false;
066: }
067:
068: /**
069: * Returns the modified
070: */
071: public boolean logModified(Logger log) {
072: return false;
073: }
074:
075: /**
076: * Adds a new path.
077: */
078: public void put(String name, Path path) {
079: _pathMap.put(name, path);
080: }
081:
082: /**
083: * Returns the class entry.
084: *
085: * @param name name of the class
086: */
087: @Override
088: protected ClassEntry getClassEntry(String name, String pathName)
089: throws ClassNotFoundException {
090: Path path = _pathMap.get(name);
091:
092: if (path != null && path.canRead() && path.getLength() > 0) {
093: ClassEntry entry = new ClassEntry(getLoader(), name, path,
094: path, getCodeSource(path));
095:
096: /*
097: int p = name.lastIndexOf('.');
098: String pkg;
099: if (p > 0)
100: pkg = name.substring(0, p);
101: else
102: pkg = "";
103:
104: ClassPackage classPackage = jarEntry.getPackage(pkg);
105:
106: entry.setClassPackage(classPackage);
107: */
108:
109: return entry;
110: }
111:
112: return null;
113: }
114:
115: /**
116: * Adds resources to the enumeration.
117: */
118: public void getResources(Vector<URL> vector, String name) {
119: }
120:
121: /**
122: * Find a given path somewhere in the classpath
123: *
124: * @param pathName the relative resourceName
125: *
126: * @return the matching path or null
127: */
128: public Path getPath(String pathName) {
129: return null;
130: }
131:
132: public Path getCodePath() {
133: return null;
134: }
135:
136: public String toString() {
137: return "PathLoader[]";
138: }
139: }
|