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; }
/** * @param customMapping * @return a new (uncustomized) field mapping */ public FieldMapping uncustomizeMapping(final CustomMapping customMapping) { delegate.removeMapping(customMapping); final FieldMapping fieldMapping = delegate.mapField(customMapping.getSource(), customMapping.getTarget()); fireEvent(MAPPING_CUSTOMIZE, customMapping, fieldMapping); return fieldMapping; }
/** * @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 * #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); }