public WorkflowBundle readWorkflowBundle()

in taverna-scufl2-wfbundle/src/main/java/org/apache/taverna/scufl2/rdfxml/WorkflowBundleParser.java [192:259]


	public WorkflowBundle readWorkflowBundle(UCFPackage ucfPackage,
			URI suggestedLocation) throws IOException, ReaderException {
		try {
			getParserState().setUcfPackage(ucfPackage);
			getParserState().setLocation(suggestedLocation);
			if (getParserState().getLocation() == null) {
				getParserState().setLocation(URI.create(""));
			} else if (!getParserState().getLocation().getRawPath()
					.endsWith("/")) {
				if (getParserState().getLocation().getQuery() != null
						|| getParserState().getLocation().getFragment() != null)
					/*
					 * Ouch.. Perhaps some silly website with ?bundleId=15 ?
					 * We'll better conserve that somehow. Let's do the jar:
					 * trick and hope it works. Have to escape evil chars.
					 */
					getParserState().setLocation(
							URI.create("jar:"
									+ getParserState().getLocation()
									.toASCIIString()
									.replace("?", "%63")
									.replace("#", "#35") + "!/"));
				else
					/*
					 * Simple, pretend we're one level down inside the ZIP file
					 * as a directory
					 */
					getParserState().setLocation(
							getParserState().getLocation().resolve(
									getParserState().getLocation().getRawPath()
											+ "/"));
			}
			String workflowBundlePath = findWorkflowBundlePath();

			InputStream bundleStream = getParserState().getUcfPackage()
					.getResourceAsInputStream(workflowBundlePath);

			JAXBElement<WorkflowBundleDocument> elem;
			try {
				elem = (JAXBElement<WorkflowBundleDocument>) unmarshaller
						.unmarshal(bundleStream);
			} catch (JAXBException e) {
				throw new ReaderException(
						"Can't parse workflow bundle document "
								+ workflowBundlePath, e);
			}
			WorkflowBundleDocument workflowBundleDocument = elem.getValue();

			URI base = getParserState().getLocation().resolve(
					workflowBundlePath);
			if (workflowBundleDocument.getBase() != null)
				base = getParserState().getLocation().resolve(
						workflowBundleDocument.getBase());

			if (workflowBundleDocument.getAny().size() != 1)
				throw new ReaderException(
						"Invalid WorkflowBundleDocument, expected only one <WorkflowBundle>");

			org.apache.taverna.scufl2.xml.WorkflowBundle wb = (org.apache.taverna.scufl2.xml.WorkflowBundle) workflowBundleDocument
					.getAny().get(0);
			WorkflowBundle workflowBundle = parseWorkflowBundle(wb, base);

			scufl2Tools.setParents(workflowBundle);
			return workflowBundle;
		} finally {
			clearParserState();
		}
	}