private List processPortBinding()

in taverna-provenanceconnector/src/main/java/org/apache/taverna/provenance/lineageservice/EventProcessor.java [1157:1275]


	private List<PortBinding> processPortBinding(Element valueEl,
			String processorId, String portName, String collIdRef,
			int positionInCollection, String parentCollectionRef,
			String iterationId, String workflowRunId, String itVector,
			String currentWorkflowID) {
		List<PortBinding> newBindings = new ArrayList<>();

		String valueType = valueEl.getName();
		//		logger.info("value element for " + processorId + ": "
		//		+ valueType);

		String iterationVector = (itVector == null ? extractIterationVector(iterationId)
				: itVector);

		PortBinding vb = new PortBinding();

		vb.setWorkflowId(currentWorkflowID);
		vb.setWorkflowRunId(workflowRunId);
		vb.setProcessorName(processorId);
		vb.setValueType(valueType);
		vb.setPortName(portName);
		vb.setCollIDRef(collIdRef);
		vb.setPositionInColl(positionInCollection);

		newBindings.add(vb);

		if (valueType.equals("literal")) {
			try {
				vb.setIteration(iterationVector);
				vb.setValue(valueEl.getAttributeValue("id"));
				logger.debug("new input VB with workflowId="+currentWorkflowID+" processorId="+processorId+
						" valueType="+valueType+" portName="+portName+" collIdRef="+collIdRef+
						" position="+positionInCollection+" itvector="+iterationVector+
						" value="+vb.getValue());
				getPw().addPortBinding(vb);
			} catch (SQLException e) {
				logger.warn("Process Port Binding problem with provenance", e);
			}

		} else if (valueType.equals("referenceSet")) {
			vb.setIteration(iterationVector);
			vb.setValue(valueEl.getAttributeValue("id"));
			vb.setReference(valueEl.getChildText("reference"));

			logger.debug("new input VB with workflowId=" + currentWorkflowID
					+ " processorId=" + processorId + " valueType=" + valueType
					+ " portName=" + portName + " collIdRef=" + collIdRef
					+ " position=" + positionInCollection + " itvector="
					+ iterationVector + " value=" + vb.getValue());

			try {
				getPw().addPortBinding(vb);
			} catch (SQLException e) {
				logger.debug("Problem processing var binding -- performing update instead of insert", e); //, e);
				// try to update the existing record instead using the current collection info

				getPw().updatePortBinding(vb);
			}

		} else if (valueType.equals("list")) {
			logger.debug("input of type list");

			// add entries to the Collection and to the PortBinding tables
			// list id --> Collection.collId

			String collId = valueEl.getAttributeValue("id");
			try {
				parentCollectionRef = getPw().addCollection(processorId, collId,
						parentCollectionRef, iterationVector, portName,
						workflowRunId);

				// iterate over each list element
				List<Element> listElements = valueEl.getChildren();

				positionInCollection = 1;  // also use this as a suffix to extend the iteration vector

				// extend iteration vector to account for additional levels within the list

				String originalIterationVector = iterationVector;

				// children can be any base type, including list itself -- so
				// use recursion
				for (Element el : listElements) {
					if (originalIterationVector.length() > 2) // vector is not empty
						iterationVector = originalIterationVector.substring(0,
								originalIterationVector.length()-1) + ","+
								Integer.toString(positionInCollection-1) + "]";
					else
						iterationVector = "["+ (positionInCollection-1) + "]";

					newBindings.addAll(processPortBinding(el, processorId,
							portName, collId, positionInCollection,
							parentCollectionRef, iterationId, workflowRunId,
							iterationVector, currentWorkflowID));

					positionInCollection++;
				}
			} catch (SQLException e) {
				logger.warn("Problem processing var binding", e);
			}
		} else if (valueType.equals("error")) {
			vb.setIteration(iterationVector);
			vb.setValue(valueEl.getAttributeValue("id"));
			vb.setReference(valueEl.getChildText("reference"));
			try {
				getPw().addPortBinding(vb);
			} catch (SQLException e) {
				logger.debug("Problem processing var binding -- performing update instead of insert", e); //, e);
				// try to update the existing record instead using the current collection info

				getPw().updatePortBinding(vb);
			}
		} else {
			logger.warn("unrecognized value type element for "
					+ processorId + ": " + valueType);
		}

		return newBindings;
	}