KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SlotClass.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: SlotClass.java,v 1.6 2004/05/23 15:23:37 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 public class SlotClass extends LispClass
25 {
26     private LispObject directSlots = NIL;
27     private LispObject effectiveSlots = NIL;
28     private LispObject directDefaultInitargs = NIL;
29     private LispObject effectiveDefaultInitargs = NIL;
30
31     public SlotClass()
32     {
33     }
34
35     public SlotClass(Symbol symbol, LispObject directSuperclasses)
36     {
37         super(symbol, directSuperclasses);
38     }
39
40     public LispObject getParts() throws ConditionThrowable
41     {
42         LispObject result = super.getParts().nreverse();
43         result = result.push(new Cons("DIRECT-SLOTS", directSlots));
44         result = result.push(new Cons("EFFECTIVE-SLOTS", effectiveSlots));
45         result = result.push(new Cons("DIRECT-DEFAULT-INITARGS", directDefaultInitargs));
46         result = result.push(new Cons("EFFECTIVE-DEFAULT-INITARGS", effectiveDefaultInitargs));
47         return result.nreverse();
48     }
49
50     public LispObject typep(LispObject type) throws ConditionThrowable
51     {
52         return super.typep(type);
53     }
54
55     public void setDirectSlots(LispObject directSlots)
56     {
57         this.directSlots = directSlots;
58     }
59
60     public final LispObject getEffectiveSlots()
61     {
62         return effectiveSlots;
63     }
64
65     public void setEffectiveSlots(LispObject slots)
66     {
67         this.effectiveSlots = slots;
68     }
69
70     // ### class-direct-slots
71
private static final Primitive1 CLASS_DIRECT_SLOTS =
72         new Primitive1("class-direct-slots", PACKAGE_SYS, false)
73     {
74         public LispObject execute(LispObject arg)
75             throws ConditionThrowable
76         {
77             if (arg instanceof SlotClass)
78                 return ((SlotClass)arg).directSlots;
79             if (arg instanceof BuiltInClass)
80                 return NIL;
81             return signal(new TypeError(arg, "standard class"));
82         }
83     };
84
85     // ### %set-class-direct-slots
86
private static final Primitive2 _SET_CLASS_DIRECT_SLOTS =
87         new Primitive2("%set-class-direct-slots", PACKAGE_SYS, false)
88     {
89         public LispObject execute(LispObject first, LispObject second)
90             throws ConditionThrowable
91         {
92             if (first instanceof SlotClass) {
93                 ((SlotClass)first).directSlots = second;
94                 return second;
95             }
96             return signal(new TypeError(first, "standard class"));
97         }
98     };
99
100     // ### class-slots
101
private static final Primitive1 CLASS_SLOTS =
102         new Primitive1("class-slots", PACKAGE_SYS, false)
103     {
104         public LispObject execute(LispObject arg)
105             throws ConditionThrowable
106         {
107             if (arg instanceof SlotClass)
108                 return ((SlotClass)arg).effectiveSlots;
109             if (arg instanceof BuiltInClass)
110                 return NIL;
111             return signal(new TypeError(arg, "standard class"));
112         }
113     };
114
115     // ### %set-class-slots
116
private static final Primitive2 _SET_CLASS_SLOTS =
117         new Primitive2("%set-class-slots", PACKAGE_SYS, false)
118     {
119         public LispObject execute(LispObject first, LispObject second)
120             throws ConditionThrowable
121         {
122             if (first instanceof SlotClass) {
123                 ((SlotClass)first).effectiveSlots = second;
124                 return second;
125             }
126             return signal(new TypeError(first, "standard class"));
127         }
128     };
129
130     // ### class-direct-default-initargs
131
private static final Primitive1 CLASS_DIRECT_DEFAULT_INITARGS =
132         new Primitive1("class-direct-default-initargs", PACKAGE_SYS, false)
133     {
134         public LispObject execute(LispObject arg)
135             throws ConditionThrowable
136         {
137             if (arg instanceof SlotClass)
138                 return ((SlotClass)arg).directDefaultInitargs;
139             if (arg instanceof BuiltInClass)
140                 return NIL;
141             return signal(new TypeError(arg, "standard class"));
142         }
143     };
144
145     // ### %set-class-direct-default-initargs
146
private static final Primitive2 _SET_CLASS_DIRECT_DEFAULT_INITARGS =
147         new Primitive2("%set-class-direct-default-initargs", PACKAGE_SYS, false)
148     {
149         public LispObject execute(LispObject first, LispObject second)
150             throws ConditionThrowable
151         {
152             if (first instanceof SlotClass) {
153                 ((SlotClass)first).directDefaultInitargs = second;
154                 return second;
155             }
156             return signal(new TypeError(first, "standard class"));
157         }
158     };
159
160     // ### class-default-initargs
161
private static final Primitive1 CLASS_DEFAULT_INITARGS =
162         new Primitive1("class-default-initargs", PACKAGE_SYS, false)
163     {
164         public LispObject execute(LispObject arg)
165             throws ConditionThrowable
166         {
167             if (arg instanceof SlotClass)
168                 return ((SlotClass)arg).effectiveDefaultInitargs;
169             if (arg instanceof BuiltInClass)
170                 return NIL;
171             return signal(new TypeError(arg, "standard class"));
172         }
173     };
174
175     // ### %set-class-default-initargs
176
private static final Primitive2 _SET_CLASS_DEFAULT_INITARGS =
177         new Primitive2("%set-class-default-initargs", PACKAGE_SYS, false)
178     {
179         public LispObject execute(LispObject first, LispObject second)
180             throws ConditionThrowable
181         {
182             if (first instanceof SlotClass) {
183                 ((SlotClass)first).effectiveDefaultInitargs = second;
184                 return second;
185             }
186             return signal(new TypeError(first, "standard class"));
187         }
188     };
189 }
190
Popular Tags