/** * Inject a list containing all known implementations of ExternalReferenceTranslatorSPI. * * @throws IllegalStateException * if this has already been set, the instance registries should only be set on bean * construction. */ public synchronized void setTranslators(List<ExternalReferenceTranslatorSPI<?, ?>> translators) { if (this.translators == null) { this.translators = translators; log.debug("* Translators injected :"); int counter = 0; for (ExternalReferenceTranslatorSPI<?, ?> translator : translators) { log.debug("* " + (++counter) + ") " + translator.getClass().getSimpleName() + ", translates " + translator.getSourceReferenceType().getSimpleName() + " to " + translator.getTargetReferenceType().getSimpleName()); } cacheValid = false; } else { log.error("Translator registry already injected, invalid operation"); throw new IllegalStateException("Can't inject the translator registry multiple times."); } }
/** * Return a human readable representation of this translation path, used by the logging * methods to print trace information. */ @SuppressWarnings("unchecked") @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append(getPathCost() + " "); if (sourceReference != null && initialBuilder != null) { sb.append(sourceReference.toString() + "->bytes(" + sourceReference.getResolutionCost() + ")->"); String builderClassName = initialBuilder.getClass().getSimpleName(); String builtType = initialBuilder.getReferenceType().getSimpleName(); sb.append("builder:" + builderClassName + "(" + initialBuilder.getConstructionCost() + "):<" + builtType + ">"); } else if (translators.isEmpty() == false) { sb.append("<" + translators.get(0).getSourceReferenceType().getSimpleName() + ">"); } for (ExternalReferenceTranslatorSPI translator : translators) { sb.append("-" + translator.getClass().getSimpleName() + "(" + translator.getTranslationCost() + ")" + "-"); sb.append("<" + translator.getTargetReferenceType().getSimpleName() + ">"); } return sb.toString(); }
@SuppressWarnings("unchecked") private void relaxNeighbours(Class<ExternalReferenceSPI> u) { log.trace("# relaxing node " + u.getSimpleName()); Set<Class<ExternalReferenceSPI>> alreadySeen = new HashSet<Class<ExternalReferenceSPI>>(); for (ExternalReferenceTranslatorSPI ert : getNeighbours(u)) { // all the translators that translate *to* u Class<ExternalReferenceSPI> v = ert.getSourceReferenceType(); log.trace("# translator found from from '" + v + "' : " + ert.getClass().getSimpleName()); if (alreadySeen.contains(v) == false && isSettled(v) == false) { // Avoid duplicate edges, always take the first one where // such duplicates exist alreadySeen.add(v); if (getShortestDistance(v) > getShortestDistance(u) + ert.getTranslationCost()) { setShortestDistance(v, getShortestDistance(u) + ert.getTranslationCost()); setPredecessor(v, u, ert); unsettledNodes.add(v); } } } }
translators.get(0).getSourceReferenceType())) { currentReference = er; break; for (ExternalReferenceTranslatorSPI translator : translators) { ExternalReferenceSPI translatedReference = translator .createReference(currentReference, context); results.add(translatedReference); currentReference = translatedReference;
public Class<? extends ExternalReferenceSPI> getSourceType() { if (translators.isEmpty() == false) { return translators.get(0).getSourceReferenceType(); } else if (this.sourceReference != null) { return this.sourceReference.getClass(); } else { return null; } }
public Class<? extends ExternalReferenceSPI> getTargetType() { if (translators.isEmpty() == false) { return translators.get(translators.size() - 1) .getTargetReferenceType(); } else if (this.initialBuilder != null) { return this.initialBuilder.getReferenceType(); } else { return null; } }
/** * Sum of translation costs of all translators in path */ public float getPathCost() { float cost = 0.0f; for (ExternalReferenceTranslatorSPI<?, ?> ert : this) { cost += ert.getTranslationCost(); } // If the source reference and initial builder are non-null then // we're going to start this translation path by downloading a byte // stream from the specified (current) reference and using it to // construct the starting point for the translation path via the // specified builder. if (sourceReference != null) { cost += sourceReference.getResolutionCost(); } if (initialBuilder != null) { cost += initialBuilder.getConstructionCost(); } return cost; }
} else if (translators.isEmpty() == false) { sb.append("<" + translators.get(0).getSourceReferenceType() .getSimpleName() + ">"); + translator.getTranslationCost() + ")" + "-"); sb.append("<" + translator.getTargetReferenceType().getSimpleName() + ">");
@SuppressWarnings("unchecked") private void relaxNeighbours(Class<ExternalReferenceSPI> u) { log.trace("# relaxing node " + u.getSimpleName()); Set<Class<ExternalReferenceSPI>> alreadySeen = new HashSet<Class<ExternalReferenceSPI>>(); for (ExternalReferenceTranslatorSPI ert : getNeighbours(u)) { // all the translators that translate *to* u Class<ExternalReferenceSPI> v = ert.getSourceReferenceType(); log.trace("# translator found from from '" + v + "' : " + ert.getClass().getSimpleName()); if (alreadySeen.contains(v) == false && isSettled(v) == false) { // Avoid duplicate edges, always take the first one where // such duplicates exist alreadySeen.add(v); if (getShortestDistance(v) > getShortestDistance(u) + ert.getTranslationCost()) { setShortestDistance(v, getShortestDistance(u) + ert.getTranslationCost()); setPredecessor(v, u, ert); unsettledNodes.add(v); } } } }
translators.get(0).getSourceReferenceType())) { currentReference = er; break; for (ExternalReferenceTranslatorSPI translator : translators) { ExternalReferenceSPI translatedReference = translator .createReference(currentReference, context); results.add(translatedReference); currentReference = translatedReference;
public Class<? extends ExternalReferenceSPI> getSourceType() { if (translators.isEmpty() == false) { return translators.get(0).getSourceReferenceType(); } else if (this.sourceReference != null) { return this.sourceReference.getClass(); } else { return null; } }
public Class<? extends ExternalReferenceSPI> getTargetType() { if (translators.isEmpty() == false) { return translators.get(translators.size() - 1) .getTargetReferenceType(); } else if (this.initialBuilder != null) { return this.initialBuilder.getReferenceType(); } else { return null; } }
/** * Sum of translation costs of all translators in path */ public float getPathCost() { float cost = 0.0f; for (ExternalReferenceTranslatorSPI<?, ?> ert : this) { cost += ert.getTranslationCost(); } // If the source reference and initial builder are non-null then // we're going to start this translation path by downloading a byte // stream from the specified (current) reference and using it to // construct the starting point for the translation path via the // specified builder. if (sourceReference != null) { cost += sourceReference.getResolutionCost(); } if (initialBuilder != null) { cost += initialBuilder.getConstructionCost(); } return cost; }
} else if (translators.isEmpty() == false) { sb.append("<" + translators.get(0).getSourceReferenceType() .getSimpleName() + ">"); + translator.getTranslationCost() + ")" + "-"); sb.append("<" + translator.getTargetReferenceType().getSimpleName() + ">");
+ translator.getClass().getSimpleName() + ", translates " + translator.getSourceReferenceType().getSimpleName() + " to " + translator.getTargetReferenceType().getSimpleName());
@SuppressWarnings("unchecked") private void relaxNeighbours(Class<ExternalReferenceSPI> u) { log.trace("# relaxing node " + u.getSimpleName()); Set<Class<ExternalReferenceSPI>> alreadySeen = new HashSet<Class<ExternalReferenceSPI>>(); for (ExternalReferenceTranslatorSPI ert : getNeighbours(u)) { // all the translators that translate *to* u Class<ExternalReferenceSPI> v = ert.getSourceReferenceType(); log.trace("# translator found from from '" + v + "' : " + ert.getClass().getSimpleName()); if (alreadySeen.contains(v) == false && isSettled(v) == false) { // Avoid duplicate edges, always take the first one where // such duplicates exist alreadySeen.add(v); if (getShortestDistance(v) > getShortestDistance(u) + ert.getTranslationCost()) { setShortestDistance(v, getShortestDistance(u) + ert.getTranslationCost()); setPredecessor(v, u, ert); unsettledNodes.add(v); } } } }
if (er.getClass().equals(translators.get(0).getSourceReferenceType())) { currentReference = er; break; } else { for (ExternalReferenceTranslatorSPI translator : translators) { ExternalReferenceSPI translatedReference = translator.createReference( currentReference, context); results.add(translatedReference);
public Class<? extends ExternalReferenceSPI> getSourceType() { if (translators.isEmpty() == false) { return translators.get(0).getSourceReferenceType(); } else if (this.sourceReference != null) { return this.sourceReference.getClass(); } else { return null; } }
public Class<? extends ExternalReferenceSPI> getTargetType() { if (translators.isEmpty() == false) { return translators.get(translators.size() - 1).getTargetReferenceType(); } else if (this.initialBuilder != null) { return this.initialBuilder.getReferenceType(); } else { return null; } }
/** * Sum of translation costs of all translators in path */ public float getPathCost() { float cost = 0.0f; for (ExternalReferenceTranslatorSPI<?, ?> ert : this) { cost += ert.getTranslationCost(); } // If the source reference and initial builder are non-null then // we're going to start this translation path by downloading a byte // stream from the specified (current) reference and using it to // construct the starting point for the translation path via the // specified builder. if (sourceReference != null) { cost += sourceReference.getResolutionCost(); } if (initialBuilder != null) { cost += initialBuilder.getConstructionCost(); } return cost; }