public Iterator traverseFrom()

in taverna-reference-impl/src/main/java/org/apache/taverna/reference/impl/ReferenceServiceImpl.java [557:598]


	public Iterator<ContextualizedT2Reference> traverseFrom(T2Reference source,
			int desiredDepth) throws ReferenceServiceException {
		checkServices();
		if (desiredDepth < 0)
			throw new ReferenceServiceException(
					"Cannot traverse to a negative depth");
		List<ContextualizedT2Reference> workingSet = new ArrayList<>();
		workingSet.add(new ContextualizedT2ReferenceImpl(source, new int[0]));
		int currentDepth = source.getDepth();
		while (currentDepth > desiredDepth) {
			List<ContextualizedT2Reference> newSet = new ArrayList<>();
			for (ContextualizedT2Reference ci : workingSet) {
				T2ReferenceImpl ref = (T2ReferenceImpl) ci.getReference();
				switch (ref.getReferenceType()) {
				case IdentifiedList:
					try {
						int position = 0;
						for (T2Reference child : getListService().getList(ref))
							newSet.add(new ContextualizedT2ReferenceImpl(child,
									addIndex(ci.getIndex(), position++)));
					} catch (ListServiceException lse) {
						throw new ReferenceServiceException(lse);
					}
					break;
				case ReferenceSet:
					throw new ReferenceServiceException(
							"Should never be trying to drill inside a data document identifier");
				case ErrorDocument:
					newSet.add(new ContextualizedT2ReferenceImpl(ref
							.getDeeperErrorReference(), addIndex(ci.getIndex(),
							0)));
					break;
				default:
					throw new ReferenceServiceException(
							"Fallen off end of case statement, unknown reference type!");
				}
			}
			currentDepth--;
			workingSet = newSet;
		}
		return workingSet.iterator();
	}