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

x33g5p2x  于2022-02-03 转载在 JavaScript  
字(8.0k)|赞(0)|评价(0)|浏览(122)

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

WrapFactory.wrapAsJavaObject介绍

[英]Wrap Java object as Scriptable instance to allow full access to its methods and fields from JavaScript.

#wrap(Context,Scriptable,Object,Class) and #wrapNewObject(Context,Scriptable,Object) call this method when they can not convert javaObject to JavaScript primitive value or JavaScript array.

Subclasses can override the method to provide custom wrappers for Java objects.
[中]将Java对象包装为可编写脚本的实例,以允许从JavaScript完全访问其方法和字段。
#wrap(Context,Scriptable,Object,Class)和#wrapNewObject(Context,Scriptable,Object)在无法将javaObject转换为JavaScript原语值或JavaScript数组时调用此方法。
子类可以重写该方法,为Java对象提供自定义包装。

代码示例

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)
  {
    if (javaObject instanceof Map && !(javaObject instanceof ScriptableHashMap))
    {
      return new NativeMap(scope, (Map)javaObject);
    }
    return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
}

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)
  {
    if (javaObject instanceof Map && !(javaObject instanceof ScriptableHashMap))
    {
      return new NativeMap(scope, (Map)javaObject);
    }
    return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
}

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)
  {
    if (javaObject instanceof Map)
    {
      return new NativeMap(scope, (Map)javaObject);
    }
    return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
}

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)
  {
    if (javaObject instanceof Map)
    {
      return new NativeMap(scope, (Map)javaObject);
    }
    return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
}

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, Class staticType)
  {
    if (javaObject instanceof Map)
    {
      return new NativeMap(scope, (Map)javaObject);
    }
    return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
}

代码示例来源:origin: rhino/js

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class<?> cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: geogebra/geogebra

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class<?> cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: ro.isdc.wro4j/rhino

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class<?> cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: com.github.tntim96/rhino

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class<?> cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: io.apigee/rhino

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class<?> cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: com.sun.phobos/phobos-rhino

/**
 * Wrap an object newly created by a constructor call.
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param obj the object to be wrapped
 * @return the wrapped value.
 */
public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
{
  if (obj instanceof Scriptable) {
    return (Scriptable)obj;
  }
  Class cls = obj.getClass();
  if (cls.isArray()) {
    return NativeJavaArray.wrap(scope, obj);
  }
  return wrapAsJavaObject(cx, scope, obj, null);
}

代码示例来源:origin: rhino/js

return NativeJavaArray.wrap(scope, obj);
return wrapAsJavaObject(cx, scope, obj, staticType);

代码示例来源:origin: io.apigee/rhino

return NativeJavaArray.wrap(scope, obj);
return wrapAsJavaObject(cx, scope, obj, staticType);

代码示例来源:origin: ro.isdc.wro4j/rhino

return NativeJavaArray.wrap(scope, obj);
return wrapAsJavaObject(cx, scope, obj, staticType);

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

/**
 * @param cx the current Context for this thread
 * @param scope the scope of the executing script
 * @param javaObject the object to be wrapped
 * @param staticType type hint. If security restrictions prevent to wrap
 *            object based on its class, staticType will be used instead.
 * @return the wrapped value which shall not be null
 */
@SuppressWarnings("unchecked")
@Override
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope,
    Object javaObject, Class staticType) {
  Scriptable result = null;
  try {
    String hostObjectName = getHostObjectName(staticType);
    if (hostObjectName == null) {
      hostObjectName = getHostObjectName(javaObject.getClass());
    }
    if (hostObjectName != null) {
      result = cx.newObject(scope, hostObjectName,
        new Object[] { javaObject });
    }
  } catch (Exception e) {
    log.warn("Cannot Wrap " + javaObject, e);
  }
  if(result==null) {
    result = super.wrapAsJavaObject(cx, scope, javaObject, staticType);
  }
  return result;
}

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

public Object create(Object[] params) {
    ServiceCycle cycle = CycleUtil.getServiceCycle();
    Scriptable parent;
    Context cx = RhinoUtil.enter();
    try {
      Scriptable standard = getStandardObjects();
      parent = cx.getWrapFactory().wrapAsJavaObject(
          cx, standard, cycle, ServiceCycle.class);
    } finally {
      Context.exit();
    }
    return parent;
  }
});

代码示例来源:origin: io.apigee/rhino

Object obj = createInterfaceAdapter(classObject,
    ScriptableObject.ensureScriptableObject(args[0]));
return cx.getWrapFactory().wrapAsJavaObject(cx, scope, obj, null);

代码示例来源:origin: geogebra/geogebra

Object obj = createInterfaceAdapter(classObject,
    ScriptableObject.ensureScriptableObject(args[0]));
return cx.getWrapFactory().wrapAsJavaObject(cx, scope, obj, null);

代码示例来源:origin: com.github.tntim96/rhino

Object obj = createInterfaceAdapter(classObject,
    ScriptableObject.ensureScriptableObject(args[0]));
return cx.getWrapFactory().wrapAsJavaObject(cx, scope, obj, null);

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

public Scriptable wrapAsJavaObject(Context cx, Scriptable scope,
    Object javaObject, Class staticClass) {
  if (javaObject instanceof Map) {
    return new NativeMap(scope, (Map) javaObject);
  } else if (javaObject instanceof List) {
    return new NativeList(scope, (List) javaObject);
  } else if (javaObject instanceof AttributeScope
      && javaObject instanceof Scriptable == false) {
    AttributeScope attrs = (AttributeScope) javaObject;
    return new NativeAttributeScope(scope, attrs);
  } else if (javaObject instanceof ServiceCycle) {
    ServiceCycle cycle = (ServiceCycle) javaObject;
    return new NativeServiceCycle(scope, cycle);
  } else if (javaObject instanceof DynaBean) {
    DynaBean dynaBean = (DynaBean) javaObject;
    return new NativeDynaBean(scope, dynaBean);
  }
  return super.wrapAsJavaObject(cx, scope, javaObject, staticClass);
}

相关文章