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


Java Callable类代码示例

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


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

示例1: get

import org.mozilla.javascript.Callable; //导入依赖的package包/类
/**
 * @see org.mozilla.javascript.Scriptable#get(java.lang.String, org.mozilla.javascript.Scriptable)
 */
public Object get(String name, Scriptable start)
{
    // get the property from the underlying QName map
    if ("length".equals(name))
    {
        return this.size();
    }
    else if ("hasOwnProperty".equals(name))
    {
        return new Callable()
        {
            @Override
            public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)
            {
                return (args.length > 0 ? hasOwnProperty(args[0]) : null);
            }
        };
    }
    else
    {
        return get(name);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:ScriptableQNameMap.java

示例2: testJsApi

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
    Context cx = Context.enter();
    cx.setOptimizationLevel(-1);
    Script script = cx.compileReader(new InputStreamReader(
            Bug482203.class.getResourceAsStream("conttest.js")), 
            "", 1, null);
    Scriptable scope = cx.initStandardObjects();
    script.exec(cx, scope);
    for(;;)
    {
        Object cont = ScriptableObject.getProperty(scope, "c");
        if(cont == null)
        {
            break;
        }
        ((Callable)cont).call(cx, scope, scope, new Object[] { null });
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:19,代码来源:Bug482203.java

示例3: testJsApi

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
    Context cx = RhinoAndroidHelper.prepareContext();
    try {
        cx.setOptimizationLevel(-1);
        Script script = cx.compileString(TestUtils.readAsset("Bug482203.js"),
                "", 1, null);
        Scriptable scope = cx.initStandardObjects();
        script.exec(cx, scope);
        int counter = 0;
        for(;;)
        {
            Object cont = ScriptableObject.getProperty(scope, "c");
            if(cont == null)
            {
                break;
            }
            counter++;
            ((Callable)cont).call(cx, scope, scope, new Object[] { null });
        }
        assertEquals(counter, 5);
        assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
    } finally {
        Context.exit();
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:26,代码来源:Bug482203Test.java

示例4: callWithDomain

import org.mozilla.javascript.Callable; //导入依赖的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

示例5: testJsApi

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public void testJsApi() throws Exception {
    Context cx = Context.enter();
    try {
        cx.setOptimizationLevel(-1);
        Script script = cx.compileReader(new InputStreamReader(
                Bug482203Test.class.getResourceAsStream("Bug482203.js")),
                "", 1, null);
        Scriptable scope = cx.initStandardObjects();
        script.exec(cx, scope);
        int counter = 0;
        for(;;)
        {
            Object cont = ScriptableObject.getProperty(scope, "c");
            if(cont == null)
            {
                break;
            }
            counter++;
            ((Callable)cont).call(cx, scope, scope, new Object[] { null });
        }
        assertEquals(counter, 5);
        assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result"));
    } finally {
        Context.exit();
    }
}
 
开发者ID:CyboticCatfish,项目名称:code404,代码行数:27,代码来源:Bug482203Test.java

示例6: initializeFunctions

import org.mozilla.javascript.Callable; //导入依赖的package包/类
protected void initializeFunctions() {
  functions = new HashMap<>();
  functions.put("contains", new Callable() {
    @Override
    public Object call(Context context, Scriptable scope, Scriptable thisObject, Object[] args) {
      if (args==null || args.length!=2 || args[0]==null) {
        return false;
      }
      if (args[0] instanceof String) {
        return ((String)args[0]).contains((CharSequence) args[1]);
      }
      if (args[0] instanceof Collection) {
        return ((Collection)args[0]).contains(args[1]);
      }
      return false;
    }
  });
}
 
开发者ID:effektif,项目名称:effektif,代码行数:19,代码来源:RhinoVariableScope.java

示例7: callWithDomain

import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
public Object callWithDomain(Object securityDomain, final Context ctx, final Callable callable,
		final Scriptable scope, final Scriptable thisObj, final Object[] args) {

	Object obj = null;
	try {
		if (securityDomain == null) {
			obj = callable.call(ctx, scope, thisObj, args);
		} else {
			PrivilegedAction<Object> action = () -> callable.call(ctx, scope, thisObj, args);
			AccessControlContext acctx = new AccessControlContext(
					new ProtectionDomain[] { (ProtectionDomain) securityDomain });
			return AccessController.doPrivileged(action, acctx);
		}
	} catch (MissingResourceException err) {
		logger.error("Missing Resource");
	}
	return obj;
}
 
开发者ID:oswetto,项目名称:LoboEvolution,代码行数:20,代码来源:SecurityControllerImpl.java

示例8: doTopCall

import org.mozilla.javascript.Callable; //导入依赖的package包/类
/**
 * Execute top call to script or function. When the runtime is about to 
 * execute a script or function that will create the first stack frame 
 * with scriptable code, it calls this method to perform the real call. 
 * In this way execution of any script happens inside this function.
 */
@Override
protected Object doTopCall(final Callable callable,
        final Context cx, final Scriptable scope,
        final Scriptable thisObj, final Object[] args) {
    AccessControlContext accCtxt = null;
    Scriptable global = ScriptableObject.getTopLevelScope(scope);
    Scriptable globalProto = global.getPrototype();
    if (globalProto instanceof RhinoTopLevel) {
        accCtxt = ((RhinoTopLevel) globalProto).getAccessContext();
    }

    if (accCtxt != null) {
        return AccessController.doPrivileged(new PrivilegedAction<Object>() {

            public Object run() {
                return superDoTopCall(callable, cx, scope, thisObj, args);
            }
        }, accCtxt);
    } else {
        return superDoTopCall(callable, cx, scope, thisObj, args);
    }
}
 
开发者ID:cybertiger,项目名称:RhinoScriptEngine,代码行数:29,代码来源:RhinoScriptEngine.java

示例9: doTopCall

import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        try {
            return super.doTopCall(callable, cx, scope, thisObj, args);
        } catch (Exception e) {
            mUiThreadExceptionHandler.uncaughtException(Thread.currentThread(), e);
            return null;
        }
    }
    return super.doTopCall(callable, cx, scope, thisObj, args);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:13,代码来源:RhinoJavaScriptEngine.java

示例10: doTopCall

import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable,
                           Context cx, Scriptable scope,
                           Scriptable thisObj, Object[] args)
{
    MyContext mcx = (MyContext)cx;
    mcx.quota = 2000;
    return super.doTopCall(callable, cx, scope, thisObj, args);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:10,代码来源:ObserveInstructionCountTest.java

示例11: makeParam

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {

        if(jsonObject == null) return Undefined.instance;

        Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
            @Override
            public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
                return objects[1];
            }
        });
        return param;
    }
 
