當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。