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.vfs;
030:
031: import com.caucho.loader.EnvironmentLocal;
032:
033: import java.util.Map;
034:
035: /**
036: * ConfigPath implements remote configuration scheme.
037: */
038: public class ConfigPath extends Path {
039: private static final EnvironmentLocal<RemotePwd> _remotePath = new EnvironmentLocal<RemotePwd>();
040:
041: /**
042: * Creates the path (for the scheme)
043: */
044: ConfigPath() {
045: super (null);
046: }
047:
048: /**
049: * Sets the remote.
050: */
051: public static void setRemote(Path remotePath) {
052: _remotePath.set(new RemotePwd(remotePath, Vfs.lookup()));
053: }
054:
055: /**
056: * Path-specific lookup. Path implementations will override this.
057: *
058: * @param userPath the user's lookup() path.
059: * @param newAttributes the attributes for the new path.
060: * @param newPath the lookup() path
061: * @param offset offset into newPath to start lookup.
062: *
063: * @return the found path
064: */
065: protected Path schemeWalk(String userPath,
066: Map<String, Object> newAttributes, String newPath,
067: int offset) {
068: throw new UnsupportedOperationException();
069: /*
070: Path path = Vfs.lookup();
071:
072: path = path.schemeWalk(userPath, newAttributes, newPath, offset);
073:
074: RemotePwd remotePwd = _remotePath.get();
075:
076: if (remotePwd == null)
077: return path;
078:
079: Path configPwd = remotePwd.getPwd();
080: Path remotePath = remotePwd.getRemote();
081:
082: String pathName = path.getFullPath();
083: String configName = configPwd.getFullPath();
084:
085: if (pathName.startsWith(configName))
086: pathName = pathName.substring(configName.length());
087:
088: return remotePath.schemeWalk(userPath, newAttributes, pathName, 0);
089: */
090: }
091:
092: /**
093: * Returns the scheme.
094: */
095: public String getScheme() {
096: Path path = Vfs.lookup();
097:
098: return path.getScheme();
099: }
100:
101: /**
102: * Returns the path.
103: */
104: public String getPath() {
105: Path path = Vfs.lookup();
106:
107: return path.getPath();
108: }
109:
110: static class RemotePwd {
111: Path _remote;
112: Path _pwd;
113:
114: RemotePwd(Path remote, Path pwd) {
115: _remote = remote;
116: _pwd = pwd;
117: }
118:
119: Path getRemote() {
120: return _remote;
121: }
122:
123: Path getPwd() {
124: return _pwd;
125: }
126: }
127: }
|