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


Java ResolveOptions类代码示例

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


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

示例1: resolveReplaceNull

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveReplaceNull() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
Path test0 = DataBundles.newListItem(list);
DataBundles.setStringValue(test0, "test0");
// 1 empty
// 2 error
DataBundles.setError(DataBundles.getListItem(list, 2), 
		"Example error", "1. Tried it\n2. Didn't work");

List resolved = (List) DataBundles.resolve(list, ResolveOptions.REPLACE_ERRORS, ResolveOptions.REPLACE_NULL);
assertEquals(test0, resolved.get(0));
assertEquals("", resolved.get(1));
assertEquals("", resolved.get(2));
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:19,代码来源:TestDataBundles.java

示例2: resolveBinaries

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveBinaries() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
Path item = DataBundles.newListItem(list);

byte[] bytes = new byte[] { 
		// Those lovely lower bytes who don't work well in UTF-8
		0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 
		// and some higher ones for fun
		-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,
		-19,-20,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-31
};
Files.write(item, bytes);


List resolvedBytes = (List)DataBundles.resolve(list, ResolveOptions.BYTES);
assertArrayEquals(bytes, (byte[])resolvedBytes.get(0));

List resolvedString = (List)DataBundles.resolve(list, ResolveOptions.STRING);		
// The below will always fail as several of the above bytes are not parsed as valid UTF-8
// but instead be substituted with replacement characters. 		
//assertArrayEquals(bytes, ((String)resolvedString.get(0)).getBytes(StandardCharsets.UTF_8));
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:25,代码来源:TestDataBundles.java

示例3: resolveAsStream

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
/**
 * Deeply resolve path as a {@link Stream} that only contain leaf elements of 
 * the specified class.
 * <p>
 * This method is somewhat equivalent to {@link #resolve(Path, ResolveOptions...)}, but 
 * the returned stream is not in any particular order, and will contain the leaf
 * items from all deep lists. Empty lists and error documents are ignored.
 * <p>
 * Any {@link IOException}s occurring during resolution are 
 * wrapped as {@link UncheckedIOException}.
 * <p>
 * Supported types include:
 * <ul>
 *   <li>{@link String}.class</li>
 *   <li><code>byte[].class</code></li>
 *   <li>{@link Path}.class</li>
 *   <li>{@link URI}.class</li>
 *   <li>{@link URL}.class</li>  
 *   <li>{@link File}.class</li>
 *   <li>{@link ErrorDocument}.class</li>
 *   <li>{@link Object}.class</li>
 * </ul>
 * 
 * @param path Data bundle path to resolve
 * @param type Type of objects to return, e.g. <code>String.class</code>
 * @return A {@link Stream} of resolved objects, or an empty stream if no such objects were resolved.
 * @throws UncheckedIOException If the path could not be accessed. 
 */
