in taverna-reference-impl/src/main/java/org/apache/taverna/reference/impl/TranslationPath.java [87:130]
public Set<ExternalReferenceSPI> doTranslation(ReferenceSet rs,
ReferenceContext context) {
Set<ExternalReferenceSPI> results = new HashSet<>();
/*
* Firstly check whether we have an initial reference and builder
* defined
*/
ExternalReferenceSPI currentReference = null;
if (getInitialBuilder() != null && getSourceReference() != null)
try (InputStream stream = getSourceReference().openStream(context)) {
ExternalReferenceSPI builtReference = getInitialBuilder()
.createReference(stream, context);
results.add(builtReference);
currentReference = builtReference;
} catch (IOException e) {
throw new DereferenceException(
"Can't create reference from stream", e);
}
if (!getTranslators().isEmpty() && currentReference == null)
/*
* If there are translators in the path (there may not be if this is
* a pure 'dereference and build' type path) and the
* currentReference hasn't been set then search the existing
* references for an appropriate starting point for the translation.
*/
for (ExternalReferenceSPI er : rs.getExternalReferences())
if (er.getClass().equals(
getTranslators().get(0).getSourceReferenceType())) {
currentReference = er;
break;
}
if (currentReference == null)
throw new RuntimeException(
"Can't locate a starting reference for the"
+ " translation path");
for (ExternalReferenceTranslatorSPI translator : getTranslators()) {
ExternalReferenceSPI translatedReference = translator
.createReference(currentReference, context);
results.add(translatedReference);
currentReference = translatedReference;
}
return results;
}