当前位置: 首页>>代码示例>>Java>>正文


Java WrappedException类代码示例

本文整理汇总了Java中org.mozilla.javascript.WrappedException的典型用法代码示例。如果您正苦于以下问题:Java WrappedException类的具体用法?Java WrappedException怎么用?Java WrappedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WrappedException类属于org.mozilla.javascript包,在下文中一共展示了WrappedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
/**
 * Calls JavaScript native function.
 * 
 * @param function Function to be called.
 * @param args Call arguments.
 */
public static void call(final Function function, final Object... args) {
	Scriptable scope = function.getParentScope();
	ObjectTopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope);
	if (topLevel != null) {
		Context cx = topLevel.getBrowserScriptEngine().enterContext();
		try {
			function.call(cx, scope, scope, args);
		} catch (Exception ex) {
			try {
				JavaScriptEngine.throwWrappedScriptException(ex);
			} catch (ScriptException e) {
				throw new WrappedException(e);
			}
		} finally {
			Context.exit();
		}
	}
}
 
开发者ID:jutils,项目名称:jsen-js,代码行数:25,代码来源:HostedJavaMethod.java

示例2: testErrorOnEvalCall

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
/**
 * Since a continuation can only capture JavaScript frames and not Java
 * frames, ensure that Rhino throws an exception when the JavaScript frames
 * don't reach all the way to the code called by
 * executeScriptWithContinuations or callFunctionWithContinuations.
 */
