source: branches/0.22.x/abcl/examples/java-interface/Main.java

Last change on this file was 12307, checked in by ehuelsmann, 15 years ago

Complete "catch (Throwable" review by reviewing ../examples.

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1/*
2 * Main.java
3 *
4 * Copyright (C) 2008 Ville Voutilainen
5 * $Id: Main.java 12307 2009-12-25 21:54:31Z ehuelsmann $
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
22import org.armedbear.lisp.*;
23
24public class Main
25{
26    /**
27     * This example loads a lisp file and gets two function symbols
28     * from it. The functions return implementations of MyInterface.
29     * The example gets two separate implementations and invokes
30     * the functions in the interface for both implementations.
31     */
32    public static void main(String[] argv)
33    {
34  try
35      {
36    Interpreter interpreter = Interpreter.createInstance();
37    interpreter.eval("(load \"interface_implementation.lisp\")");
38    // the function is not in a separate package, thus the
39    // correct package is CL-USER. Symbol names are
40    // upper case. Package needs the prefix, because java
41    // also has a class named Package.
42    org.armedbear.lisp.Package defaultPackage = 
43        Packages.findPackage("CL-USER");
44    Symbol interfacesym = 
45        defaultPackage.findAccessibleSymbol("GET-INTERFACE");
46    Function interfaceFunction = 
47        (Function) interfacesym.getSymbolFunction();
48    LispObject myinterface = interfaceFunction.execute();
49    MyInterface x = 
50        (MyInterface) JavaObject.getObject(myinterface);
51    x.firstFunction();
52    x.secondFunction();
53    Symbol interfacesym2 = 
54        defaultPackage.
55        findAccessibleSymbol("GET-ANOTHER-INTERFACE");
56    Function interfaceFunction2 = 
57        (Function) interfacesym2.getSymbolFunction();
58    LispObject myInterface2 = interfaceFunction2.execute();
59    MyInterface y = 
60        (MyInterface) JavaObject.getObject(myInterface2);
61    y.firstFunction();
62    y.secondFunction();
63      }
64  catch (Throwable t)
65      {
66    System.out.println("exception!");
67    t.printStackTrace();
68      }
69    }
70}
Note: See TracBrowser for help on using the repository browser.