/** * @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 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; }
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; }