/**
  * @param mapping
  * @param source
  * @return The supplied mapping if it remains incomplete, else a new mapping mapped via the
  *     delegate
  */
 public MappingOperation<?, ?> setSource(
     final MappingOperation<?, ?> mapping, final Object source) {
   if (mapping.getType() == null) {
     ((MappingPlaceholder) mapping).setSource(source);
   }
   return update(mapping, source, (Model) mapping.getTarget(), MAPPING_SOURCE);
 }
 /**
  * @param mapping
  * @param target
  * @return The supplied mapping if it remains incomplete, else a new mapping mapped via the
  *     delegate
  */
 public MappingOperation<?, ?> setTarget(
     final MappingOperation<?, ?> mapping, final Model target) {
   if (mapping.getType() == null) {
     ((MappingPlaceholder) mapping).setTarget(target);
   }
   return update(mapping, mapping.getSource(), target, MAPPING_TARGET);
 }
 /**
  * @param mapping
  * @param language
  * @param expression
  * @return The supplied mapping if it remains incomplete, else a new mapping mapped via the
  *     delegate
  */
 public MappingOperation<?, ?> setSourceExpression(
     final MappingOperation<?, ?> mapping, final String language, final String expression) {
   if (mapping.getType() == null) {
     ((MappingPlaceholder) mapping).setSource(new ExpressionPlaceholder(language, expression));
   } else {
     delegate.removeMapping(mapping);
   }
   return update(mapping, language, expression, (Model) mapping.getTarget(), MAPPING_SOURCE);
 }
 /**
  * {@inheritDoc}
  *
  * @see org.jboss.tools.fuse.transformation.MapperConfiguration
  *     #getMappingsForTarget(org.jboss.tools.fuse.transformation.model.Model)
  */
 @Override
 public List<MappingOperation<?, ?>> getMappingsForTarget(final Model target) {
   final List<MappingOperation<?, ?>> mappings = delegate.getMappingsForTarget(target);
   for (final MappingOperation<?, ?> mapping : mappingPlaceholders) {
     if (target.equals(mapping.getTarget())) {
       mappings.add(mapping);
     }
   }
   return mappings;
 }
 /**
  * {@inheritDoc}
  *
  * @see org.jboss.tools.fuse.transformation.MapperConfiguration
  *     #getMappingsForSource(org.jboss.tools.fuse.transformation.model.Model)
  */
 @Override
 public List<MappingOperation<?, ?>> getMappingsForSource(final Model source) {
   final List<MappingOperation<?, ?>> mappings = delegate.getMappingsForSource(source);
   for (final MappingOperation<?, ?> mapping : mappingPlaceholders) {
     if (source.equals(mapping.getSource())) {
       mappings.add(mapping);
     }
   }
   return mappings;
 }
 /**
  * {@inheritDoc}
  *
  * @see org.jboss.tools.fuse.transformation.MapperConfiguration
  *     #removeMapping(org.jboss.tools.fuse.transformation.MappingOperation)
  */
 @Override
 public void removeMapping(final MappingOperation<?, ?> mapping) {
   if (mapping.getType() == null) {
     mappingPlaceholders.remove(mapping);
   } else {
     delegate.removeMapping(mapping);
   }
   fireEvent(MAPPING, mapping, null);
 }
示例#7
0
  public static void updateDateFormat(final Shell shell, final MappingOperation<?, ?> mappingOp) {
    if (mappingOp != null && mappingOp instanceof BaseDozerMapping) {

      // if both sides of the equation are Models, we're good to check this out
      if (!(mappingOp.getSource() instanceof Model && mappingOp.getTarget() instanceof Model)) {
        return;
      }
      Model srcModel = (Model) mappingOp.getSource();
      Model tgtModel = (Model) mappingOp.getTarget();
      BaseDozerMapping dMapping = (BaseDozerMapping) mappingOp;
      if (srcModel.getType().equalsIgnoreCase("java.lang.String")
          && tgtModel.getType().equalsIgnoreCase("java.util.Date")) {
        String dateFormatStr = Util.getDateFormat(shell, mappingOp, true);
        dMapping.setSourceDateFormat(dateFormatStr);
      } else if (tgtModel.getType().equalsIgnoreCase("java.lang.String")
          && srcModel.getType().equalsIgnoreCase("java.util.Date")) {
        String dateFormatStr = Util.getDateFormat(shell, mappingOp, false);
        dMapping.setTargetDateFormat(dateFormatStr);
      }
    }
  }
 private MappingOperation<?, ?> update(
     final MappingOperation<?, ?> mapping,
     final Object source,
     final Model target,
     final String eventType) {
   MappingOperation<?, ?> resultMapping;
   if (source == null || target == null) {
     resultMapping = mapping;
   } else {
     // Not or no longer a mapping placeholder
     if (mapping.getType() == null) {
       mappingPlaceholders.remove(mapping);
     }
     if (source instanceof Model) {
       if (mapping.getType() != null) {
         delegate.removeMapping(mapping);
       }
       resultMapping = delegate.mapField((Model) source, target);
       if (mapping.getType() == MappingType.CUSTOM) {
         final CustomMapping customMapping = (CustomMapping) mapping;
         resultMapping =
             delegate.customizeMapping(
                 (FieldMapping) resultMapping,
                 customMapping.getMappingClass(),
                 customMapping.getMappingOperation());
       }
     } else if (source instanceof Variable) {
       if (mapping.getType() == MappingType.VARIABLE && target.equals(mapping.getTarget())) {
         resultMapping = mapping;
         ((VariableMapping) mapping).setVariable((Variable) source);
       } else {
         if (mapping.getType() != null) {
           delegate.removeMapping(mapping);
         }
         resultMapping = delegate.mapVariable((Variable) source, target);
       }
     } else {
       if (mapping.getType() != null) {
         delegate.removeMapping(mapping);
       }
       final Expression expression = (Expression) source;
       resultMapping =
           delegate.mapExpression(expression.getLanguage(), expression.getExpression(), target);
     }
   }
   fireEvent(eventType, mapping, resultMapping);
   return resultMapping;
 }
 private MappingOperation<?, ?> update(
     final MappingOperation<?, ?> mapping,
     final String language,
     final String expression,
     final Model target,
     final String eventType) {
   MappingOperation<?, ?> resultMapping;
   if (target == null) {
     resultMapping = mapping;
   } else {
     if (mapping.getType() == null) {
       mappingPlaceholders.remove(mapping);
     }
     resultMapping = delegate.mapExpression(language, expression, target);
   }
   fireEvent(eventType, mapping, resultMapping);
   return resultMapping;
 }
示例#10
0
 /**
  * @param mapping
  * @param variable
  * @return <code>true</code> if the supplied mapping contains the supplied variable
  */
 public boolean mappingContainsVariable(
     final MappingOperation<?, ?> mapping, final Variable variable) {
   return mapping != null
       && mapping.getType() == MappingType.VARIABLE
       && ((VariableMapping) mapping).getSource().getName().equals(variable.getName());
 }