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