本文整理汇总了Java中org.mozilla.javascript.WrappedException.getWrappedException方法的典型用法代码示例。如果您正苦于以下问题:Java WrappedException.getWrappedException方法的具体用法?Java WrappedException.getWrappedException怎么用?Java WrappedException.getWrappedException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.WrappedException
的用法示例。
在下文中一共展示了WrappedException.getWrappedException方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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);
}
}
示例3: 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);
}
示例4: 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
示例5: 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
示例6: doAfterProcess
import org.mozilla.javascript.WrappedException; //导入方法依赖的package包/类
protected void doAfterProcess(final Context parentContext, final Scriptable parentScope, final Scriptable processScope,
final Scriptable thisObj, final Pair<Scriptable, Function> afterProcessCallback)
{
final Context cx = Context.enter();
try
{
this.scriptProcessor.inheritCallChain(parentContext);
if (afterProcessCallback.getSecond() != null)
{
final Scriptable afterProcessOriginalCallScope = afterProcessCallback.getFirst();
final Scriptable afterProcessCallScope = this.facadeFactory.toFacadedObject(afterProcessOriginalCallScope, parentScope);
final Function afterProcessFn = afterProcessCallback.getSecond();
if (afterProcessFn 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) afterProcessFn;
final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
threadLocalParentScope.setEffectiveParentScope(processScope);
try
{
// execute with thread local parent scope
nativeFn.call(cx, processScope, afterProcessCallScope, new Object[0]);
}
finally
{
threadLocalParentScope.removeEffectiveParentScope();
}
}
else
{
// not a native function, so has not associated scope - calling as-is
afterProcessFn.call(cx, processScope, afterProcessCallScope, new Object[0]);
}
}
}
catch (final WrappedException ex)
{
final Throwable wrappedException = ex.getWrappedException();
if (wrappedException instanceof RuntimeException)
{
throw (RuntimeException) wrappedException;
}
throw ex;
}
finally
{
Context.exit();
// clear thread-local facade mapping
this.facadeFactory.clearThread();
}
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:56,代码来源:AbstractExecuteBatchFunction.java
示例7: execute
import org.mozilla.javascript.WrappedException; //导入方法依赖的package包/类
public Object execute(Object[] args) {
Context cx = RhinoUtil.enter();
Object ret = null;
try {
Scriptable scope = RhinoUtil.getScope();
Object jsRet;
if (_elStyle && args != null) {
Object host = getELStyleHost(cx, scope);
jsRet = functionExecute(cx, scope, host, args);
} else {
jsRet = normalExecute(cx, scope);
}
ret = RhinoUtil.convertResult(cx, getExpectedClass(), jsRet);
} catch (RhinoException e) {
if (e instanceof WrappedException) {
WrappedException we = (WrappedException) e;
Throwable wrapped = we.getWrappedException();
if (wrapped instanceof RenderingBrake) {
RhinoUtil.removeWrappedException(we);
}
}
// エラーとなったソース情報が微妙なので微調整。
// 行番号はスクリプト次第でずれてしまう。
int offsetLine;
String message;
String sourceName;
if (e instanceof JavaScriptException
&& ((JavaScriptException)e).getValue() instanceof IdScriptableObject) {
offsetLine = -1;
IdScriptableObject scriptable =
(IdScriptableObject) ((JavaScriptException) e).getValue();
Object messageProperty = scriptable.get("message", scriptable);
if (messageProperty != Scriptable.NOT_FOUND) {
message = messageProperty.toString();
} else {
message = scriptable.toString();
}
} else {
offsetLine = e.lineNumber() - _lineNumber + 1; // one "\n" is added
message = e.details() + " in script=\n" + getText();
}
if (e.lineSource() == null && message != null) {
String[] lines = message.split("\n");
offsetLine = (lines.length > offsetLine) ? offsetLine : _offsetLine;
if (offsetLine >= 0 && lines.length > offsetLine) {
e.initLineSource(lines[offsetLine]);
sourceName = _sourceName;
} else {
sourceName = e.sourceName();
}
} else {
sourceName = e.sourceName();
}
throw new OffsetLineRhinoException(
message,
sourceName, e.lineNumber(), e.lineSource(),
e.columnNumber(), offsetLine, e.getCause());
} finally {
Context.exit();
}
return ret;
}