gpt4 book ai didi

org.apache.taverna.scufl2.api.io.WorkflowBundleIO类的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 09:17:05 28 4
gpt4 key购买 nike

本文整理了Java中org.apache.taverna.scufl2.api.io.WorkflowBundleIO类的一些代码示例,展示了WorkflowBundleIO类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WorkflowBundleIO类的具体详情如下:
包路径:org.apache.taverna.scufl2.api.io.WorkflowBundleIO
类名称:WorkflowBundleIO

WorkflowBundleIO介绍

[英]Utility class for reading and writing WorkflowBundles.

This class depends on implemented WorkflowBundleReader and WorkflowBundleWriter instances, which are discovered from the classpath using ServiceLoader or set using #setReaders(List)and #setWriters(List). An OSGi service descriptors is provided for instantiating this class as bean workflowBundleIO, while non-OSGi uses can just instantiate this class where needed.

The methods #readBundle(File,String), #readBundle(InputStream,String), #readBundle(URL,String)and #writeBundle(WorkflowBundle,File,String)/ #writeBundle(WorkflowBundle,OutputStream,String) take an argument to indicate the media type of the format. The reader methods from file and URL allow the parameter to be null in order to guess the format, but the writer method requires the format to be specified explicitly.

Known supported formats (as of 2013-04-23): text/vnd.taverna.scufl2.structure A textual tree-view, useful for debugging, but probably incomplete for actual workflow execution. Reader and writer provided by scufl2-api (this module). application/vnd.taverna.scufl2.workflow-bundle The SCU F L 2 workflow bundle format, a ZIP container of RDF/XML files. Reader and writer provided by the scufl2-rdfxml module. application/vnd.taverna.t2flow+xml The Taverna 2 workflow format t2flow. An XML format based on XMLBeans serialization of T2 java objects. Reader provided by the scufl2-t2flow module. application/vnd.taverna.scufl+xml The Taverna 1 workflow format SCUFL. An XML format made for the FreeFluo workflow engine. Experimental reader provided by the scufl2-scufl module. text/vnd.wf4ever.wfdesc+turtle An abstract workflow structure format by the Wf4Ever project. RDF Turtle according to thewfdesc ontology. Writer provided by the third-party scufl2-wfdesc module.
[中]用于读写WorkflowBundles的实用程序类。
此类依赖于已实现的WorkflowBundleReader和WorkflowBundleWriter实例,这些实例是使用ServiceLoader从类路径中发现的,或使用#setReaders(列表)和#SetWriter(列表)进行设置的。OSGi服务描述符用于将这个类实例化为beanworkflowBundleIO,而非OSGi用户只需在需要的地方实例化这个类。
#readBundle(File,String)、#readBundle(InputStream,String)、#readBundle(URL,String)和#writeBundle(WorkflowBundle,File,String)/#writeBundle(WorkflowBundle,OutputStream,String)方法使用参数来指示格式的媒体类型。file和URL中的reader方法允许参数为null以猜测格式,但writer方法要求显式指定格式。
已知支持的格式(截至2013年4月23日):文本/vnd。酒馆。浮渣。构造一个文本树视图,对调试有用,但对实际的工作流执行可能不完整。scufl2 api(本模块)提供的读写器。应用程序/vnd。酒馆。浮渣。工作流包是{$0$}格式,一个RDF/XML文件的ZIP容器。scufl2 rdfxml模块提供的读写器。应用程序/vnd。酒馆。t2flow+xml Taverna 2工作流格式t2flow。基于T2 java对象的XMLBeans序列化的XML格式。scufl2-t2flow模块提供的读卡器。应用程序/vnd。酒馆。scufl+xml Taverna 1工作流格式scufl。为FreeFluo工作流引擎制作的XML格式。scufl2 scufl模块提供的实验读取器。text/vnd。永远不要。wfdesc+turtle是Wf4Ever project. RDF Turtle according to thewfdesc ontology的抽象工作流结构格式。Writer由第三方scufl2-wfdesc模块提供。

代码示例

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

public static WorkflowBundle getWorkflowBundle(Bundle dataBundle)
    throws ReaderException, IOException {
  Path wf = getWorkflow(dataBundle);
  // String type = Files.probeContentType(wf);
  return getWfBundleIO().readBundle(newInputStream(wf), null);
}

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

