private void assignNamesTo()

in taverna-workflowmodel-impl/src/main/java/org/apache/taverna/workflowmodel/impl/AbstractCrystalizer.java [127:191]


		private void assignNamesTo(NamedNode n, int[] index) {
			/* Only act if contents of this node undefined */
			if (n.contents != null)
				return;

			Map<String, List<T2Reference>> listItems = new HashMap<>();
			int pos = 0;
			for (NamedNode child : n.children) {
				/*
				 * If child doesn't have a defined name map yet then define it.
				 */
				Job j;
				if (child == null) {
					/*
					 * happens if we're completing a partially empty collection
					 * structure
					 */
					int[] newIndex = new int[index.length + 1];
					for (int i = 0; i < index.length; i++)
						newIndex[i] = index[i];
					newIndex[index.length] = pos++;
					j = getEmptyJob(owningProcess, newIndex, context);
					jobCreated(j);
				} else if (child.contents == null) {
					int[] newIndex = new int[index.length + 1];
					for (int i = 0; i < index.length; i++)
						newIndex[i] = index[i];
					newIndex[index.length] = pos++;
					assignNamesTo(child, newIndex);
					j = child.contents;
				} else {
					pos++;
					j = child.contents;
				}

				/*
				 * Now pull the names out of the child job map and push them
				 * into lists to be registered
				 */

				for (String outputName : j.getData().keySet()) {
					List<T2Reference> items = listItems.get(outputName);
					if (items == null) {
						items = new ArrayList<>();
						listItems.put(outputName, items);
					}
					items.add(j.getData().get(outputName));
				}
			}
			Map<String, T2Reference> newDataMap = new HashMap<>();
			for (String outputName : listItems.keySet())
				newDataMap.put(
						outputName,
						context.getReferenceService()
								.getListService()
								.registerList(listItems.get(outputName),
										context).getId());
			Job newJob = new Job(owningProcess, index, newDataMap, context);
			n.contents = newJob;

			/* Get rid of the children as we've now named this node */

			n.children.clear();
			jobCreated(n.contents);
		}