コード例 #1
0
  private Transformer<?, ?> getJavaFallbackTransformer(QName from, QName to) {
    Class<?> javaType = JavaService.toJavaMessageType(from);

    if (javaType == null) {
      return null;
    }

    Set<Map.Entry<NameKey, Transformer<?, ?>>> entrySet = _transformers.entrySet();
    List<JavaSourceFallbackTransformer> fallbackTransforms =
        new ArrayList<JavaSourceFallbackTransformer>();
    for (Map.Entry<NameKey, Transformer<?, ?>> entry : entrySet) {
      NameKey nameKey = entry.getKey();

      // "to" must be an exact match...
      if (nameKey.getTo().equals(to)) {
        if (JavaService.isJavaMessageType(nameKey.getFrom())) {
          Class<?> candidateType = JavaService.toJavaMessageType(nameKey.getFrom());
          if (candidateType != null && candidateType.isAssignableFrom(javaType)) {
            fallbackTransforms.add(
                new JavaSourceFallbackTransformer(candidateType, entry.getValue()));
          }
        }
      }
    }

    if (fallbackTransforms.size() == 0) {
      // No fallback...
      return null;
    }
    if (fallbackTransforms.size() == 1) {
      Transformer<?, ?> fallbackTransformer = fallbackTransforms.get(0)._transformer;
      addFallbackTransformer(fallbackTransformer, from, to);
      return fallbackTransformer;
    }

    try {
      JavaSourceFallbackTransformerComparator comparator =
          new JavaSourceFallbackTransformerComparator();
      Collections.sort(fallbackTransforms, comparator);

      // Closest super-type will be first in the list..
      Transformer<?, ?> fallbackTransformer = fallbackTransforms.get(0)._transformer;
      addFallbackTransformer(fallbackTransformer, from, to);
      return fallbackTransformer;
    } catch (MultipleFallbacks e) {
      _log.debug(
          "Cannot resolve fallback Transformer from '"
              + from
              + "' to '"
              + to
              + "'.  "
              + e.getMessage());
      return null;
    }
  }
コード例 #2
0
  @Override
  public Transformer<?, ?> getTransformer(QName from, QName to) {
    NameKey nameKey = new NameKey(from, to);
    Transformer<?, ?> transformer = _transformers.get(nameKey);

    if (transformer == null) {
      transformer = _fallbackTransformers.get(nameKey);
      if (transformer == null && JavaService.isJavaMessageType(from)) {
        transformer = getJavaFallbackTransformer(from, to);
      }
    }

    return transformer;
  }