public void testErrorOnEvalCall() {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1); // must use interpreter mode
        Script script = cx.compileString("eval('myObject.f(3);');",
                "test source", 1, null);
        cx.executeScriptWithContinuations(script, globalScope);
        fail("Should throw IllegalStateException");
    } catch (WrappedException we) {
        Throwable t = we.getWrappedException();
        assertTrue(t instanceof IllegalStateException);
        assertTrue(t.getMessage().startsWith("Cannot capture continuation"));
    } finally {
        Context.exit();
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:23,代码来源:ContinuationsApiTest.java

示例3: callWithDomain

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
/**
 * Calls {@link Callable#call(Context, Scriptable, Scriptable, Object[])} of
 * <code>callable</code> under restricted security domain where an action is
 * allowed only if it is allowed according to the Java stack on the
 * moment of the <code>callWithDomain</code> call and
 * <code>securityDomain</code>. Any call to
 * {@link #getDynamicSecurityDomain(Object)} during execution of
 * {@link Callable#call(Context, Scriptable, Scriptable, Object[])}
 * should return a domain incorporate restrictions imposed by
 * <code>securityDomain</code>.
 */
public Object callWithDomain(Object securityDomain, final Context cx,
                             final Callable callable,
                             final Scriptable scope,
                             final Scriptable thisObj,
                             final Object[] args) {
    AccessControlContext acc;
    if (securityDomain instanceof AccessControlContext)
        acc = (AccessControlContext)securityDomain;
    else {
        RhinoClassLoader loader = (RhinoClassLoader)securityDomain;
        acc = loader.rhinoAccessControlContext;
    }

    PrivilegedExceptionAction execAction = new PrivilegedExceptionAction() {
        public Object run() {
            return callable.call(cx, scope, thisObj, args);
        }
    };
    try {
        return AccessController.doPrivileged(execAction, acc);
    } catch (Exception e) {
        throw new WrappedException(e);
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:36,代码来源:BatikSecurityController.java

示例4: call

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
public Object call( Context cx, Scriptable scope, Scriptable thisObj,
		java.lang.Object[] args )
{
	Object[] convertedArgs = JavascriptEvalUtil
			.convertToJavaObjects( args );

	try
	{
		if ( convertedArgs.length == 2 )
			report.setUserProperty( (String) convertedArgs[0],
					(String) convertedArgs[1] );
		else if ( convertedArgs.length == 3 )
			report.setUserProperty( (String) convertedArgs[0],
					convertedArgs[1], (String) convertedArgs[2] );

	}
	catch ( SemanticException e )
	{
		throw new WrappedException( e );
	}

	return null;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:24,代码来源:ReportDesign.java

示例5: evaluate

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
/**
 * This method evaluates a piece of ECMAScript.
 * @param scriptReader a <code>java.io.Reader</code> on the piece of script
 * @param description description which can be later used (e.g., for error
 *        messages).
 * @return if no exception is thrown during the call, should return the
 * value of the last expression evaluated in the script.
 */
public Object evaluate(final Reader scriptReader, final String description)
    throws IOException {

    ContextAction evaluateAction = new ContextAction() {
        public Object run(Context cx) {
            try {
                return cx.evaluateReader(globalObject,
                                         scriptReader,
                                         description,
                                         1, rhinoClassLoader);
            } catch (IOException ioe) {
                throw new WrappedException(ioe);
            }
        }
    };
    try {
        return contextFactory.call(evaluateAction);
    } catch (JavaScriptException e) {
        // exception from JavaScript (possibly wrapping a Java Ex)
        Object value = e.getValue();
        Exception ex = value instanceof Exception ? (Exception) value : e;
        throw new InterpreterException(ex, ex.getMessage(), -1, -1);
    } catch (WrappedException we) {
        Throwable w = we.getWrappedException();
        if (w instanceof Exception) {
            throw new InterpreterException
                ((Exception) w, w.getMessage(), -1, -1);
        } else {
            throw new InterpreterException(w.getMessage(), -1, -1);
        }
    } catch (InterruptedBridgeException ibe) {
        throw ibe;
    } catch (RuntimeException re) {
        throw new InterpreterException(re, re.getMessage(), -1, -1);
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:45,代码来源:RhinoInterpreter.java

示例6: call

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
public Object call(Context cx, Scriptable scope, Scriptable thisObj, java.lang.Object[] args) {
    try {
        return jsFunction_render((args.length == 0) ? null : args[0]);
    } catch(RenderException e) {
        throw new WrappedException(e);
    }
}
 
开发者ID:haplo-org,项目名称:haplo-safe-view-templates,代码行数:8,代码来源:HaploTemplate.java

示例7: assignValue

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
public void assignValue(Object value) {
    if (isReadOnly()) {
        throw new ReadOnlyScriptBlockException(getScriptText());
    }
    Context cx = RhinoUtil.enter();
    try {
        Scriptable scope = RhinoUtil.getScope();
        if (_elStyle) {
            Object host =  getELStyleHost(cx, scope);
            if (host == null) {
                scope.put(_elStyleName, scope, value);
            } else if (host instanceof Scriptable) {
                ((Scriptable) host).put(_elStyleName, scope, value);
            } else if (host instanceof AttributeScope) {
                ((AttributeScope) host).setAttribute(_elStyleName, value);
            } else {
                ObjectUtil.setProperty(host, _elStyleName, value);
            }
        } else {
            throw new IllegalStateException();
        }
    } catch (WrappedException e) {
        RhinoUtil.removeWrappedException(e);
    } finally {
        Context.exit();
    }
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:28,代码来源:TextCompiledScriptImpl.java

示例8: removeWrappedException

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
/**
 * Rhinoスクリプト実行中に発生した例外を、wrapされていない元の例外にして
 * 再度throwします。もしwrapされていた例外がRuntimeExceptionでない場合、
 * RuntimeExceptionでwrapしてthrowします。
 *
 * @param e Rhinoスクリプト中で発生した例外
 */
public static void removeWrappedException(WrappedException e) {
    Throwable t = e.getWrappedException();
    if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
    }
    throw new RuntimeException(t);
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:15,代码来源:RhinoUtil.java

示例9: execute

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
public Object execute(Object[] args) {
    Context cx = RhinoUtil.enter();
    Object ret = null;
    try {
        compileFromSource(cx, getSource());
        Object jsRet = _rhinoScript.exec(cx, RhinoUtil.getScope());
        ret = RhinoUtil.convertResult(cx, getExpectedClass(), jsRet);
    } catch (WrappedException e) {
        RhinoUtil.removeWrappedException(e);
    } finally {
        Context.exit();
    }
    return ret;
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:15,代码来源:SourceCompiledScriptImpl.java

示例10: handleError

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
private void handleError(Throwable t) throws BSFException {
    if (t instanceof WrappedException) {
        t = ((WrappedException) t).getWrappedException();
    }

    String message = null;
    Throwable target = t;

    if (t instanceof JavaScriptException) {
        message = t.getLocalizedMessage();

        // Is it an exception wrapped in a JavaScriptException?
        Object value = ((JavaScriptException) t).getValue();
        if (value instanceof Throwable) {
            // likely a wrapped exception from a LiveConnect call.
            // Display its stack trace as a diagnostic
            target = (Throwable) value;
        }
    }
    else if (t instanceof EvaluatorException ||
             t instanceof SecurityException) {
        message = t.getLocalizedMessage();
    }
    else if (t instanceof RuntimeException) {
        message = "Internal Error: " + t.toString();
    }
    else if (t instanceof StackOverflowError) {
        message = "Stack Overflow";
    }

    if (message == null) {
        message = t.toString();
    }

    if (t instanceof Error && !(t instanceof StackOverflowError)) {
        // Re-throw Errors because we're supposed to let the JVM see it
        // Don't re-throw StackOverflows, because we know we've
        // corrected the situation by aborting the loop and
        // a long stacktrace would end up on the user's console
        throw (Error) t;
    }
    else {
        throw new BSFException(BSFException.REASON_OTHER_ERROR,
                               "JavaScript Error: " + message,
                               target);
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:48,代码来源:BSFJavaScriptEngine.java

示例11: runnersFromJs

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
private static List<Runner> runnersFromJs(final Class<?> cls)
throws InitializationError, IOException {
    final JavascriptResource js = cls.getAnnotation(JavascriptResource.class);
    final List<Runner> runners = new LinkedList<>();
    try (final LineNumberReader reader = new LineNumberReader(
            new InputStreamReader(ClassLoader.getSystemResourceAsStream(js.name())))) {
        while (true) {
            final String expr = reader.readLine();
            final int line = reader.getLineNumber();
            if (expr == null) {
                break;
            }

            if (!expr.trim().isEmpty() && !expr.trim().startsWith("//")) {
                runners.add(new Runner() {
                    @Override
                    public Description getDescription() {
                        final String[] parts = expr.split(" *; *");
                        final String desc = parts[parts.length - 1];
                        return Description.createTestDescription(cls,
                            String.format("%s:%s => %s", js.name(), line, desc), js);
                    }

                    @Override
                    public void run(final RunNotifier notifier) {
                        notifier.fireTestStarted(getDescription());
                        // should really do something more generic here
                        // instead of hard-coded setup, explicit
                        // data frame construction...
                        System.setIn(new ByteArrayInputStream(
                            String.format("tmp = frames[0]; df = frames[1]; %s;", expr).getBytes()));
                        try {
                            final DataFrame<Object> df = DataFrame.readCsv(ClassLoader.getSystemResourceAsStream("grouping.csv"));
                            final Object result = Shell.repl(Arrays.asList(new DataFrame<>(), df));
                            if (result instanceof WrappedException) {
                                throw WrappedException.class.cast(result).getWrappedException();
                            } else if (result instanceof Throwable) {
                                throw Throwable.class.cast(result);
                            }
                            org.junit.Assert.assertFalse(result == null);
                        } catch (final IOException ioe) {
                            notifier.fireTestAssumptionFailed(new Failure(getDescription(), ioe));
                        } catch (final AssertionError err) {
                            notifier.fireTestFailure(new Failure(getDescription(), err));
                        } catch (final Throwable ex) {
                            notifier.fireTestFailure(new Failure(getDescription(), ex));
                        } finally {
                            notifier.fireTestFinished(getDescription());
                        }
                    }
                });
            }
        }
    }
    return runners;
}
 
开发者ID:cardillo,项目名称:joinery,代码行数:57,代码来源:JavascriptExpressionSuite.java

示例12: initFunctions

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
private void initFunctions( )
{
	Method[] tmpMethods = this.getClass( ).getDeclaredMethods( );
	HashMap<String, Method> methods = new LinkedHashMap<String, Method>( );
	for ( int i = 0; i < tmpMethods.length; i++ )
	{
		Method tmpMethod = tmpMethods[i];
		String methodName = tmpMethod.getName( );
		// must handle special case with long parameter or polymiorphism
		if ( "getReportElementByID".equals( methodName ) //$NON-NLS-1$
				|| "setUserProperty".equals( methodName ) ) //$NON-NLS-1$
			continue;
		if ( ( tmpMethod.getModifiers( ) & Modifier.PUBLIC ) != 0 )
			methods.put( methodName, tmpMethod );
	}

	Context.enter( );
	try
	{
		for ( final Entry<String, Method> entry : methods.entrySet( ) )
		{
			this.defineProperty( entry.getKey( ), new BaseFunction( ) {

				public Object call( Context cx, Scriptable scope,
						Scriptable thisObj, Object[] args )
				{
					Object[] convertedArgs = JavascriptEvalUtil
							.convertToJavaObjects( args );
					try
					{
						Method method = entry.getValue( );
						return method.invoke( ReportDesign.this,
								convertedArgs );
					}
					catch ( Exception e )
					{
						throw new WrappedException( e );
					}
				}

			}, DONTENUM );
		}
	}
	finally
	{
		Context.exit( );
	}

	this.defineProperty( "getReportElementByID", //$NON-NLS-1$
			new Function_getReportElementByID( ), DONTENUM );
	this.defineProperty( "setUserProperty", //$NON-NLS-1$
			new Function_setUserProperty( ), DONTENUM );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:54,代码来源:ReportDesign.java

示例13: handleError

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
private void handleError(Throwable t) throws BSFException {
    if (t instanceof WrappedException)
        t = ((WrappedException) t).getWrappedException();

    String message = null;
    Throwable target = t;

    if (t instanceof JavaScriptException) {
        message = t.getLocalizedMessage();

        // Is it an exception wrapped in a JavaScriptException?
        Object value = ((JavaScriptException) t).getValue();
        if (value instanceof Throwable) {
            // likely a wrapped exception from a LiveConnect call.
            // Display its stack trace as a diagnostic
            target = (Throwable) value;
        }
    }
    else if (t instanceof EvaluatorException ||
             t instanceof SecurityException) {
        message = t.getLocalizedMessage();
    }
    else if (t instanceof RuntimeException) {
        message = "Internal Error: " + t.toString();
    }
    else if (t instanceof StackOverflowError) {
        message = "Stack Overflow";
    }

    if (message == null)
        message = t.toString();

    if (t instanceof Error && !(t instanceof StackOverflowError)) {
        // Re-throw Errors because we're supposed to let the JVM see it
        // Don't re-throw StackOverflows, because we know we've
        // corrected the situation by aborting the loop and
        // a long stacktrace would end up on the user's console
        throw (Error) t;
    }
    else {
        throw new BSFException(BSFException.REASON_OTHER_ERROR,
                               "JavaScript Error: " + message,
                               target);
    }
}
 
开发者ID:botelhojp,项目名称:apache-jmeter-2.10,代码行数:46,代码来源:BSFJavaScriptEngine.java

示例14: doBeforeProcess

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
protected Scriptable doBeforeProcess(final Context parentContext, final Scriptable parentScope, final Scriptable thisObj,
        final Pair<Scriptable, Function> beforeProcessCallback)
{
    final Context cx = Context.enter();
    try
    {
        this.scriptProcessor.inheritCallChain(parentContext);

        final Scriptable processScope = cx.newObject(parentScope);
        processScope.setPrototype(null);
        processScope.setParentScope(null);

        // check for registerChildScope function on logger and register process scope if function is available
        final Object loggerValue = ScriptableObject.getProperty(parentScope, RhinoLogFunction.LOGGER_OBJ_NAME);
        if (loggerValue instanceof Scriptable)
        {
            final Scriptable loggerObj = (Scriptable) loggerValue;
            final Object registerChildScopeFuncValue = ScriptableObject.getProperty(loggerObj,
                    RhinoLogFunction.REGISTER_CHILD_SCOPE_FUNC_NAME);
            if (registerChildScopeFuncValue instanceof Function)
            {
                final Function registerChildScopeFunc = (Function) registerChildScopeFuncValue;
                registerChildScopeFunc.call(cx, parentScope, thisObj, new Object[] { processScope });
            }
        }

        if (beforeProcessCallback.getSecond() != null)
        {
            final Scriptable beforeProcessOriginalCallScope = beforeProcessCallback.getFirst();
            final Scriptable beforeProcessCallScope = this.facadeFactory.toFacadedObject(beforeProcessOriginalCallScope, parentScope);
            final Function beforeProcessFn = beforeProcessCallback.getSecond();

            if (beforeProcessFn instanceof NativeFunction)
            {
                // native function has parent scope based on location in source code
                // per batch function contract we need to execute it in our process scope
                final NativeFunction nativeFn = (NativeFunction) beforeProcessFn;

                final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
                threadLocalParentScope.setEffectiveParentScope(processScope);
                try
                {
                    // execute with thread local parent scope
                    nativeFn.call(cx, processScope, beforeProcessCallScope, new Object[0]);
                }
                finally
                {
                    threadLocalParentScope.removeEffectiveParentScope();
                }
            }
            else
            {
                // not a native function, so has no associated scope - calling as-is
                beforeProcessFn.call(cx, processScope, beforeProcessCallScope, new Object[0]);
            }
        }

        return processScope;
    }
    catch (final WrappedException ex)
    {
        final Throwable wrappedException = ex.getWrappedException();
        if (wrappedException instanceof RuntimeException)
        {
            throw (RuntimeException) wrappedException;
        }
        throw ex;
    }
    finally
    {
        Context.exit();
    }
}
 
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:74,代码来源:AbstractExecuteBatchFunction.java

示例15: doProcess

import org.mozilla.javascript.WrappedException; //导入依赖的package包/类
protected void doProcess(final Context parentContext, final Scriptable parentScope, final Scriptable processScope,
        final Scriptable thisObj, final Pair<Scriptable, Function> processCallback, final Object element)
{
    final Context cx = Context.enter();
    try
    {
        this.scriptProcessor.inheritCallChain(parentContext);

        final Scriptable processOriginalCallScope = processCallback.getFirst();
        final Scriptable processCallScope = this.facadeFactory.toFacadedObject(processOriginalCallScope, parentScope);
        final Function processFn = processCallback.getSecond();

        if (processFn instanceof NativeFunction)
        {
            // native function has parent scope based on location in source code
            // per batch function contract we need to execute it in our process scope
            final NativeFunction nativeFn = (NativeFunction) processFn;

            final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
            threadLocalParentScope.setEffectiveParentScope(processScope);
            try
            {
                // execute with thread local parent scope
                nativeFn.call(cx, processScope, processCallScope, new Object[] { element });
            }
            finally
            {
                threadLocalParentScope.removeEffectiveParentScope();
            }
        }
        else
        {
            // not a native function, so has not associated scope - calling as-is
            processFn.call(cx, processScope, processCallScope, new Object[] { element });
        }
    }
    catch (final WrappedException ex)
    {
        final Throwable wrappedException = ex.getWrappedException();
        if (wrappedException instanceof RuntimeException)
        {
            throw (RuntimeException) wrappedException;
        }
        throw ex;
    }
    finally
    {
        Context.exit();
    }
}
 
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:51,代码来源:AbstractExecuteBatchFunction.java


注:本文中的org.mozilla.javascript.WrappedException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。