source: branches/streams/abcl/src/org/armedbear/lisp/scripting/AbclScriptEngineFactory.java

Last change on this file was 13060, checked in by vvoutilainen, 14 years ago

Make the getter for the engine synchronized, as the engine
is nowadays lazy-initialized.

  • Property svn:eol-style set to LF
File size: 3.1 KB
Line 
1/*
2 * AbclScriptEngineFactory.java
3 *
4 * Copyright (C) 2008 Alessio Stalla
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21package org.armedbear.lisp.scripting;
22
23import java.util.ArrayList;
24import java.util.Collections;
25import java.util.List;
26
27import javax.script.ScriptEngine;
28import javax.script.ScriptEngineFactory;
29
30public class AbclScriptEngineFactory implements ScriptEngineFactory {
31
32    private static AbclScriptEngine THE_ONLY_ONE_ENGINE = null;
33 
34    public String getEngineName() {
35  return "ABCL Script";
36    }
37
38    public String getEngineVersion() {
39  return "0.1";
40    }
41
42    public List<String> getExtensions() {
43  List<String> extensions = new ArrayList<String>(1);
44  extensions.add("lisp");
45  return Collections.unmodifiableList(extensions);
46    }
47
48    public String getLanguageName() {
49  return "ANSI Common Lisp";
50    }
51
52    public String getLanguageVersion() {
53  return "ANSI X3.226:1994";
54    }
55
56    public static String escape(String raw) {
57  StringBuilder sb = new StringBuilder();
58  int len = raw.length();
59  char c;
60  for(int i = 0; i < len; ++i) {
61      c = raw.charAt(i);
62      if(c != '"') {
63    sb.append(c);
64      } else {
65    sb.append("\\\"");
66      }
67  }
68  return sb.toString();
69    }
70 
71    public String getMethodCallSyntax(String obj, String method, String... args) {
72  StringBuilder sb = new StringBuilder();
73  sb.append("(jcall \"");
74  sb.append(method);
75  sb.append("\" ");
76  sb.append(obj);
77  for(String arg : args) {
78      sb.append(" ");
79      sb.append(arg);
80  }
81  sb.append(")");
82  return sb.toString();
83    }
84   
85    public List<String> getMimeTypes() {
86  return Collections.unmodifiableList(new ArrayList<String>());
87    }
88
89    public List<String> getNames() {
90  List<String> names = new ArrayList<String>(1);
91  names.add("ABCL");
92  names.add("cl");
93  names.add("Lisp");
94  names.add("Common Lisp");
95  return Collections.unmodifiableList(names);
96    }
97
98    public String getOutputStatement(String str) {
99  return "(cl:print \"" + str + "\")";
100    }
101
102    public Object getParameter(String key) {
103  // TODO Auto-generated method stub
104  return null;
105    }
106
107    public String getProgram(String... statements) {
108  StringBuilder sb = new StringBuilder();
109  sb.append("(cl:progn");
110  for(String stmt : statements) {
111      sb.append("\n\t");
112      sb.append(stmt);
113  }
114  sb.append(")");
115  return sb.toString();
116    }
117   
118    public synchronized ScriptEngine getScriptEngine() {
119        if (THE_ONLY_ONE_ENGINE == null) {
120            THE_ONLY_ONE_ENGINE = new AbclScriptEngine();
121        }
122  return THE_ONLY_ONE_ENGINE;
123    }
124
125}
Note: See TracBrowser for help on using the repository browser.