KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > vfs > SchemeMap


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.vfs;
31
32 import java.util.HashMap JavaDoc;
33
34 /**
35  * The top-level filesystem schemes are collected into a single map.
36  *
37  * <p>The default scheme has a number of standard filesystems, file:, mailto:,
38  * jndi:, http:.
39  *
40  * <p>Applications can add schemes in the configuration file. When first
41  * accessed, the SchemeMap will look in the Registry to match the scheme.
42  * If the new scheme exists, it will instantiate a single root instance and
43  * use that for the remainder of the application.
44  * <code><pre>
45  * &lt;caucho.com>
46  * &lt;vfs scheme="foo" class-name="test.vfs.FooPath"/>
47  * &lt;/caucho.com>
48  * </pre></code>
49  */

50 public class SchemeMap {
51   // Constant null scheme map for protected filesystems.
52
public static final SchemeMap NULL_SCHEME_MAP = new SchemeMap();
53   
54   private final HashMap JavaDoc<String JavaDoc,Path> _schemeMap
55     = new HashMap JavaDoc<String JavaDoc,Path>();
56     
57   /**
58    * Create an empty SchemeMap.
59    */

60   public SchemeMap()
61   {
62   }
63     
64   /**
65    * Create an empty SchemeMap.
66    */

67   private SchemeMap(HashMap JavaDoc<String JavaDoc,Path> map)
68   {
69     _schemeMap.putAll(map);
70   }
71
72   /**
73    * The null scheme map is useful for protected filesystems as used
74    * in createRoot(). That way, no dangerous code can get access to
75    * files using, for example, the file: scheme.
76    */

77   static SchemeMap getNullSchemeMap()
78   {
79     return NULL_SCHEME_MAP;
80   }
81
82   /**
83    * Gets the scheme from the schemeMap.
84    */

85   public Path get(String JavaDoc scheme)
86   {
87     Path path = _schemeMap.get(scheme);
88
89     if (path != null)
90       return path;
91     else {
92
93       return new NotFoundPath(scheme + ":");
94     }
95   }
96
97   /**
98    * Puts a new value in the schemeMap.
99    */

100   public Path put(String JavaDoc scheme, Path path)
101   {
102     return _schemeMap.put(scheme, path);
103   }
104
105   public SchemeMap copy()
106   {
107     return new SchemeMap(_schemeMap);
108   }
109
110   /**
111    * Removes value from the schemeMap.
112    */

113   public Path remove(String JavaDoc scheme)
114   {
115     return _schemeMap.remove(scheme);
116   }
117 }
118
Popular Tags