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


Java NativeJavaObject类代码示例

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


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

示例1: evaluate

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
public String evaluate(String url, String host) {
	Object result = "";
	try {
		Context ctx = Context.enter();
		result = ctx.evaluateString(scope, "FindProxyForURL (\"" + url + "\",\"" + host + "\")", "check", 0, null);
	} catch (Exception e) {
		Engine.logProxyManager.error("(PacManager) Failed to evaluate .pac for " + url + " from " + host, e);
	} finally {
		Context.exit();	
	}
	if (result instanceof NativeJavaObject) {
		result = ((NativeJavaObject) result).unwrap();
	}
	
	Engine.logProxyManager.debug("(PacManager) evaluate " + url + " from " + host + " : " + result);
	
	return result.toString();
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:19,代码来源:PacManager.java

示例2: stepExecute

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Override
protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException {
	variables.clear();

	if (isEnabled()) {
		for (RequestableVariable var : getParentSequence().getAllVariables()) {
			try {
				//evaluate(javascriptContext, scope, var.getName(), "expression", true);
				evaluated = scope.get(var.getName(), scope);
				if (evaluated != null && !(evaluated instanceof Undefined)) {
					if (evaluated instanceof NativeJavaObject) {
						evaluated = ((NativeJavaObject) evaluated).unwrap();
					}
					variables.put(var.getName(), evaluated);
				}
			} catch (Exception e) {
				evaluated = null;
				Engine.logBeans.warn(e.getMessage());
			}
		}
		return super.stepExecute(javascriptContext, scope);
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:InputVariablesStep.java

示例3: runScript

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例4: runScript

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
public String runScript(String js, String functionName, Object[] functionParams) {
    Context rhino = Context.enter();
    rhino.setOptimizationLevel(-1);
    try {
        Scriptable scope = rhino.initStandardObjects();

        ScriptableObject.putProperty(scope, "javaContext", Context.javaToJS(mActivity.getContext(), scope));
        ScriptableObject.putProperty(scope, "javaLoader", Context.javaToJS(ChapterActivity.class.getClassLoader(), scope));

        rhino.evaluateString(scope, js, "ChapterActivity", 1, null);

        Function function = (Function) scope.get(functionName, scope);

        Object result = function.call(rhino, scope, scope, functionParams);
        if (result instanceof String) {
            return (String) result;
        } else if (result instanceof NativeJavaObject) {
            return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
        } else if (result instanceof NativeObject) {
            return (String) ((NativeObject) result).getDefaultValue(String.class);
        }
        return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
    } finally {
        Context.exit();
    }
}
 
开发者ID:hanFengSan,项目名称:Yakami-manga,代码行数:27,代码来源:ChapterController.java

示例5: runScript

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
public String runScript(String js, String functionName, Object[] functionParams) {
    Context rhino = Context.enter();
    rhino.setOptimizationLevel(-1);
    try {
        Scriptable scope = rhino.initStandardObjects();

        ScriptableObject.putProperty(scope, "javaContext", Context.javaToJS(MainActivity.this, scope));
        ScriptableObject.putProperty(scope, "javaLoader", Context.javaToJS(MainActivity.class.getClassLoader(), scope));

        rhino.evaluateString(scope, js, "MainActivity", 1, null);

        Function function = (Function) scope.get(functionName, scope);

        Object result = function.call(rhino, scope, scope, functionParams);
        if (result instanceof String) {
            return (String) result;
        } else if (result instanceof NativeJavaObject) {
            return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
        } else if (result instanceof NativeObject) {
            return (String) ((NativeObject) result).getDefaultValue(String.class);
        }
        return result.toString();
    } finally {
        Context.exit();
    }
}
 
开发者ID:hearsilent,项目名称:KUAS-AP,代码行数:27,代码来源:MainActivity.java

示例6: runScript

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
private String runScript(String js, String functionName, Object[] functionParams) {
    Context rhino = Context.enter();
    rhino.setOptimizationLevel(-1);
    try {
        Scriptable scope = rhino.initStandardObjects();
        rhino.evaluateString(scope, js, "JavaScript", js.split("\n").length, null);

        Function function = (Function) scope.get(functionName, scope);

        Object result = function.call(rhino, scope, scope, functionParams);
        if (result instanceof String) {
            return (String) result;
        } else if (result instanceof NativeJavaObject) {
            return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
        } else if (result instanceof NativeObject) {
            return (String) ((NativeObject) result).getDefaultValue(String.class);
        }
        return result.toString();
    } finally {
        Context.exit();
    }
}
 
开发者ID:andforce,项目名称:SmartZPN,代码行数:23,代码来源:PacScriptParser.java

示例7: jsFunction_join

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
public static Scriptable jsFunction_join(final Context ctx, final Scriptable object, final Object[] args, final Function func) {
    final DataFrame<Object> other = DataFrameAdapter.class.cast(args[0]).df;
    final JoinType type = args.length > 1 && args[1] instanceof NativeJavaObject ?
            JoinType.class.cast(Context.jsToJava(args[1], JoinType.class)) : null;
    if (args.length > 1 && args[args.length - 1] instanceof Function) {
        @SuppressWarnings("unchecked")
        final KeyFunction<Object> f = (KeyFunction<Object>)Context.jsToJava(args[args.length - 1], KeyFunction.class);
        if (type != null) {
            return new DataFrameAdapter(object, cast(object).df.join(other, type, f));
        }
        return new DataFrameAdapter(object, cast(object).df.join(other, f));
    }
    if (type != null) {
        return new DataFrameAdapter(object, cast(object).df.join(other, type));
    }
    return new DataFrameAdapter(object, cast(object).df.join(other));
}
 
开发者ID:cardillo,项目名称:joinery,代码行数:18,代码来源:DataFrameAdapter.java

示例8: jsToPigMap

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
private Object jsToPigMap(Scriptable object, Schema schema, int depth) {
    debugConvertJSToPig(depth, "Map", object, schema);
    Map<String, Object> map = new HashMap<String, Object>();
    Object[] ids = object.getIds();
    for (Object id : ids) {
        if (id instanceof String) {
            String name = (String) id;
            Object value = object.get(name, object);
            if (value instanceof NativeJavaObject) {
                value = ((NativeJavaObject)value).unwrap();
            } else if (value instanceof Undefined) {
                value = null;
            }
            map.put(name, value);
        }
    }
    debugReturn(depth, map);
    return map;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:20,代码来源:JsFunction.java

示例9: isSupportedType

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
private boolean isSupportedType( Object obValue )
{
	if ( obValue instanceof Scriptable )
	{
		if ( obValue instanceof IdScriptableObject )
		{
			IdScriptableObject jsObject = ( (IdScriptableObject) obValue );
			if ( jsObject.getClassName( ).equals( "Date" ) )
			{
				return true;
			}
			return false;
		}
		else if ( obValue instanceof NativeJavaObject )
		{
			return true;
		}
		return false;
	}
	return IOUtil.getTypeIndex( obValue ) != -1;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:22,代码来源:DynamicTextItemExecutor.java

示例10: getTypeName

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
public String getTypeName( )
{
	if ( reservedValueType != null )
	{
		return reservedValueType;
	}

	Object valObj = value;

	if ( value instanceof NativeJavaObject )
	{
		valObj = ( (NativeJavaObject) value ).unwrap( );
	}

	if ( valObj != null )
	{
		return convertArrayTypeName( valObj.getClass( ), isPrimitive );
	}

	return "null"; //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:birt,代码行数:22,代码来源:JsValue.java

示例11: testFixDir

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Test
public void testFixDir() throws Exception {
    String js = "" +
            "ci.fixDir({" +
            "   file1: ci.fixFile('123')," +
            "   file2: ci.fixFile('234')" +
            "})";

    TestConfigurationParser parser = new TestConfigurationParser();
    NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string");
    FixDirHierarchyCreator creator = (FixDirHierarchyCreator) creatorObj.unwrap();
    FixDir fixDir = creator.create(null);

    Assert.assertEquals(fixDir.getChildren().size(), 2);
    Assert.assertTrue(IOUtils.contentEquals(fixDir.getChildren().get("file1").asFile().getContent(), new ByteArrayInputStream("123".getBytes())));
    Assert.assertTrue(IOUtils.contentEquals(fixDir.getChildren().get("file2").asFile().getContent(), new ByteArrayInputStream("234".getBytes())));
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:18,代码来源:TestConfigurationParserTest.java

示例12: testFixDirWithFixDir

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Test
public void testFixDirWithFixDir() throws Exception {
    String js = "" +
            "ci.fixDir({" +
            "    file0: ci.fixFile('012')," +
            "    dir1: ci.fixDir({" +
            "        file1: ci.fixFile('123')," +
            "        file2: ci.fixFile('234')" +
            "    })" +
            "})";

    TestConfigurationParser parser = new TestConfigurationParser();
    NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string");
    FixDirHierarchyCreator creator = (FixDirHierarchyCreator) creatorObj.unwrap();
    FixDir fixDir = creator.create(null);

    Assert.assertEquals(fixDir.getChildren().size(), 2);
    Assert.assertTrue(IOUtils.contentEquals(fixDir.getChildren().get("file0").asFile().getContent(), new ByteArrayInputStream("012".getBytes())));

    FixDir fixDir2 = (FixDir) fixDir.getChildren().get("dir1");
    Assert.assertEquals(fixDir2.getChildren().size(), 2);
    Assert.assertTrue(IOUtils.contentEquals(fixDir2.getChildren().get("file1").asFile().getContent(), new ByteArrayInputStream("123".getBytes())));
    Assert.assertTrue(IOUtils.contentEquals(fixDir2.getChildren().get("file2").asFile().getContent(), new ByteArrayInputStream("234".getBytes())));

}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:26,代码来源:TestConfigurationParserTest.java

示例13: testFixTableFromTSV

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Test
public void testFixTableFromTSV() throws Exception {

    String js = "ci.fixTableFromTsv(ci.fixFile(\"A\\tB\\n1\\t2\\n11\\t22\"))";

    TestConfigurationParser parser = new TestConfigurationParser();

    NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string");
    FileFixTableCreator creator = (FileFixTableCreator) creatorObj.unwrap();
    TestRun testRun = mock(TestRun.class);

    FixTable t = creator.create(testRun);
    FixTable.FixRow r1 = t.getRows().get(0);
    FixTable.FixRow r2 = t.getRows().get(1);
    Assert.assertEquals("1", r1.getCells().get("A"));
    Assert.assertEquals("2", r1.getCells().get("B"));
    Assert.assertEquals("11", r2.getCells().get("A"));
    Assert.assertEquals("22", r2.getCells().get("B"));
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:20,代码来源:TestConfigurationParserTest.java

示例14: testHiveInput

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Test
public void testHiveInput() throws Exception {

    String tableCreationScript = "table creation script";
    String js = "ci.hiveInput(\"dbname\", \"tablename\", ci.fixFile(\"" + tableCreationScript + "\"))";

    TestConfigurationParser parser = new TestConfigurationParser();

    NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string");
    HiveTableDeployer hiveTableDeployer = (HiveTableDeployer) creatorObj.unwrap();

    FixFile tableCreationFile = hiveTableDeployer.getTableCreationScriptFile().create(null);

    Assert.assertEquals(hiveTableDeployer.getDatabaseName(), new DatabaseName("dbname"));
    Assert.assertEquals(hiveTableDeployer.getTableName(), "tablename");
    Assert.assertEquals(IOUtils.toString(tableCreationFile.getContent()), tableCreationScript);
    Assert.assertNull(hiveTableDeployer.getDataFileCreator());
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:19,代码来源:TestConfigurationParserTest.java

示例15: testHiveInputWithData

import org.mozilla.javascript.NativeJavaObject; //导入依赖的package包/类
@Test
public void testHiveInputWithData() throws Exception {

    String tableCreationScript = "table creation script";
    String js =
            "var table = ci.fixTable([\"col1\", \"col2\"], [[\"row1\", \"row2\"],[\"row11\", \"row22\"]]);" +
            "ci.hiveInput(\"dbname\", \"tablename\", ci.fixFile(\"" + tableCreationScript + "\"), table)";

    TestConfigurationParser parser = new TestConfigurationParser();

    NativeJavaObject creatorObj = (NativeJavaObject) parser.evaluateTestConfig(new StringReader(js), "string");
    HiveTableDeployer hiveTableDeployer = (HiveTableDeployer) creatorObj.unwrap();

    Assert.assertEquals(hiveTableDeployer.getDatabaseName(), new DatabaseName("dbname"));
    Assert.assertEquals(hiveTableDeployer.getTableName(), "tablename");

    FixFile tableCreationFile = hiveTableDeployer.getTableCreationScriptFile().create(null);
    Assert.assertEquals(IOUtils.toString(tableCreationFile.getContent()), tableCreationScript);
    Assert.assertEquals(hiveTableDeployer.getDataFileCreator().getClass(), StringArrayFixTableCreator.class);
}
 
开发者ID:collectivemedia,项目名称:celos,代码行数:21,代码来源:TestConfigurationParserTest.java


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