public static Workflow buildFromXML()

in taverna-perspective-myexperiment/src/main/java/org/apache/taverna/ui/perspectives/myexperiment/model/Workflow.java [244:434]


  public static Workflow buildFromXML(Element docRootElement, Logger logger) {
	// return null to indicate an error if XML document contains no root element
	if (docRootElement == null)
	  return (null);

	Workflow w = new Workflow();

	try {
	  // Access type
	  w.setAccessType(Util.getAccessTypeFromXMLElement(docRootElement.getChild("privileges")));

	  // URI
	  w.setURI(docRootElement.getAttributeValue("uri"));

	  // Resource URI
	  w.setResource(docRootElement.getAttributeValue("resource"));

	  // Version
	  String version = docRootElement.getAttributeValue("version");
	  if (version != null && !version.equals("")) {
		w.setVersion(Integer.parseInt(version));
	  }

	  // Id
	  String id = docRootElement.getChildText("id");
	  if (id == null || id.equals("")) {
		id = "API Error - No workflow ID supplied";
		logger.error("Error while parsing workflow XML data - no ID provided for workflow with title: \""
			+ docRootElement.getChildText("title") + "\"");
	  }
	  w.setID(id);

	  // Title
	  w.setTitle(docRootElement.getChildText("title"));

	  // Description
	  w.setDescription(docRootElement.getChildText("description"));

	  // Uploader
	  Element uploaderElement = docRootElement.getChild("uploader");
	  w.setUploader(Util.instantiatePrimitiveUserFromElement(uploaderElement));

	  // Created at
	  String createdAt = docRootElement.getChildText("created-at");
	  if (createdAt != null && !createdAt.equals("")) {
		w.setCreatedAt(MyExperimentClient.parseDate(createdAt));
	  }

	  // Updated at
	  String updatedAt = docRootElement.getChildText("updated-at");
	  if (updatedAt != null && !updatedAt.equals("")) {
		w.setUpdatedAt(MyExperimentClient.parseDate(updatedAt));
	  }

	  // Preview
	  String preview = docRootElement.getChildText("preview");
	  if (preview != null && !preview.equals("")) {
		w.setPreview(new URI(preview));
	  }

	  // Thumbnail
	  String thumbnail = docRootElement.getChildText("thumbnail");
	  if (thumbnail != null && !thumbnail.equals("")) {
		w.setThumbnail(new URI(thumbnail));
	  }

	  // Thumbnail (big)
	  String thumbnailBig = docRootElement.getChildText("thumbnail-big");
	  if (thumbnailBig != null && !thumbnailBig.equals("")) {
		w.setThumbnailBig(new URI(thumbnailBig));
	  }

	  // SVG
	  String svg = docRootElement.getChildText("svg");
	  if (svg != null && !svg.equals("")) {
		w.setSvg(new URI(svg));
	  }

	  // License
	  w.setLicense(License.getInstance(docRootElement.getChildText("license-type")));

	  // Content URI
	  String contentUri = docRootElement.getChildText("content-uri");
	  if (contentUri != null && !contentUri.equals("")) {
		w.setContentUri(new URI(contentUri));
	  }

	  // Type and Content-Type
	  w.setVisibleType(docRootElement.getChildText("type"));
	  w.setContentType(docRootElement.getChildText("content-type"));

	  // Tags
	  w.tags = new ArrayList<Tag>();
	  w.tags.addAll(Util.retrieveTags(docRootElement));

	  // Comments
	  w.comments = new ArrayList<Comment>();
	  w.getComments().addAll(Util.retrieveComments(docRootElement, w));

	  // Credits
	  w.credits = new ArrayList<Resource>();
	  w.getCredits().addAll(Util.retrieveCredits(docRootElement));

	  // Attributions
	  w.attributions = new ArrayList<Resource>();
	  w.getAttributions().addAll(Util.retrieveAttributions(docRootElement));

	  // Components
	  w.components = new HashMap<String, ArrayList<HashMap<String, String>>>();

	  Element componentsElement = docRootElement.getChild("components");
	  if (componentsElement != null) {
		// ** inputs **
		Element sourcesElement = componentsElement.getChild("sources");
		if (sourcesElement != null) {
		  ArrayList<HashMap<String, String>> inputs = new ArrayList<HashMap<String, String>>();
		  List<Element> sourcesNodes = sourcesElement.getChildren();
		  for (Element e : sourcesNodes) {
			HashMap<String, String> curInput = new HashMap<String, String>();
			curInput.put("name", e.getChildText("name"));
			curInput.put("description", e.getChildText("description"));
			inputs.add(curInput);
		  }

		  // put all inputs that were found into the overall component collection
		  w.getComponents().put("inputs", inputs);
		}

		// ** outputs **
		Element outputsElement = componentsElement.getChild("sinks");
		if (outputsElement != null) {
		  ArrayList<HashMap<String, String>> sinks = new ArrayList<HashMap<String, String>>();
		  List<Element> outputsNodes = outputsElement.getChildren();
		  for (Element e : outputsNodes) {
			HashMap<String, String> curOutput = new HashMap<String, String>();
			curOutput.put("name", e.getChildText("name"));
			curOutput.put("description", e.getChildText("description"));
			sinks.add(curOutput);
		  }

		  // put all outputs that were found into the overall component collection
		  w.getComponents().put("outputs", sinks);
		}

		// ** processors **
		Element processorsElement = componentsElement.getChild("processors");
		if (processorsElement != null) {
		  ArrayList<HashMap<String, String>> processors = new ArrayList<HashMap<String, String>>();
		  List<Element> processorsNodes = processorsElement.getChildren();
		  for (Element e : processorsNodes) {
			HashMap<String, String> curProcessor = new HashMap<String, String>();
			curProcessor.put("name", e.getChildText("name"));
			curProcessor.put("type", e.getChildText("type"));
			curProcessor.put("description", e.getChildText("description"));
			processors.add(curProcessor);
		  }

		  // put all processors that were found into the overall component collection
		  w.getComponents().put("processors", processors);
		}

		// ** links **
		Element linksElement = componentsElement.getChild("links");
		if (linksElement != null) {
		  ArrayList<HashMap<String, String>> links = new ArrayList<HashMap<String, String>>();
		  List<Element> linksNodes = linksElement.getChildren();
		  for (Element e : linksNodes) {
			HashMap<String, String> curLink = new HashMap<String, String>();
			String strSource = e.getChild("source").getChildText("node")
				+ (e.getChild("source").getChildText("port") == null ? "" : (":" + e.getChild("source").getChildText("port")));
			curLink.put("source", strSource);
			String strSink = e.getChild("sink").getChildText("node")
				+ (e.getChild("sink").getChildText("port") == null ? "" : (":" + e.getChild("sink").getChildText("port")));
			curLink.put("sink", strSink);
			links.add(curLink);
		  }

		  // put all links that were found into the overall component collection
		  w.getComponents().put("links", links);
		}
	  }

	  logger.debug("Found information for worklow with ID: " + w.getID()
		  + ", Title: " + w.getTitle());
	} catch (Exception e) {
	  logger.error("Failed midway through creating workflow object from XML", e);
	}

	// return created workflow instance
	return (w);
  }