开发者ID:MilosKozak,项目名称:AndroidAPS,代码行数:13,代码来源:DetermineBasalAdapterAMAJS.java

示例12: makeParamArray

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
        //Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() {
        Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() {
        @Override
        public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
            return objects[1];
        }
    });
    return param;
}
 
开发者ID:MilosKozak,项目名称:AndroidAPS,代码行数:11,代码来源:DetermineBasalAdapterAMAJS.java

示例13: makeParam

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
    Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
        @Override
        public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
            return objects[1];
        }
    });
    return param;
}
 
开发者ID:MilosKozak,项目名称:AndroidAPS,代码行数:10,代码来源:DetermineBasalAdapterMAJS.java

示例14: get

import org.mozilla.javascript.Callable; //导入依赖的package包/类
public Object get( String name, Scriptable scope )
{
	ParameterAttribute parameter = getParameterAttribute( name );
	if ( FIELD_VALUE.equals( name ) )
	{
		return parameter.getValue( );
	}
	else if ( FIELD_DISPLAY_TEXT.equals( name ) )
	{
		return parameter.getDisplayText( );
	}
	Object value = parameter.getValue( );
	Scriptable jsValue = Context.toObject( value, scope );
	Scriptable prototype = jsValue.getPrototype( );
	if( prototype != null )
	{
		Object property = jsValue.getPrototype( ).get( name, jsValue );
		if ( property instanceof Callable )
		{
			Callable callable = (Callable) property;
			return new JsValueCallable( callable, jsValue );
		}
		return jsValue.get( name, jsValue );
	}
	else
	{
		return jsValue.get( name, jsValue );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:30,代码来源:ScriptableParameter.java

示例15: doTopCall

import org.mozilla.javascript.Callable; //导入依赖的package包/类
@Override
protected Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
	TimeBoxedContext mcx = (TimeBoxedContext) cx;
	mcx.startTime = System.currentTimeMillis();

	return super.doTopCall(callable, cx, scope, thisObj, args);
}
 
开发者ID:oglimmer,项目名称:cyc,代码行数:8,代码来源:SandboxContextFactory.java


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