public static WorkflowBundleIO getWfBundleIO() {
  if (wfBundleIO == null)
    wfBundleIO = new WorkflowBundleIO();
  return wfBundleIO;
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

fileIn.read(firstBytes);
  mediaType = guessMediaTypeForSignature(firstBytes);
WorkflowBundleReader reader = getReaderForMediaType(mediaType);
if (reader == null) {
  if (mediaType == null)

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

URLConnection connection = url.openConnection();
if (mediaType != null && !mediaType.isEmpty())
  addAcceptHeaders(mediaType, connection);
else
  for (String supportedType : getSupportedReaderMediaTypes()) {
    addAcceptHeaders(supportedType, connection);
    connection.addRequestProperty("Accept", "*/*;q=0.1");
  return readBundle(url.openStream(), contentType);

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void readToWriteRoundTrip() throws Exception {
  InputStream inputStream = new ByteArrayInputStream(
      getStructureFormatWorkflowBundle().getBytes("utf-8"));
  WorkflowBundle readBundle = bundleIO.readBundle(inputStream,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(readBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = new String(output.toByteArray(), UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

public static void setWorkflowBundle(Bundle dataBundle,
    WorkflowBundle wfBundle) throws IOException {
  Path bundlePath = withExtension(getWorkflow(dataBundle), DOT_WFBUNDLE);
  checkExistingAnyExtension(bundlePath);
  // TODO: Save as nested folder?
  try (OutputStream outputStream = newOutputStream(bundlePath)) {
    getWfBundleIO().writeBundle(wfBundle, outputStream,
        WFBUNDLE_CONTENT_TYPE);
  } catch (WriterException e) {
    throw new IOException("Can't write workflow bundle to: "
        + bundlePath, e);
  }
  // wfdesc
  Path wfdescPath = getWorkflowDescription(dataBundle);
  try (OutputStream outputStream = newOutputStream(wfdescPath)) {
    getWfBundleIO().writeBundle(wfBundle, outputStream, WFDESC_TURTLE);
  } catch (IllegalArgumentException | WriterException e) {
    logger.warn("Can't write wfdesc to: " + bundlePath, e);
    delete(wfdescPath);
    // throw new IOException("Can't write wfdesc to: " + bundlePath, e);
  }
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-t2flow

@Before
public void readWorkflow() throws ReaderException, IOException {
  WorkflowBundleIO io = new WorkflowBundleIO();
  InputStream is = getClass().getResourceAsStream(ITERATIONSTRATEGIES_T2FLOW);
  wfBundle = io.readBundle(is, APPLICATION_VND_TAVERNA_T2FLOW_XML);
  wf = wfBundle.getMainWorkflow();
  coloursLisr = wf.getProcessors().getByName("ColoursLisr");
  concat = wf.getProcessors().getByName("Concatenate_two_strings");
  shape = wf.getProcessors().getByName("ShapeAnimals");
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

bundleIO.setReaders(Collections.singletonList(myReader));
assertEquals(1, bundleIO.getReaders().size());
assertSame(myReader, bundleIO.getReaders().get(0));
assertSame(myReader,
    bundleIO.getReaderForMediaType("application/vnd.example.myOwn"));
    .getReaderForMediaType(TEXT_VND_TAVERNA_SCUFL2_STRUCTURE));		
assertEquals("test/test", bundleIO.guessMediaTypeForSignature(new byte[4]));

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-t2flow

@Test
  public void readSemanticAnnotations() throws Exception {
    URL wfResource = getClass().getResource(SEMANTIC_ANNOTATIONS);
    assertNotNull("Could not find workflow " + SEMANTIC_ANNOTATIONS, wfResource);
    T2FlowParser parser = new T2FlowParser();
    parser.setValidating(true);
    parser.setStrict(false);
    WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream());
    assertEquals(4, wfBundle.getAnnotations().size());
    for (Annotation x : wfBundle.getAnnotations()) {
      System.out.println(x.getTarget());
//            System.out.println(x.getBodyStatements().get(0));
    }
    File f = File.createTempFile("annotation", ".wfbundle");
    System.err.println(f);
    new WorkflowBundleIO().writeBundle(wfBundle, f, "application/vnd.taverna.scufl2.workflow-bundle");
  }

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

@Test
public void setWorkflowBundle() throws Exception {
  WorkflowBundleIO wfBundleIO = new WorkflowBundleIO();
  WorkflowBundle wfBundle = wfBundleIO.createBundle();
  DataBundles.setWorkflowBundle(dataBundle, wfBundle);
  
  Path wf = DataBundles.getWorkflow(dataBundle);
  assertEquals("/workflow.wfbundle", wf.toString());        
  assertEquals("application/vnd.taverna.scufl2.workflow-bundle", 
      Files.probeContentType(wf));
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void setWriters() {
  WorkflowBundleWriter myWriter = new WorkflowBundleWriter() {
    @Override
    public Set<String> getMediaTypes() {
      return Collections.singleton("application/vnd.example.myOwn");
    }
    @Override
    public void writeBundle(WorkflowBundle wfBundle, File destination,
        String mediaType) {
    }
    @Override
    public void writeBundle(WorkflowBundle wfBundle,
        OutputStream output, String mediaType) {
    }
  };
  bundleIO.setWriters(Collections.singletonList(myWriter));
  assertEquals(1, bundleIO.getWriters().size());
  assertSame(myWriter, bundleIO.getWriters().get(0));
  assertSame(myWriter,
      bundleIO.getWriterForMediaType("application/vnd.example.myOwn"));
  // Should now be null
  assertNull(bundleIO
      .getWriterForMediaType(TEXT_VND_TAVERNA_SCUFL2_STRUCTURE));
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

bundleIO.setReaders(Arrays.asList(myReader));
assertEquals(null, bundleIO.guessMediaTypeForSignature(new byte[16]));
assertEquals("test/test", bundleIO.guessMediaTypeForSignature(new byte[4]));
bundleIO.setReaders(Arrays.asList(myReader, myReader));
assertEquals("test/test", bundleIO.guessMediaTypeForSignature(new byte[4]));		
bundleIO.setReaders(Arrays.asList(myReader, myReader, otherReader));
assertEquals(null, bundleIO.guessMediaTypeForSignature(new byte[4]));

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void guessMediaType() throws Exception {
  byte[] firstBytes = new byte[1024];
  getClass().getResourceAsStream(EXAMPLE_SCUFL2).read(firstBytes);        
  assertEquals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE, bundleIO.guessMediaTypeForSignature(firstBytes));
  // Mess up the mime type string
  firstBytes[45] = 32;
  assertEquals(null, bundleIO.guessMediaTypeForSignature(firstBytes));
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

WorkflowBundleWriter writer = getWriterForMediaType(mediaType);
if (writer == null)
  throw new IllegalArgumentException(

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

/**
 * Get the supported media types for reading.
 * <p>
 * Returned media types can be used with {@link #readBundle(File, String)},
 * {@link #readBundle(InputStream, String)} and/or
 * {@link #readBundle(URL, String)}.
 * 
 * @return A (usually sorted) set of media types
 */
public Set<String> getSupportedReaderMediaTypes() {
  Set<String> mediaTypes = new TreeSet<>();
  for (WorkflowBundleReader reader : getReaders())
    mediaTypes.addAll(reader.getMediaTypes());
  return mediaTypes;
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void getReaderForMediaType() throws Exception {
  WorkflowBundleReader Reader = bundleIO
  .getReaderForMediaType(TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  assertTrue(Reader instanceof StructureReader);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void createBundle() throws Exception {
  WorkflowBundle wb = bundleIO.createBundle();
  assertEquals(wb, wb.getMainWorkflow().getParent());
  assertEquals(wb, wb.getMainProfile().getParent());
  assertEquals("bundle1", wb.getName());
  assertEquals("workflow1", wb.getMainWorkflow().getName());
  assertEquals("profile1", wb.getMainProfile().getName());
  assertNotNull(wb.getCurrentRevision());
  assertNotNull(wb.getMainWorkflow().getCurrentRevision());
  assertNotNull(wb.getMainProfile().getCurrentRevision());
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-t2flow

@Test
public void readSimpleWorkflow() throws Exception {
  URL wfResource = getClass().getResource(AS_T2FLOW);
  assertNotNull("Could not find workflow " + AS_T2FLOW, wfResource);
  WorkflowBundle wfBundle = io.readBundle(wfResource,
      APPLICATION_VND_TAVERNA_T2FLOW_XML);
  Profile profile = wfBundle.getMainProfile();
  assertEquals(1, wfBundle.getProfiles().size());
  assertEquals(profile,
      wfBundle.getProfiles().getByName("taverna-2.1.0"));
  
  String report = IOUtils.toString(getClass().getResourceAsStream("/as.txt"));
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
  io.writeBundle(wfBundle, byteStream, StructureReader.TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
      String byteStreamTtoString = byteStream.toString("utf-8");
      report = report.replaceAll("\r", "").replaceAll("\n", "");
      byteStreamTtoString = byteStreamTtoString.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(report, byteStreamTtoString);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void writeBundleStream() throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(wfBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = new String(output.toByteArray(), UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

@Ignore
@Test
public void getWorkflowBundle() throws Exception {
  WorkflowBundleIO wfBundleIO = new WorkflowBundleIO();
  WorkflowBundle wfBundle = wfBundleIO.createBundle();
  
  String name = wfBundle.getName();
  String wfName = wfBundle.getMainWorkflow().getName();
  URI id = wfBundle.getIdentifier();
  
  DataBundles.setWorkflowBundle(dataBundle, wfBundle);
  // Reload the bundle
  wfBundle = DataBundles.getWorkflowBundle(dataBundle);        
  assertEquals(name, wfBundle.getName());
  assertEquals(wfName, wfBundle.getMainWorkflow().getName());        
  assertEquals(id, wfBundle.getIdentifier());        
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com