예제 #1
0
  @SuppressWarnings("unchecked")
  private <S, D> void propertyMap(Mapping mapping, MappingContextImpl<S, D> context) {
    MappingImpl mappingImpl = (MappingImpl) mapping;
    if (context.isShaded(mappingImpl.getPath())) return;

    Condition<Object, Object> condition = (Condition<Object, Object>) mapping.getCondition();
    if (condition == null)
      condition = (Condition<Object, Object>) context.getTypeMap().getPropertyCondition();
    if (condition == null && mapping.isSkipped()) return;

    Object source = resolveSourceValue(context, mapping);
    MappingContextImpl<Object, Object> propertyContext =
        propertyContextFor(context, source, mapping);

    if (condition != null) {
      if (!condition.applies(propertyContext)) {
        context.shadePath(mappingImpl.getPath());
        return;
      } else if (mapping.isSkipped()) return;
    }

    Converter<Object, Object> converter = (Converter<Object, Object>) mapping.getConverter();
    if (converter == null)
      converter = (Converter<Object, Object>) context.getTypeMap().getPropertyConverter();
    if (converter != null) context.shadePath(mappingImpl.getPath());
    else if (mapping instanceof SourceMapping) return;

    // Create destination for property context prior to mapping/conversion
    createDestinationViaProvider(propertyContext);

    // Set mapped/converted destination value
    setDestinationValue(context, propertyContext, mappingImpl, converter);
  }
예제 #2
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eUnset(int featureID) {
   switch (featureID) {
     case MappingPackage.MAPPING_ROOT__OUTPUT_READ_ONLY:
       setOutputReadOnly(OUTPUT_READ_ONLY_EDEFAULT);
       return;
     case MappingPackage.MAPPING_ROOT__TOP_TO_BOTTOM:
       setTopToBottom(TOP_TO_BOTTOM_EDEFAULT);
       return;
     case MappingPackage.MAPPING_ROOT__COMMAND_STACK:
       setCommandStack(COMMAND_STACK_EDEFAULT);
       return;
   }
   super.eUnset(featureID);
 }
예제 #3
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void eSet(int featureID, Object newValue) {
   switch (featureID) {
     case MappingPackage.MAPPING_ROOT__OUTPUT_READ_ONLY:
       setOutputReadOnly((Boolean) newValue);
       return;
     case MappingPackage.MAPPING_ROOT__TOP_TO_BOTTOM:
       setTopToBottom((Boolean) newValue);
       return;
     case MappingPackage.MAPPING_ROOT__COMMAND_STACK:
       setCommandStack((String) newValue);
       return;
   }
   super.eSet(featureID, newValue);
 }
예제 #4
0
  /**
   * Sets a mapped or converted destination value in the last mapped mutator for the given {@code
   * mapping}. The final destination value is resolved by walking the {@code mapping}'s mutator
   * chain and obtaining each destination value in the chain either from the cache, from a
   * corresponding accessor, from a provider, or by instantiation, in that order.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void setDestinationValue(
      MappingContextImpl<?, ?> context,
      MappingContextImpl<Object, Object> propertyContext,
      MappingImpl mapping,
      Converter<Object, Object> converter) {
    Object destination = context.getDestination();
    List<Mutator> mutatorChain = (List<Mutator>) mapping.getDestinationProperties();
    StringBuilder destPathBuilder = new StringBuilder();

    for (int i = 0; i < mutatorChain.size(); i++) {
      Mutator mutator = mutatorChain.get(i);
      destPathBuilder.append(mutator.getName()).append('.');
      String destPath = destPathBuilder.toString();

      // Handle last mutator in chain
      if (i == mutatorChain.size() - 1) {
        // Final destination value
        Object destinationValue = null;

        if (converter != null) {
          // Obtain from accessor on provided destination
          if (context.providedDestination) {
            Accessor accessor =
                TypeInfoRegistry.typeInfoFor(destination.getClass(), configuration)
                    .getAccessors()
                    .get(mutator.getName());
            if (accessor != null) {
              Object intermediateDest = accessor.getValue(destination);
              propertyContext.setDestination(intermediateDest);
            }
          }

          destinationValue = convert(propertyContext, converter);
        } else if (propertyContext.getSource() != null) destinationValue = map(propertyContext);

        context.destinationCache.put(destPath, destinationValue);
        mutator.setValue(
            destination,
            destinationValue == null
                ? Primitives.defaultValue(mutator.getType())
                : destinationValue);
        if (destinationValue == null) context.shadePath(mapping.getPath());
      } else {
        // Obtain from cache
        Object intermediateDest = context.destinationCache.get(destPath);

        if (intermediateDest != null) {
          mutator.setValue(destination, intermediateDest);
        } else {
          // Obtain from circular destinations
          if (!context.intermediateDestinations.isEmpty()) {
            for (Object intermediateDestination : context.intermediateDestinations) {
              // Match intermediate destinations to mutator by type
              if (intermediateDestination.getClass().equals(mutator.getType())) {
                intermediateDest = intermediateDestination;
                mutator.setValue(destination, intermediateDest);
                break;
              }
            }
          }

          if (intermediateDest == null) {
            // Obtain from accessor on provided destination
            if (context.providedDestination) {
              Accessor accessor =
                  TypeInfoRegistry.typeInfoFor(destination.getClass(), configuration)
                      .getAccessors()
                      .get(mutator.getName());
              if (accessor != null) intermediateDest = accessor.getValue(destination);
            }

            // Obtain from new instance
            if (intermediateDest == null) {
              if (propertyContext.getSource() == null) return;

              Provider<?> globalProvider = configuration.getProvider();
              if (globalProvider != null)
                intermediateDest =
                    globalProvider.get(
                        new ProvisionRequestImpl(context.parentSource(), mutator.getType()));
              else intermediateDest = instantiate(mutator.getType(), context.errors);
              if (intermediateDest == null) return;

              mutator.setValue(destination, intermediateDest);
            }
          }

          context.destinationCache.put(destPath, intermediateDest);
        }

        destination = intermediateDest;
      }
    }
  }