KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > LogicalPathname


1 /*
2  * LogicalPathname.java
3  *
4  * Copyright (C) 2004 Peter Graves
5  * $Id: LogicalPathname.java,v 1.3 2004/02/23 14:24:47 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 import java.util.HashMap JavaDoc;
25
26 public final class LogicalPathname extends Pathname
27 {
28     private static final HashMap JavaDoc map = new HashMap JavaDoc();
29
30     private LogicalPathname()
31     {
32         // "The device component of a logical pathname is always :unspecific;
33
// no other component of a logical pathname can be :unspecific."
34
device = Keyword.UNSPECIFIC;
35     }
36
37     public LispObject typeOf()
38     {
39         return Symbol.LOGICAL_PATHNAME;
40     }
41
42     public LispClass classOf()
43     {
44         return BuiltInClass.LOGICAL_PATHNAME;
45     }
46
47     public LispObject typep(LispObject type) throws ConditionThrowable
48     {
49         if (type == Symbol.LOGICAL_PATHNAME)
50             return T;
51         if (type == BuiltInClass.LOGICAL_PATHNAME)
52             return T;
53         return super.typep(type);
54     }
55
56     // ### %set-logical-pathname-translations
57
// %set-logical-pathname-translations host new-translations => newval
58
private static final Primitive2 _SET_LOGICAL_PATHNAME_TRANSLATIONS =
59         new Primitive2("%set-logical-pathname-translations", PACKAGE_SYS, false,
60                        "host new-translations")
61     {
62         public LispObject execute(LispObject first, LispObject second)
63             throws ConditionThrowable
64         {
65             String JavaDoc host = first.getStringValue().toUpperCase();
66             map.put(host, NIL); // FIXME
67
return NIL;
68         }
69     };
70
71     // ### logical-pathname-translations host => translations
72
private static final Primitive1 LOGICAL_PATHNAME_TRANSLATIONS =
73         new Primitive1("logical-pathname-translations", "host")
74     {
75         public LispObject execute(LispObject arg) throws ConditionThrowable
76         {
77             return NIL;
78         }
79     };
80
81     // ### load-logical-pathname-translations host => just-loaded
82
private static final Primitive1 LOAD_LOGICAL_PATHNAME_TRANSLATIONS =
83         new Primitive1("load-logical-pathname-translations", "host")
84     {
85         public LispObject execute(LispObject arg) throws ConditionThrowable
86         {
87             String JavaDoc host = arg.getStringValue().toUpperCase();
88             if (map.get(host) != null)
89                 return NIL;
90             return signal(new LispError("LOAD-LOGICAL-PATHNAME-TRANSLATIONS is not implemented."));
91         }
92     };
93
94     // ### logical-pathname pathspec => logical-pathname
95
private static final Primitive1 LOGICAL_PATHNAME =
96         new Primitive1("logical-pathname", "pathspec")
97     {
98         public LispObject execute(LispObject arg) throws ConditionThrowable
99         {
100             if (arg instanceof LogicalPathname)
101                 return arg;
102             if (arg instanceof AbstractString) {
103                 String JavaDoc s = arg.getStringValue();
104                 int index = s.indexOf(':');
105                 if (index >= 0) {
106                     String JavaDoc host = s.substring(0, index).toUpperCase();
107                     LogicalPathname p = new LogicalPathname();
108                     p.host = new SimpleString(host);
109                     return p;
110                 }
111                 return NIL;
112             }
113             if (arg instanceof Stream)
114                 return NIL;
115             return signal(new TypeError(String.valueOf(arg) +
116                                         " is not a string, stream, or logical pathname."));
117         }
118     };
119 }
120
Popular Tags