org.mozilla.javascript.Context.setWrapFactory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(6.2k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.mozilla.javascript.Context.setWrapFactory()方法的一些代码示例,展示了Context.setWrapFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.setWrapFactory()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:setWrapFactory

Context.setWrapFactory介绍

[英]Set a WrapFactory for this Context.

The WrapFactory allows custom object wrapping behavior for Java object manipulated with JavaScript.
[中]为此上下文设置WrapFactory。
WrapFactory允许使用JavaScript操作Java对象的自定义对象包装行为。

代码示例

代码示例来源:origin: stackoverflow.com

import java.util.Vector;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class InterceptTest {
  public static void main(String[] args) {
    Context cx=Context.enter();
    cx.setWrapFactory(new InterceptWrapFactory());
    Scriptable root=cx.initStandardObjects();
    ScriptableObject.putProperty(root,"v", new Vector<String>());
    cx.evaluateString(root, "v.add('foo'); v.get(0)", "src", 1, null);
  }
}

代码示例来源:origin: org.seasar.mayaa/mayaa

/**
 * カレントスレッドに関連付いたContextを取得します。
 * 同時にScriptEnvironmentからWrapFactoryを取得してContextにセットします。
 * Rhinoスクリプト実行前に、Context.enter()の代わりに利用します。
 * これを実行したあとは、try {} finally {} を使って Context.exit() を
 * 必ず実行する必要があります。
 *
 * @return カレントスレッドに関連付いたContext
 */
public static Context enter() {
  Context cx = Context.enter();
  WrapFactory factory = ScriptEnvironmentImpl.getWrapFactory();
  if (factory != null) {
    cx.setWrapFactory(factory);
  }
  return cx;
}

代码示例来源:origin: rhq-project/rhq

@Override
protected Context makeContext() {
  Context cx = super.makeContext();
  cx.setOptimizationLevel(-1);
  cx.setWrapFactory(new CustomWrapFactory());
  return cx;
}

代码示例来源:origin: viltgroup/minium

@Override
public T call() throws X {
  Context cx = Context.enter();
  cx.setWrapFactory(wrapFactory);
  try {
    return doCall(cx, scope);
  } finally {
    Context.exit();
  }
}

代码示例来源:origin: stackoverflow.com

c.setWrapFactory(wrapper);

代码示例来源:origin: org.alfresco.surf/spring-webscripts

/**
 * Inits the processor.
 */
protected void initProcessor()
{
  // Initialize the secure scope
  Context cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.secureScope = initScope(cx, false, true);
  }
  finally
  {
    Context.exit();
  }
  
  // Initialize the non-secure scope
  cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.nonSecureScope = initScope(cx, true, true);
  }
  finally
  {
    Context.exit();
  }
}

代码示例来源:origin: org.apache.xmlgraphics/batik-bridge

/**
   * Creates a Context object for use with the interpreter.
   */
  protected Context makeContext() {
    Context cx = super.makeContext();
    cx.setWrapFactory(wrapFactory);
    cx.setSecurityController(securityController);
    cx.setClassShutter(classShutter);
    if (rhinoClassLoader == null) {
      cx.setOptimizationLevel(-1);
    }
    return cx;
  }
}

代码示例来源:origin: apache/batik

/**
   * Creates a Context object for use with the interpreter.
   */
  protected Context makeContext() {
    Context cx = super.makeContext();
    cx.setWrapFactory(wrapFactory);
    cx.setSecurityController(securityController);
    cx.setClassShutter(classShutter);
    if (rhinoClassLoader == null) {
      cx.setOptimizationLevel(-1);
    }
    return cx;
  }
}

代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik

/**
   * Creates a Context object for use with the interpreter.
   */
  protected Context makeContext() {
    Context cx = super.makeContext();
    cx.setWrapFactory(wrapFactory);
    cx.setSecurityController(securityController);
    cx.setClassShutter(classShutter);
    if (rhinoClassLoader == null) {
      cx.setOptimizationLevel(-1);
    }
    return cx;
  }
}

