protected UCFPackage makeUCFPackage()

in taverna-scufl2-wfbundle/src/main/java/org/apache/taverna/scufl2/rdfxml/RDFXMLWriter.java [84:141]


	protected UCFPackage makeUCFPackage(WorkflowBundle wfBundle)
			throws IOException, WriterException {
		//UCFPackage ucfPackage = new UCFPackage();
		UCFPackage ucfPackage = wfBundle.getResources();		
		if (ucfPackage.getPackageMediaType() == null)
			ucfPackage
				.setPackageMediaType(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);

		RDFXMLSerializer serializer = new RDFXMLSerializer(wfBundle);
		
		for (Workflow wf : wfBundle.getWorkflows()) {
			String path = WORKFLOW + uriTools.validFilename(wf.getName()) + RDF;

			try (OutputStream outputStream = ucfPackage
					.addResourceUsingOutputStream(path, APPLICATION_RDF_XML)) {
				serializer.workflowDoc(outputStream, wf, URI.create(path));
			} catch (JAXBException e) {
				throw new WriterException("Can't generate " + path, e);
			}
			
			path = HISTORY + WF +  
					uriTools.validFilename(wf.getName()) + REVISIONS + RDF;
			addRevisions(wf, path, wfBundle);
		}

		for (Profile pf : wfBundle.getProfiles()) {
			String path = PROFILE + uriTools.validFilename(pf.getName()) + RDF;
			try (OutputStream outputStream = ucfPackage
					.addResourceUsingOutputStream(path, APPLICATION_RDF_XML)) {
				serializer.profileDoc(outputStream, pf, URI.create(path));
			} catch (JAXBException e) {
				throw new WriterException("Can't generate " + path, e);
			}
			path = HISTORY + "pf-" +  
					uriTools.validFilename(pf.getName()) + REVISIONS + RDF;
			addRevisions(pf, path, wfBundle);
		}

		try (OutputStream outputStream = ucfPackage
				.addResourceUsingOutputStream(WORKFLOW_BUNDLE_RDF,
						APPLICATION_RDF_XML)) {
			serializer.workflowBundleDoc(outputStream,
					URI.create(WORKFLOW_BUNDLE_RDF));
		} catch (JAXBException e) {
			throw new WriterException("Can't generate " + WORKFLOW_BUNDLE_RDF,
					e);
		}
		
		if (ucfPackage.getPackageMediaType().equals(
				APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE))
			ucfPackage
					.setRootFile(WORKFLOW_BUNDLE_RDF, WORKFLOW_BUNDLE_VERSION);

		String path = HISTORY + "wfbundle" + REVISIONS + RDF;
		addRevisions(wfBundle, path, wfBundle);
		
		return ucfPackage;
	}