當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptException類代碼示例

本文整理匯總了Java中javax.script.ScriptException的典型用法代碼示例。如果您正苦於以下問題:Java ScriptException類的具體用法?Java ScriptException怎麽用?Java ScriptException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScriptException類屬於javax.script包,在下文中一共展示了ScriptException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: timeOut

import javax.script.ScriptException; //導入依賴的package包/類
public void timeOut(final long delay, final EventInstanceManager eim) {
    if (disposed || eim == null) {
        return;
    }
    eventTimer = EventTimer.getInstance().schedule(new Runnable() {
        @Override
        public void run() {
            if (disposed || eim == null || em == null) {
                return;
            }
            try {
                em.getIv().invokeFunction("scheduledTimeout", eim);
            } catch (NoSuchMethodException | ScriptException ex) {
                System.out.println("Event name" + em.getName() + ", Instance name : " + name + ", method Name : scheduledTimeout:\n" + ex);
            }
        }
    }, delay);
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:19,代碼來源:EventInstanceManager.java

示例2: lexicalScopeTest

import javax.script.ScriptException; //導入依賴的package包/類
/**
 * Make sure lexically defined variables are accessible in other scripts.
 */
@Test
public void lexicalScopeTest() throws ScriptException {
    final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    final ScriptEngine e = factory.getScriptEngine(LANGUAGE_ES6);

    e.eval("let x; const y = 'world';");

    assertEquals(e.eval("x = 'hello'"), "hello");
    assertEquals(e.eval("typeof x"), "string");
    assertEquals(e.eval("typeof y"), "string");
    assertEquals(e.eval("x"), "hello");
    assertEquals(e.eval("y"), "world");
    assertEquals(e.eval("typeof this.x"), "undefined");
    assertEquals(e.eval("typeof this.y"), "undefined");
    assertEquals(e.eval("this.x"), null);
    assertEquals(e.eval("this.y"), null);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:LexicalBindingTest.java

示例3: testNonWrapping

import javax.script.ScriptException; //導入依賴的package包/類
/**
 * Ensure that the old behaviour (every object is a Map) is unchanged.
 */
@Test
public void testNonWrapping() throws ScriptException {
    final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
    final Object val = engine.eval("({x: [1, {y: [2, {z: [3]}]}, [4, 5]]})");
    final Map<String, Object> root = asMap(val);
    final Map<String, Object> x = asMap(root.get("x"));
    assertEquals(x.get("0"), 1);
    final Map<String, Object> x1 = asMap(x.get("1"));
    final Map<String, Object> y = asMap(x1.get("y"));
    assertEquals(y.get("0"), 2);
    final Map<String, Object> y1 = asMap(y.get("1"));
    final Map<String, Object> z = asMap(y1.get("z"));
    assertEquals(z.get("0"), 3);
    final Map<String, Object> x2 = asMap(x.get("2"));
    assertEquals(x2.get("0"), 4);
    assertEquals(x2.get("1"), 5);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:JSONCompatibleTest.java

示例4: classFilterTest2

import javax.script.ScriptException; //導入依賴的package包/類
@Test
public void classFilterTest2() throws ScriptException {
    final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
    final ScriptEngine e = fac.getScriptEngine(new String[0], Thread.currentThread().getContextClassLoader(),
        new ClassFilter() {
            @Override
            public boolean exposeToScripts(final String fullName) {
                // don't allow anything that is not "java."
                return fullName.startsWith("java.");
            }
        });

    assertEquals(e.eval("typeof javax.script.ScriptEngine"), "object");
    assertEquals(e.eval("typeof java.util.Vector"), "function");

    try {
        e.eval("Java.type('javax.script.ScriptContext')");
        fail("should not reach here");
    } catch (final ScriptException | RuntimeException se) {
        if (! (se.getCause() instanceof ClassNotFoundException)) {
            fail("ClassNotFoundException expected");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:TrustedScriptEngineTest.java

示例5: globalPerEngineTest

import javax.script.ScriptException; //導入依賴的package包/類
@Test
public void globalPerEngineTest() throws ScriptException {
    final NashornScriptEngineFactory fac = new NashornScriptEngineFactory();
    final String[] options = new String[] { "--global-per-engine" };
    final ScriptEngine e = fac.getScriptEngine(options);

    e.eval("function foo() {}");

    final ScriptContext newCtx = new SimpleScriptContext();
    newCtx.setBindings(e.createBindings(), ScriptContext.ENGINE_SCOPE);

    // all global definitions shared and so 'foo' should be
    // visible in new Bindings as well.
    assertTrue(e.eval("typeof foo", newCtx).equals("function"));

    e.eval("function bar() {}", newCtx);

    // bar should be visible in default context
    assertTrue(e.eval("typeof bar").equals("function"));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TrustedScriptEngineTest.java

示例6: action

import javax.script.ScriptException; //導入依賴的package包/類
public final void action(final MapleClient c, final byte mode, final byte type, final int selection) {
    if (mode != -1) {
        final NPCConversationManager cm = cms.get(c);
        if (cm == null || cm.getLastMsg() > -1) {
            return;
        }
        final Lock lock = c.getNPCLock();
        lock.lock();
        try {
            if (cm.pendingDisposal) {
                dispose(c);
            } else {
                c.setClickedNPC();
                cm.getIv().invokeFunction("action", mode, type, selection);
            }
        } catch (final ScriptException | NoSuchMethodException e) {
            System.err.println("Error executing NPC script. NPC ID : " + cm.getNpc() + ":" + e);
            dispose(c);
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:25,代碼來源:NPCScriptManager.java

示例7: variableArityInterfaceTest

import javax.script.ScriptException; //導入依賴的package包/類
@Test
/**
 * Tests whether invocation of a JavaScript method through a variable arity
 * Java method will pass the vararg array. Both non-vararg and vararg
 * JavaScript methods are tested.
 *
 * @throws ScriptException
 */
public void variableArityInterfaceTest() throws ScriptException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    e.eval(
            "function test1(i, strings) {"
            + "    return 'i == ' + i + ', strings instanceof java.lang.String[] == ' + (strings instanceof Java.type('java.lang.String[]')) + ', strings == ' + java.util.Arrays.toString(strings)"
            + "}"
            + "function test2() {"
            + "    return 'arguments[0] == ' + arguments[0] + ', arguments[1] instanceof java.lang.String[] == ' + (arguments[1] instanceof Java.type('java.lang.String[]')) + ', arguments[1] == ' + java.util.Arrays.toString(arguments[1])"
            + "}");
    final VariableArityTestInterface itf = ((Invocable) e).getInterface(VariableArityTestInterface.class);
    Assert.assertEquals(itf.test1(42, "a", "b"), "i == 42, strings instanceof java.lang.String[] == true, strings == [a, b]");
    Assert.assertEquals(itf.test2(44, "c", "d", "e"), "arguments[0] == 44, arguments[1] instanceof java.lang.String[] == true, arguments[1] == [c, d, e]");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:InvocableTest.java

示例8: initJS

import javax.script.ScriptException; //導入依賴的package包/類
/**
 * Setup javascript shortcuts such as 'server'.
 */
private void initJS() {

    // Allow JS to load java classes.
    Thread currentThread = Thread.currentThread();
    ClassLoader previousClassLoader = currentThread.getContextClassLoader();
    currentThread.setContextClassLoader(Core.getInstance().getClass().getClassLoader());

    try {
        this.engine = new ScriptEngineManager().getEngineByName("JavaScript");
        engine.put("engine", engine); // Allow JS to do consistent eval.
        engine.eval(new InputStreamReader(Core.getInstance().getResource("boot.js"))); // Run JS startup.
        MechanicManager.getMechanics().forEach(this::bindObject); // Create shortcuts for all mechanics.
        bindClass(Utils.class);
        bindClass(KCPlayer.class);
        bindClass(ReflectionUtil.class);
    } catch (ScriptException ex) {
        ex.printStackTrace();
        Core.warn("Failed to initialize JS shortcuts.");
    } finally {
        // Set back the previous class loader.
        currentThread.setContextClassLoader(previousClassLoader);
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:27,代碼來源:CommandJS.java

示例9: getIntegerVector

import javax.script.ScriptException; //導入依賴的package包/類
@Override
public int[] getIntegerVector(final String variable) {
    if (isNull(variable)) {
        return null;
    } else {
        try {
            final Vector sexp = (Vector) engine.unwrap().eval(variable);
            final int[] array = new int[sexp.length()];
            for (int i = 0; i < array.length; i++) {
                array[i] = sexp.getElementAsInt(i);
            }
            return array;
        } catch (final ScriptException e) {
            throw new RuntimeException(e);
        }
    }
}
 
開發者ID:subes,項目名稱:invesdwin-context-r,代碼行數:18,代碼來源:RenjinScriptTaskResultsR.java

示例10: getBooleanMatrix

import javax.script.ScriptException; //導入依賴的package包/類
@Override
public boolean[][] getBooleanMatrix(final String variable) {
    if (isNull(variable)) {
        return null;
    } else {
        try {
            final Matrix sexp = new Matrix((Vector) engine.unwrap().eval(variable));
            final boolean[][] matrix = new boolean[sexp.getNumRows()][];
            for (int row = 0; row < matrix.length; row++) {
                final boolean[] vector = new boolean[sexp.getNumCols()];
                for (int col = 0; col < vector.length; col++) {
                    vector[col] = sexp.getElementAsInt(row, col) > 0;
                }
                matrix[row] = vector;
            }
            return matrix;
        } catch (final ScriptException e) {
            throw new RuntimeException(e);
        }
    }
}
 
開發者ID:subes,項目名稱:invesdwin-context-r,代碼行數:22,代碼來源:RenjinScriptTaskResultsR.java

示例11: setJsSentence

import javax.script.ScriptException; //導入依賴的package包/類
protected void setJsSentence(INlpSentence s) throws CoreCriticalException {
    try {
        jsEngine.eval("var sentence = [];");
        if ((Boolean) jsEngine.eval(String.format("sentence.positionInSentence == %d", s.getSentenceIndexInCorpus())))
            return;
        jsEngine.eval(String.format("sentence.positionInSentence = %d", s.getSentenceIndexInCorpus()));
        for (int i = 0; i< s.getTokenCount(); i++) {
            Token token = s.getToken(i);
            jsEngine.eval(String.format("sentence[%d] = %s;", token.getTokenIndexInSentence(), tokenToJson(token)));
        }

        jsEngine.eval("sentence.spanAnnotations = []");
        for (SpanAnnotation annotation : s.getSpanAnnotations()) {
            jsEngine.eval(String.format("sentence.spanAnnotations.push(%s);", annotationToJson(annotation)));

            for (int i = annotation.getStartTokenIndex(); i <= annotation.getEndTokenIndex(); i++) {
                jsEngine.eval(String.format("sentence[%s].parentAnnotations.push(sentence.spanAnnotations[sentence.spanAnnotations.length - 1]);", i));
            }
        }

    } catch (ScriptException e) {
        throw new CoreCriticalException(e);
    }
}
 
開發者ID:radsimu,項目名稱:UaicNlpToolkit,代碼行數:25,代碼來源:StateMachine.java

示例12: evalReader

import javax.script.ScriptException; //導入依賴的package包/類
private Object evalReader(Reader in, String filename) {
   try {
     engine.put(ScriptEngine.FILENAME, filename);
     return engine.eval(in);
   } catch (ScriptException sexp) {
     System.err.println(sexp);
     printError(sexp.toString(), sexp);
     } finally {
     try {
       in.close();
     } catch (IOException ioe) {
       printError(ioe.toString(), ioe);
     }
   }
   return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:JSJavaScriptEngine.java

示例13: schedule

import javax.script.ScriptException; //導入依賴的package包/類
public final void schedule(final String methodName, final long delay) {
    if (disposed) {
        return;
    }
    EventTimer.getInstance().schedule(new Runnable() {
        @Override
        public void run() {
            if (disposed || EventInstanceManager.this == null || em == null) {
                return;
            }
            try {
                em.getIv().invokeFunction(methodName, EventInstanceManager.this);
            } catch (NullPointerException npe) {
            } catch (NoSuchMethodException | ScriptException ex) {
                System.out.println("Event name" + em.getName() + ", Instance name : " + name + ", method Name : " + methodName + ":\n" + ex);
            }
        }
    }, delay);
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:20,代碼來源:EventInstanceManager.java

示例14: scriptObjectAutoConversionTest

import javax.script.ScriptException; //導入依賴的package包/類
@Test
public void scriptObjectAutoConversionTest() throws ScriptException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    e.eval("obj = { foo: 'hello' }");
    e.put("Window", e.eval("Packages.jdk.nashorn.api.scripting.test.Window"));
    assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
    assertEquals(e.eval("Window.funcScriptObjectMirror(obj)"), "hello");
    assertEquals(e.eval("Window.funcMap(obj)"), "hello");
    assertEquals(e.eval("Window.funcJSObject(obj)"), "hello");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ScriptEngineTest.java

示例15: accessStaticFieldString

import javax.script.ScriptException; //導入依賴的package包/類
@Test
public void accessStaticFieldString() throws ScriptException {
    e.eval("var ps_string = SharedObject.publicStaticString;");
    assertEquals(SharedObject.publicStaticString, e.get("ps_string"));
    assertEquals("string", e.eval("typeof ps_string;"));
    e.eval("SharedObject.publicStaticString = 'changedString';");
    assertEquals("changedString", SharedObject.publicStaticString);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:StringAccessTest.java


注:本文中的javax.script.ScriptException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。