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


Java Context.getService方法代码示例

本文整理汇总了Java中org.scijava.Context.getService方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getService方法的具体用法?Java Context.getService怎么用?Java Context.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.scijava.Context的用法示例。


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

示例1: main

import org.scijava.Context; //导入方法依赖的package包/类
public static void main(String[] args) throws ScriptException {
    // Only for testing purpose

    Context context = new Context();
    ScriptService scriptService = context.getService(ScriptService.class);
    ScriptLanguage scriptLanguage = scriptService.getLanguageByName("python");
    ScriptEngine engine = scriptLanguage.getScriptEngine();

    Object result = engine.eval("p=999\n555");
    System.out.println(result);

    scriptService = context.getService(ScriptService.class);
    scriptLanguage = scriptService.getLanguageByName("python");
    engine = scriptLanguage.getScriptEngine();
    
    result = engine.eval("555");
    System.out.println(result);

    context.dispose();
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:21,代码来源:TestScriptEngine.java

示例2: testLocals

import org.scijava.Context; //导入方法依赖的package包/类
@Test
	public void testLocals() throws ScriptException {
		final Context context = new Context(ScriptService.class);
		final ScriptService scriptService = context.getService(ScriptService.class);

		final ScriptLanguage language = scriptService.getLanguageByExtension("kt");
		final ScriptEngine engine = language.getScriptEngine();
		assertTrue(engine.getFactory().getNames().contains("kotlin"));

		engine.put("hello", 17);
		assertEquals("17", engine.eval("bindings[\"hello\"]").toString());
		assertEquals("17", engine.get("hello").toString());

		engine.put("foo", "bar");
		assertEquals("bar", engine.eval("bindings[\"foo\"]").toString());
		assertEquals("bar", engine.get("foo").toString());
		// FIXME: You cannot modify or insert a variable in the bindings!
//		engine.eval("bindings[\"foo\"] = \"great\"");
//		assertEquals("great", engine.eval("bindings[\"foo\"]").toString());
//		assertEquals("great", engine.get("foo").toString());

		final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
		bindings.clear();
		assertNull(engine.get("hello"));
	}
 
开发者ID:scijava,项目名称:scripting-kotlin,代码行数:26,代码来源:KotlinTest.java

示例3: testLocals

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testLocals() throws ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final ScriptLanguage language = scriptService.getLanguageByExtension("r");
	final ScriptEngine engine = language.getScriptEngine();
	assertEquals(RenjinScriptEngine.class, engine.getClass());
	engine.put("hello", 17);
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.eval("hello")));
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.get("hello")));

	final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
	bindings.clear();
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("hello")));
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("polar_kraken")));
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:18,代码来源:RenjinTest.java

示例4: testParameters

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testParameters() throws InterruptedException, ExecutionException, IOException, ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final String script = "" + //
			"# @ScriptService ss\n" + //
			"# @OUTPUT String name\n" + //
			"language <- ss$getLanguageByName('Renjin')\n" + //
			"name <- language$languageName\n";
	final ScriptModule m = scriptService.run("hello.r", script, true).get();

	final Object actual = m.getOutput("name");
	final String expected = scriptService.getLanguageByName("Renjin").getLanguageName();
	assertEquals(expected, actual);
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:17,代码来源:RenjinTest.java

示例5: createMock

import org.scijava.Context; //导入方法依赖的package包/类
@Override
public IRandomAccess createMock(final byte[] page, final String mode,
	final int bufferSize) throws IOException
{
	final File pageFile = File.createTempFile("page", ".dat");
	final OutputStream stream = new FileOutputStream(pageFile);
	try {
		stream.write(page);
	}
	finally {
		stream.close();
	}
	final Context context = new Context(NIOService.class);
	final NIOService nioService = context.getService(NIOService.class);
	return new NIOFileHandle(nioService, pageFile, mode, bufferSize);
}
 
开发者ID:scifio,项目名称:scifio,代码行数:17,代码来源:NIOFileHandleProvider.java

示例6: run

import org.scijava.Context; //导入方法依赖的package包/类
/**
 * This method is called when the plugin is loaded. See
 * {@link ij.plugin.PlugIn#run(java.lang.String)} Prompts user for a new
 * snippet that will be saved in {@code BAR/My_Routines/}
 *
 * @param arg
 *            ignored (Otherwise specified in plugins.config).
 */
@Override
public void run(final String arg) {
	Utils.shiftClickWarning();
	if (new GuiUtils().getFileCount(Utils.getLibDir()) == 0) {
		final YesNoCancelDialog query = new YesNoCancelDialog(null, "Install lib Files?",
				"Some of the code generated by this plugin assumes the adoption\n"
						+ "of centralized lib files, but none seem to exist in your local directory\n" + "("
						+ Utils.getLibDir() + ")\nWould you like to install them now?");
		if (query.cancelPressed()) {
			return;
		} else if (query.yesPressed()) {
			final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
			final CommandService commandService = context.getService(CommandService.class);
			commandService.run(Installer.class, true);
			return;
		}
	}
	if (showDialog()) {
		if (sContents.length()>0)
			saveAndOpenSnippet();
		else
			IJ.showStatus(sFilename +" was empty. No file was saved...");
	}

}
 
开发者ID:tferr,项目名称:Scripts,代码行数:34,代码来源:SnippetCreator.java

示例7: testBasic

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testBasic() throws Exception {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final ScriptLanguage language =
		scriptService.getLanguageByExtension("scala");
	final ScriptEngine engine = language.getScriptEngine();

	final SimpleScriptContext ssc = new SimpleScriptContext();
	final StringWriter writer = new StringWriter();
	ssc.setWriter(writer);

	final String script = "print(\"3\");";
	engine.eval(script, ssc);
	assertEquals("3", writer.toString());
}
 
