コード例 #1
0
  /** Returns a property context. */
  @SuppressWarnings({"rawtypes", "unchecked"})
  private MappingContextImpl<Object, Object> propertyContextFor(
      MappingContextImpl<?, ?> context, Object source, Mapping mapping) {
    Class<?> sourceType;
    boolean cyclic = false;

    if (mapping instanceof PropertyMapping) {
      PropertyMappingImpl propertyMapping = (PropertyMappingImpl) mapping;
      sourceType = propertyMapping.getLastSourceProperty().getType();
      cyclic = propertyMapping.cyclic;
    } else if (mapping instanceof ConstantMapping) {
      Object constant = ((ConstantMapping) mapping).getConstant();
      sourceType = constant == null ? Object.class : Types.deProxy(constant.getClass());
    } else {
      sourceType = ((SourceMapping) mapping).getSourceType();
    }

    Class<Object> destinationType = (Class<Object>) mapping.getLastDestinationProperty().getType();
    return new MappingContextImpl(
        context, source, sourceType, null, destinationType, null, mapping, !cyclic);
  }
コード例 #2
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();
  }