Ejemplo n.º 1
0
  /** Performs a type mapping for the {@code typeMap} and {@code context}. */
  <S, D> D typeMap(MappingContextImpl<S, D> context, TypeMap<S, D> typeMap) {
    context.setTypeMap(typeMap);
    if (context.getDestination() == null && Types.isInstantiable(context.getDestinationType())) {
      D destination = createDestination(context);
      if (destination == null) return null;
    }

    @SuppressWarnings("unchecked")
    Condition<S, D> condition = (Condition<S, D>) typeMap.getCondition();
    Converter<S, D> converter = typeMap.getConverter();
    if (condition == null || condition.applies(context)) {
      if (converter != null) return convert(context, converter);

      converter = typeMap.getPreConverter();
      if (converter != null) convert(context, converter);

      for (Mapping mapping : typeMap.getMappings()) propertyMap(mapping, context);

      converter = typeMap.getPostConverter();
      if (converter != null) convert(context, converter);
    }

    return context.getDestination();
  }