Author: sebb
Date: Fri Jul 31 01:27:49 2009
New Revision: 799482
URL: http://svn.apache.org/viewvc?rev=799482&view=rev
Log:
The Jexl Script engine factory
Added:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
(with props)
Added:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java?rev=799482&view=auto
==============================================================================
---
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
(added)
+++
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
Fri Jul 31 01:27:49 2009
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.commons.jexl.scripting;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+/**
+ * Implements the Jexl ScriptEngineFactory for JSF-223.
+ * <p>
+ * See
+ * <a
href="http://java.sun.com/javase/6/docs/api/javax/script/package-summary.html">Java
Scripting API</a>
+ * Javadoc.
+ */
+public class JexlScriptEngineFactory implements ScriptEngineFactory {
+
+ private static final List<String> extensions =
Collections.unmodifiableList(
+ Arrays.asList("jexl"));
+
+ private final List<String> mimeTypes = Collections.unmodifiableList(
+ Arrays.asList("application/x-jexl"));
+
+ private final List<String> names = Collections.unmodifiableList(
+ Arrays.asList( "jexl" ));
+
+ /** {...@inheritdoc} */
+ public String getEngineName() {
+ return "Jexl Engine";
+ }
+
+ /** {...@inheritdoc} */
+ public String getEngineVersion() {
+ return "1.0";
+ }
+
+ /** {...@inheritdoc} */
+ public List<String> getExtensions() {
+ return extensions;
+ }
+
+ /** {...@inheritdoc} */
+ public String getLanguageName() {
+ return "Jexl";
+ }
+
+ /** {...@inheritdoc} */
+ public String getLanguageVersion() {
+ return "2.0"; // TODO this should be derived from the actual version
+ }
+
+ /** {...@inheritdoc} */
+ public String getMethodCallSyntax(String object, String method, String[]
args) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(object);
+ sb.append('.');
+ sb.append(method);
+ sb.append('(');
+ boolean needComma = false;
+ for(String arg : args){
+ if (needComma) {
+ sb.append(',');
+ }
+ sb.append(arg);
+ needComma = true;
+ }
+ sb.append(')');
+ return sb.toString();
+ }
+
+ /** {...@inheritdoc} */
+ public List<String> getMimeTypes() {
+ return mimeTypes;
+ }
+
+ /** {...@inheritdoc} */
+ public List<String> getNames() {
+ return names;
+ }
+
+ /** {...@inheritdoc} */
+ public String getOutputStatement(String message) { // TODO - is there one?
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ /** {...@inheritdoc} */
+ public Object getParameter(String key) {
+ if (key == ScriptEngine.ENGINE) {
+ return getEngineName();
+ } else if (key == ScriptEngine.ENGINE_VERSION) {
+ return getEngineVersion();
+ } else if (key == ScriptEngine.NAME) {
+ return getNames();
+ } else if (key == ScriptEngine.LANGUAGE) {
+ return getLanguageName();
+ } else if(key == ScriptEngine.ENGINE_VERSION) {
+ return getLanguageVersion();
+ } else if (key == "THREADING") {
+ return null;//"MULTITHREADED"; // TODO what is the correct value
here?
+ }
+ return null;
+ }
+
+ /** {...@inheritdoc} */
+ public String getProgram(String[] args) {
+ StringBuilder sb = new StringBuilder();
+ for(String arg : args){
+ sb.append(arg);
+ if (!arg.endsWith(";")){
+ sb.append(';');
+ }
+ }
+ return sb.toString();
+ }
+
+ /** {...@inheritdoc} */
+ public ScriptEngine getScriptEngine() {
+ JexlScriptEngine engine = new JexlScriptEngine(this);
+ return engine;
+ }
+
+}
Propchange:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngineFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision