Ejemplo n.º 1
0
 private String fullyQualifiedName(final Model model, final StringBuilder builder) {
   if (model.getParent() != null) {
     fullyQualifiedName(model.getParent(), builder);
     builder.append('.');
   }
   builder.append(model.getName());
   return builder.toString();
 }
Ejemplo n.º 2
0
 Model find(final Object object, final Model model) {
   if (model.equals(object)) {
     return model;
   }
   for (final Model child : model.getChildren()) {
     final Model match = find(object, child);
     if (match != null) {
       return match;
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 /**
  * {@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;
 }
Ejemplo n.º 4
0
 /**
  * {@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;
 }
Ejemplo n.º 5
0
 public static boolean validSourceAndTarget(
     final Object source, final Object target, final TransformationConfig config) {
   final Model sourceModel = source instanceof Model ? (Model) source : null;
   final Model targetModel = target instanceof Model ? (Model) target : null;
   if (sourceModel != null && Util.type(sourceModel)) {
     return false;
   }
   if (targetModel != null && Util.type(targetModel)) {
     return false;
   }
   if (sourceModel != null && targetModel != null) {
     if (config.getMapping(sourceModel, targetModel) != null) {
       return false;
     }
     if (sourceModel.isCollection() && targetModel.isCollection()) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 6
0
  public static FieldMapping updateDateFormat(
      final Shell shell,
      final Model srcModel,
      final Model tgtModel,
      final TransformationConfig config) {

    if (srcModel != null && tgtModel != null && config != null) {
      FieldMapping mapping = config.mapField(srcModel, tgtModel);
      if (srcModel.getType().equalsIgnoreCase("java.lang.String")
          && tgtModel.getType().equalsIgnoreCase("java.util.Date")) {
        String dateFormatStr = Util.getDateFormat(shell, mapping, true);
        mapping.setSourceDateFormat(dateFormatStr);
      } else if (tgtModel.getType().equalsIgnoreCase("java.lang.String")
          && srcModel.getType().equalsIgnoreCase("java.util.Date")) {
        String dateFormatStr = Util.getDateFormat(shell, mapping, false);
        mapping.setTargetDateFormat(dateFormatStr);
      }
      return mapping;
    }
    return null;
  }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 public static boolean modelsNeedDateFormat(
     final Object source, final Object target, final boolean isSource) {
   if (!(source instanceof Model && target instanceof Model)) {
     return false;
   }
   Model srcModel = (Model) source;
   Model tgtModel = (Model) target;
   if (isValidNonNullType(srcModel) && isValidNonNullType(tgtModel)) {
     if (srcModel.getType().equalsIgnoreCase("java.lang.String")
         && tgtModel.getType().equalsIgnoreCase("java.util.Date")
         && isSource) {
       return true;
     } else if (tgtModel.getType().equalsIgnoreCase("java.lang.String")
         && srcModel.getType().equalsIgnoreCase("java.util.Date")
         && !isSource) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 9
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);
      }
    }
  }
Ejemplo n.º 10
0
 public static boolean type(final Model model) {
   return (!model.isCollection() && !model.getChildren().isEmpty());
 }
Ejemplo n.º 11
0
 public static boolean isOrInCollection(final Model model) {
   return model != null && (model.isCollection() || isOrInCollection(model.getParent()));
 }
Ejemplo n.º 12
0
 private static boolean isValidNonNullType(Model model) {
   if (model != null && model.getType() != null) {
     return true;
   }
   return false;
 }
Ejemplo n.º 13
0
 /**
  * @param model
  * @return the root model of the supplied model
  */
 public Model root(final Model model) {
   return model.getParent() == null ? model : root(model.getParent());
 }