开发者ID:scijava,项目名称:scripting-scala,代码行数:18,代码来源:ScalaTest.java

示例8: testBasic

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testBasic() throws InterruptedException, ExecutionException,
	IOException, ScriptException
{
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);
	final String script = "1 + 2";
	final ScriptModule m = scriptService.run("add.kt", script, true).get();
	final Object result = m.getReturnValue();
	assertEquals("3", result.toString());
}
 
开发者ID:scijava,项目名称:scripting-kotlin,代码行数:12,代码来源:KotlinTest.java

示例9: getUploaderService

import org.scijava.Context; //导入方法依赖的package包/类
/** Gets the uploader service associated with this updater frame. */
public UploaderService getUploaderService() {
	if (uploaderService == null) {
		setClassLoaderIfNecessary();
		final Context context = new Context(UploaderService.class);
		uploaderService = context.getService(UploaderService.class);
	}

	return uploaderService;
}
 
开发者ID:imagej,项目名称:imagej-ui-swing,代码行数:11,代码来源:UpdaterFrame.java

示例10: OpSearchResult

import org.scijava.Context; //导入方法依赖的package包/类
public OpSearchResult(final Context context, final OpInfo info,
	final String baseDir)
{
	cacheService = context.getService(CacheService.class);
	convertService = context.getService(ConvertService.class);
	this.info = info;

	final Object shortSigKey = new ShortSigKey(info);
	final Object shortSigValue = cacheService.get(shortSigKey);
	if (shortSigValue == null) {
		shortSig = buildShortSig();
		cacheService.put(shortSigKey, shortSig);
	}
	else shortSig = (String) shortSigValue;

	props = new LinkedHashMap<>();

	props.put("Signature", info.toString());

	final String opType = info.getType().getName();
	props.put("Op type", opType.startsWith("net.imagej.ops.Ops$") ? //
		opType.substring(15).replace('$', '.') : opType);

	final String[] aliases = info.getAliases();
	if (aliases != null && aliases.length > 0) {
		props.put("Aliases", Arrays.toString(aliases));
	}

	props.put("Identifier", info.cInfo().getIdentifier());
	props.put("Location", ModuleSearcher.location(info.cInfo(), baseDir));
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:32,代码来源:OpSearchResult.java

示例11: testReadmesExample

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testReadmesExample() throws Exception {
	// extract the example script
	final File readme = new File("README.md");
	final String contents = new String(FileUtils.readFile(readme), "UTF-8");
	final String telltale = String.format("```python%n");
	final int begin = contents.indexOf(telltale) + telltale.length();
	assertTrue(begin > telltale.length());
	assertTrue(contents.indexOf(telltale, begin) < 0);
	final int end = contents.indexOf(String.format("```%n"), begin);
	assertTrue(end > 0);
	final String snippet = contents.substring(begin, end);
	assertTrue(snippet.startsWith("# @ImageJ ij"));

	final Context context = new Context();
	final ScriptService script = context.getService(ScriptService.class);

	// create mock ImageJ gateway
	script.addAlias("ImageJ", Mock.class);
	final ScriptModule module =
		script.run("op-example.py", snippet, true).get();
	assertNotNull(module);
	module.run();

	final Mock ij = context.getService(Mock.class);
	assertEquals(3, ij.images.size());
	assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
	assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
	assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:31,代码来源:ReadmeExampleTest.java

示例12: testBasic

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testBasic() throws InterruptedException, ExecutionException, IOException, ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);
	final String script = "as.integer(1) + as.integer(2)";
	final ScriptModule m = scriptService.run("add.r", script, true).get();
	final Object result = m.getReturnValue();
	assertTrue(result instanceof IntArrayVector);
	final IntArrayVector resultVector = (IntArrayVector) result;
	assertEquals(1, resultVector.length());
	assertEquals(3, resultVector.getElementAsInt(0));
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:13,代码来源:RenjinTest.java

示例13: testString

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testString() throws InterruptedException, ExecutionException, IOException, ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);
	final String script = "result = R.version$version.string\n";
	final ScriptModule m = scriptService.run("version.r", script, true).get();
	final Object result = m.getReturnValue();
	assertTrue(result.toString().startsWith("Renjin version "));
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:10,代码来源:RenjinTest.java

示例14: testSciJava

import org.scijava.Context; //导入方法依赖的package包/类
@Test
public void testSciJava() throws InterruptedException, ExecutionException, IOException, ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);
	final String langClass = RenjinScriptLanguage.class.getName();
	final String script = "" + //
			"# @OUTPUT " + langClass + " language\n" + //
			"import(" + langClass + ")\n" + //
			"language <<- RenjinScriptLanguage$new()\n" + //
			"print(language$engineName)\n";
	final ScriptModule m = scriptService.run("sjc.r", script, true).get();

	final Object actual = m.getOutput("language");
	assertEquals(scriptService.getLanguageByName("Renjin").getClass(), actual.getClass());
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:16,代码来源:RenjinTest.java

示例15: register

import org.scijava.Context; //导入方法依赖的package包/类
/**
 * Registers the given ImgPlus with the RefManagerService in the provided
 * component's Context.
 */
private static void register(final List<? extends SCIFIOImgPlus> imgPlus,
	final AbstractImgIOComponent component)
{
	final Context ctx = component.getContext();
	final RefManagerService refManagerService =
		ctx.getService(RefManagerService.class);
	for (final SCIFIOImgPlus<?> img : imgPlus) {
		refManagerService.manage(img, ctx);
	}
}
 
开发者ID:scifio,项目名称:scifio,代码行数:15,代码来源:IO.java


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