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.vfs;
031:
032: import java.util.HashMap;
033:
034: /**
035: * The top-level filesystem schemes are collected into a single map.
036: *
037: * <p>The default scheme has a number of standard filesystems, file:, mailto:,
038: * jndi:, http:.
039: *
040: * <p>Applications can add schemes in the configuration file. When first
041: * accessed, the SchemeMap will look in the Registry to match the scheme.
042: * If the new scheme exists, it will instantiate a single root instance and
043: * use that for the remainder of the application.
044: * <code><pre>
045: * <caucho.com>
046: * <vfs scheme="foo" class-name="test.vfs.FooPath"/>
047: * </caucho.com>
048: * </pre></code>
049: */
050: public class SchemeMap {
051: // Constant null scheme map for protected filesystems.
052: public static final SchemeMap NULL_SCHEME_MAP = new SchemeMap();
053:
054: private final HashMap<String, Path> _schemeMap = new HashMap<String, Path>();
055:
056: /**
057: * Create an empty SchemeMap.
058: */
059: public SchemeMap() {
060: }
061:
062: /**
063: * Create an empty SchemeMap.
064: */
065: private SchemeMap(HashMap<String, Path> map) {
066: _schemeMap.putAll(map);
067: }
068:
069: /**
070: * The null scheme map is useful for protected filesystems as used
071: * in createRoot(). That way, no dangerous code can get access to
072: * files using, for example, the file: scheme.
073: */
074: static SchemeMap getNullSchemeMap() {
075: return NULL_SCHEME_MAP;
076: }
077:
078: /**
079: * Gets the scheme from the schemeMap.
080: */
081: public Path get(String scheme) {
082: Path path = _schemeMap.get(scheme);
083:
084: if (path != null)
085: return path;
086: else {
087:
088: return new NotFoundPath(scheme + ":");
089: }
090: }
091:
092: /**
093: * Puts a new value in the schemeMap.
094: */
095: public Path put(String scheme, Path path) {
096: return _schemeMap.put(scheme, path);
097: }
098:
099: public SchemeMap copy() {
100: return new SchemeMap(_schemeMap);
101: }
102:
103: /**
104: * Removes value from the schemeMap.
105: */
106: public Path remove(String scheme) {
107: return _schemeMap.remove(scheme);
108: }
109: }
|