代码示例来源:origin: org.springframework.extensions.surf/spring-webscripts

/**
 * Inits the processor.
 */
protected void initProcessor()
{
  // Initialize the secure scope
  Context cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.secureScope = initScope(cx, false, true);
  }
  finally
  {
    Context.exit();
  }
  
  // Initialize the non-secure scope
  cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.nonSecureScope = initScope(cx, true, true);
  }
  finally
  {
    Context.exit();
  }
}

代码示例来源:origin: deas/alfresco

/**
 * Inits the processor.
 */
protected void initProcessor()
{
  // Initialize the secure scope
  Context cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.secureScope = initScope(cx, false, true);
  }
  finally
  {
    Context.exit();
  }
  
  // Initialize the non-secure scope
  cx = Context.enter();
  try
  {
    cx.setWrapFactory(wrapFactory);
    this.nonSecureScope = initScope(cx, true, true);
  }
  finally
  {
    Context.exit();
  }
}

代码示例来源:origin: org.alfresco/alfresco-repository

try
  cx.setWrapFactory(wrapFactory);
  this.secureScope = initScope(cx, false, true);
try
  cx.setWrapFactory(wrapFactory);
  this.nonSecureScope = initScope(cx, true, true);

代码示例来源:origin: Alfresco/alfresco-repository

try
  cx.setWrapFactory(wrapFactory);
  this.secureScope = initScope(cx, false, true);
try
  cx.setWrapFactory(wrapFactory);
  this.nonSecureScope = initScope(cx, true, true);

代码示例来源:origin: io.apisense/rhino-android

/**
 * Create new Context instance to be associated with the current thread.
 */
@Override
protected Context makeContext() {
  Context cx = super.makeContext();
  cx.setLanguageVersion(languageVersion);
  cx.setOptimizationLevel(optimizationLevel);
  cx.setClassShutter(RhinoClassShutter.getInstance());
  cx.setWrapFactory(RhinoWrapFactory.getInstance());
  return cx;
}

代码示例来源:origin: javanna/elasticshell

@Override
protected void init() {
  super.init();
  Context context = Context.enter();
  context.setErrorReporter(new RhinoErrorReporter(false, console.out()));
  context.setWrapFactory(new RhinoCustomWrapFactory());
}

代码示例来源:origin: org.alfresco.surf/spring-webscripts

cx.setWrapFactory(wrapFactory);
Scriptable scope;
if (this.shareSealedScopes)

代码示例来源:origin: deas/alfresco

cx.setWrapFactory(wrapFactory);
Scriptable scope;
if (this.shareSealedScopes)

代码示例来源:origin: RPTools/maptool

public static Object evaluate(Map<String, Object> globals, String script) throws IOException {
  init();
  try {
    Context jsContext = ContextFactory.getGlobal().enterContext();
    jsContext.setClassShutter(new SecurityClassShutter());
    jsContext.setWrapFactory(new PrimitiveWrapFactory());
    Scriptable instanceScope = jsContext.newObject(jsScope);
    instanceScope.setPrototype(jsScope);
    instanceScope.setParentScope(null);
    if (globals != null) {
      for (Map.Entry<String, Object> entry : globals.entrySet()) {
        Object wrappedObject = Context.javaToJS(entry.getValue(), instanceScope);
        ScriptableObject.putProperty(instanceScope, entry.getKey(), wrappedObject);
      }
    }
    Object o = jsContext.evaluateString(instanceScope, script, "evaluate", 1, null);
    return o;
  } finally {
    Context.exit();
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.scripting.javascript

rhinoContext.setWrapFactory(wrapFactory);

代码示例来源:origin: deas/alfresco

try
  cx.setWrapFactory(wrapFactory);
  Scriptable scope;
  if (!secure)

相关文章

微信公众号

Context类方法