KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > JVar


1 /*
2  * JVar.java
3  *
4  * Copyright (C) 2003 Peter Graves
5  * $Id: JVar.java,v 1.3 2003/10/06 13:51:18 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.j;
23
24 import java.util.ArrayList JavaDoc;
25 import org.armedbear.lisp.ConditionThrowable;
26 import org.armedbear.lisp.LispError;
27 import org.armedbear.lisp.LispObject;
28 import org.armedbear.lisp.Symbol;
29
30 public final class JVar extends LispObject
31 {
32     private static final Symbol J_VARIABLE_VALUE =
33         LispAPI.PACKAGE_J_INTERNALS.addInternalSymbol("J-VARIABLE-VALUE");
34
35     private final Property property;
36
37     private JVar(String JavaDoc name, Property property)
38     {
39         this.property = property;
40         Symbol symbol = LispAPI.PACKAGE_J.findAccessibleSymbol(name);
41         if (symbol == null)
42             symbol = LispAPI.PACKAGE_J.addExternalSymbol(name);
43         try {
44             put(symbol, J_VARIABLE_VALUE, this);
45         }
46         catch (Throwable JavaDoc t) {
47             Log.error(t);
48         }
49     }
50
51     public Property getProperty()
52     {
53         return property;
54     }
55
56     public static JVar getJVar(Symbol symbol) throws ConditionThrowable
57     {
58         LispObject obj = get(symbol, J_VARIABLE_VALUE, null);
59         if (obj instanceof JVar)
60             return (JVar) obj;
61         throw new ConditionThrowable(new LispError(String.valueOf(symbol) +
62             " is not defined as an editor variable"));
63     }
64
65     public static synchronized void addVariableForProperty(Property property)
66     {
67         new JVar(property.getLispName(), property);
68     }
69
70     public String JavaDoc toString()
71     {
72         FastStringBuffer sb = new FastStringBuffer("#<J-VARIABLE @ #x");
73         sb.append(Integer.toHexString(hashCode()));
74         sb.append(">");
75         return sb.toString();
76     }
77 }
78
Popular Tags