public static <T> Stream<T> resolveAsStream(Path path, Class<T> type) throws UncheckedIOException {
	ResolveOptions options;
	if (type == String.class) {
		options = ResolveOptions.STRING;
	} else if (type == byte[].class) {
		options = ResolveOptions.BYTES;
	} else if (type == Path.class) {
		options = ResolveOptions.PATH;
	} else if (type == URI.class) {
		options = ResolveOptions.URI;
	} else {
		// Dummy-option, we'll filter on the returned type anyway
		options = ResolveOptions.DEFAULT;
	}
	if (isList(path)) {
		// return Stream of unordered list of resolved list items,	
		// recursing to find the leaf nodes			
		try {
			return Files.walk(path)
					// avoid re-recursion
					.filter(p -> !Files.isDirectory(p)) 
					.flatMap(p -> resolveItemAsStream(p, type, options));
		} catch (IOException e) {
			throw new UncheckedIOException(e);
		}
	} else {
		return resolveItemAsStream(path, type, options);
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:58,代码来源:DataBundles.java

示例4: resolveItemAsStream

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
private static <T> Stream<T> resolveItemAsStream(Path path, Class<T> type, ResolveOptions options) throws UncheckedIOException {
	try {
		Object value = resolve(path, options);
		if (type.isInstance(value)) {
			return Stream.of(type.cast(value));
		}
		return Stream.empty();
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:12,代码来源:DataBundles.java

示例5: resolveNestedString

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveNestedString() throws Exception {
Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);


Path nested0 = DataBundles.newListItem(list);
DataBundles.newListItem(nested0);		
DataBundles.setStringValue(DataBundles.newListItem(nested0), "test0,0");
DataBundles.setStringValue(DataBundles.newListItem(nested0), "test0,1");
DataBundles.setStringValue(DataBundles.newListItem(nested0), "test0,2");
Path nested1 = DataBundles.newListItem(list);
DataBundles.newListItem(nested1); // empty
Path nested2 = DataBundles.newListItem(list);
DataBundles.newListItem(nested2);
DataBundles.setStringValue(DataBundles.newListItem(nested2), "test2,0");



List<List<String>> resolved = (List<List<String>>) DataBundles.resolve(list, ResolveOptions.STRING);

assertEquals("Unexpected list size", 3, resolved.size());
assertEquals("Unexpected sublist[0] size", 3, resolved.get(0).size());
assertEquals("Unexpected sublist[1] size", 0, resolved.get(1).size());
assertEquals("Unexpected sublist[2] size", 1, resolved.get(2).size());


assertEquals("test0,0", resolved.get(0).get(0));
assertEquals("test0,1", resolved.get(0).get(1));
assertEquals("test0,2", resolved.get(0).get(2));
assertEquals("test2,0", resolved.get(2).get(0));		
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:34,代码来源:TestDataBundles.java

示例6: resolveURIs

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveURIs() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
Path test0 = DataBundles.newListItem(list);
DataBundles.setStringValue(test0, "test0");
// 1 http:// reference
URI reference = URI.create("http://example.com/");
DataBundles.setReference(DataBundles.newListItem(list), reference);
// 2 file:/// reference
Path tmpFile = Files.createTempFile("test", ".txt");
URI fileRef = tmpFile.toUri();
assertEquals("file", fileRef.getScheme());
DataBundles.setReference(DataBundles.newListItem(list), fileRef);
// 3 empty (null)
// 4 error
Path error4 = DataBundles.getListItem(list,  4);
DataBundles.setError(error4, "Example error", "1. Tried it\n2. Didn't work");

List resolved = (List) DataBundles.resolve(list, ResolveOptions.URI);
assertEquals(test0.toUri(), resolved.get(0));
assertEquals(reference, resolved.get(1));
assertEquals(fileRef, resolved.get(2));
assertNull(resolved.get(3));
// NOTE: Need to get the Path again due to different file extension
assertTrue(resolved.get(4) instanceof ErrorDocument);		
//assertTrue(DataBundles.getListItem(list,  4).toUri(), resolved.get(4));
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:31,代码来源:TestDataBundles.java

示例7: resolvePaths

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolvePaths() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
Path test0 = DataBundles.newListItem(list);
DataBundles.setStringValue(test0, "test0");
// 1 http:// reference
URI reference = URI.create("http://example.com/");
Path test1 = DataBundles.setReference(DataBundles.newListItem(list), reference);
// 2 file:/// reference
Path tmpFile = Files.createTempFile("test", ".txt");
URI fileRef = tmpFile.toUri();
assertEquals("file", fileRef.getScheme());
Path test2 = DataBundles.setReference(DataBundles.newListItem(list), fileRef);
// 3 empty (null)
// 4 error
Path error4 = DataBundles.setError(DataBundles.getListItem(list,  4), "Example error", "1. Tried it\n2. Didn't work");

List<Path> resolved = (List<Path>) DataBundles.resolve(list, ResolveOptions.PATH);
assertEquals(test0, resolved.get(0));
assertEquals(test1, resolved.get(1));
assertEquals(test2, resolved.get(2));
assertNull(resolved.get(3));
assertEquals(error4, resolved.get(4));		
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:28,代码来源:TestDataBundles.java

示例8: resolveReplaceError

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveReplaceError() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
DataBundles.setStringValue(DataBundles.newListItem(list), "test0");
// 1 error
DataBundles.setError(DataBundles.newListItem(list), 
		"Example error", "1. Tried it\n2. Didn't work");

List resolved = (List) DataBundles.resolve(list, ResolveOptions.STRING, ResolveOptions.REPLACE_ERRORS);
assertEquals("test0", resolved.get(0));
assertNull(resolved.get(1));
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:16,代码来源:TestDataBundles.java

示例9: resolveDefault

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveDefault() throws Exception {
  	Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
Path test0 = DataBundles.newListItem(list);
DataBundles.setStringValue(test0, "test0");
// 1 http:// reference
URI reference = URI.create("http://example.com/");
Path test1 = DataBundles.setReference(DataBundles.newListItem(list), reference);
// 2 file:/// reference
Path tmpFile = Files.createTempFile("test", ".txt");
URI fileRef = tmpFile.toUri();
assertEquals("file", fileRef.getScheme());
Path test2 = DataBundles.setReference(DataBundles.newListItem(list), fileRef);
// 3 empty (null)
// 4 error
Path error4 = DataBundles.setError(DataBundles.getListItem(list,  4), "Example error", "1. Tried it\n2. Didn't work");

List resolved = (List) DataBundles.resolve(list, ResolveOptions.DEFAULT);
assertEquals(test0, resolved.get(0));
assertTrue(resolved.get(1) instanceof URL);
assertEquals("http://example.com/", resolved.get(1).toString());
assertTrue(resolved.get(2) instanceof File);
assertEquals(tmpFile.toFile(), resolved.get(2));
assertNull(resolved.get(3));
assertTrue(resolved.get(4) instanceof ErrorDocument);
  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:30,代码来源:TestDataBundles.java

示例10: getObjectForName

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
protected Object getObjectForName(String name) {
	Object result = null;
	try {
		if (chosenReferences.containsKey(name))
			result = DataBundles.resolve(chosenReferences.get(name), 
					ResolveOptions.STRING, 
					ResolveOptions.REPLACE_ERRORS, 
					ResolveOptions.REPLACE_NULL);
	} catch (IOException e) {
		logger.warn("Error getting value for " + name, e);
	}
	if (result == null)
		result = "(null)";
	return result;
}
 
开发者ID:apache,项目名称:incubator-taverna-workbench,代码行数:16,代码来源:SaveAllResultsSPI.java

示例11: resolveString

import org.apache.taverna.databundle.DataBundles.ResolveOptions; //导入依赖的package包/类
@Test
  public void resolveString() throws Exception {
Path inputs = DataBundles.getInputs(dataBundle);
Path list = DataBundles.getPort(inputs, "in1");
DataBundles.createList(list);
// 0 string value
DataBundles.setStringValue(DataBundles.newListItem(list), "test0");
// 1 http:// reference
URI reference = URI.create("http://example.com/");
DataBundles.setReference(DataBundles.newListItem(list), reference);
// 2 file:/// reference
Path tmpFile = Files.createTempFile("test", ".txt");
URI fileRef = tmpFile.toUri();
assertEquals("file", fileRef.getScheme());
DataBundles.setReference(DataBundles.newListItem(list), fileRef);
// 3 empty (null)
// 4 error
DataBundles.setError(DataBundles.getListItem(list,  4), "Example error", "1. Tried it\n2. Didn't work");




Object resolved = DataBundles.resolve(list, ResolveOptions.STRING);
assertTrue("Didn't resolve to a list", resolved instanceof List);

List resolvedList = (List) resolved;
assertEquals("Unexpected list size", 5, resolvedList.size());

assertTrue(resolvedList.get(0) instanceof String);
assertEquals("test0", resolvedList.get(0));

assertTrue(resolvedList.get(1) instanceof URL);
assertEquals(reference, ((URL)resolvedList.get(1)).toURI());

assertTrue(resolvedList.get(2) instanceof File);
assertEquals(tmpFile.toFile(), resolvedList.get(2));

assertNull(resolvedList.get(3));
assertTrue(resolvedList.get(4) instanceof ErrorDocument);
assertEquals("Example error", ((ErrorDocument)resolvedList.get(4)).getMessage());

  }
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:43,代码来源:TestDataBundles.java


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