コード例 #1
0
  private void populateMappingInfo(EObject xmlEntity) {
    Resource resource = xmlEntity.eResource();

    // model contents for this resource
    ModelContents mdlContents = new ModelContents(resource);
    XmlDocument document = getXmlDocument(xmlEntity);
    currentDocumentName = document.getName();
    // fill the map with element to its mappingClass column value
    this.elementMap = new HashMap();
    this.elementFullNames = new HashSet();
    // get the mapping root associated with the transformation
    Iterator rootIter = mdlContents.getTransformations(document).iterator();
    while (rootIter.hasNext()) {
      MappingRoot mappingRoot = (MappingRoot) rootIter.next();
      // if there is a mapping root
      if (mappingRoot != null && mappingRoot instanceof TreeMappingRoot) {
        Iterator mappingIter = mappingRoot.getNested().iterator();
        while (mappingIter.hasNext()) {
          Mapping nestedMapping = (Mapping) mappingIter.next();
          // mapping Class columns
          List inputs = nestedMapping.getInputs();
          // xml elements
          List outputs = nestedMapping.getOutputs();
          if (!outputs.isEmpty() && !inputs.isEmpty()) {
            Object output = outputs.iterator().next();
            Object input = inputs.iterator().next();
            elementMap.put(output, input);
            if (output instanceof XmlElement) {
              elementFullNames.add(this.getFullName((EObject) output));
            }
          }
        }
      }
    }
  }
コード例 #2
0
  public Collection<? extends Mapping> getExactMappings(Collection<?> collection) {
    Collection<Mapping> result = new ArrayList<Mapping>();
    for (Mapping mapping : getAllMappings(collection)) {
      if (collection.containsAll(mapping.getMappedObjects())) {
        result.add(mapping);
      }
    }

    return result;
  }
コード例 #3
0
  /**
   * @see
   *     com.metamatrix.modeler.core.metamodel.aspect.sql.SqlColumnAspect#isTranformationInputParameter(org.eclipse.emf.ecore.EObject)
   * @since 4.2
   */
  public boolean isTranformationInputParameter(EObject eObject) {
    CoreArgCheck.isInstanceOf(XmlElement.class, eObject);
    final XmlElement element = (XmlElement) eObject;

    if (element instanceof XmlRoot) {
      return false;
    }

    final XmlDocument doc = getDocParent(element);
    final XmlElement parent = getElementParent(element);
    if (doc == null || parent == null) {
      return false;
    }

    Resource eResource = element.eResource();
    if (eResource instanceof EmfResource) {
      EmfResource emfResource = (EmfResource) eResource;
      ModelContents contents = emfResource.getModelContents();
      if (contents != null) {
        for (final Iterator mappings = contents.getTransformations(doc).iterator();
            mappings.hasNext(); ) {
          final TreeMappingRoot tmr = (TreeMappingRoot) mappings.next();
          if (tmr.getOutputs().contains(parent)) {
            final Iterator nested = tmr.getNested().iterator();
            while (nested.hasNext()) {
              final Mapping mapping = (Mapping) nested.next();
              if (mapping.getOutputs().contains(element)) {
                if (mapping.getInputs().size() == 0) {
                  return false;
                }
                Iterator i = mapping.getInputs().iterator();
                while (i.hasNext()) {
                  MappingClassColumn column = (MappingClassColumn) i.next();
                  SqlAspect aspect = AspectManager.getSqlAspect(column);
                  if (!(aspect instanceof SqlColumnAspect)) {
                    return false;
                  }
                  if (!((SqlColumnAspect) aspect).isTranformationInputParameter(column)) {
                    return false;
                  }
                }
                return true;
              }
            }
          }
        }
      }
    }
    return false;
  }
コード例 #4
0
  public void deregister(Mapping mapping) {
    for (Object input : mapping.getInputs()) {
      MappedObjectState mappedObjectState = getMappedObjectState(input);
      if (mappedObjectState != null) {
        mappedObjectState.getMappings().remove(mapping);
      }
    }

    for (Object output : mapping.getOutputs()) {
      MappedObjectState mappedObjectState = getMappedObjectState(output);
      if (mappedObjectState != null) {
        mappedObjectState.getMappings().remove(mapping);
      }
    }
  }
コード例 #5
0
  public Mapping getParentMapping(Collection<?> collection) {
    // Barring a better result, this will be the result.
    //
    Mapping result = this;

    // Cache the tree path for each object.
    //
    final Collection<List<?>> allTreePaths = new ArrayList<List<?>>();
    for (Object object : collection) {
      allTreePaths.add(domain.getTreePath(object));
    }

    // Iterate over the mappings in the tree.
    //
    OuterLoop:
    for (TreeIterator<Mapping> mappings = treeIterator(); mappings.hasNext(); ) {
      Mapping mapping = mappings.next();

      // Check to make sure that every object in the collection has an ancestor that is contained in
      // this mapping.
      //
      for (Iterator<List<?>> treePaths = allTreePaths.iterator(); treePaths.hasNext(); ) {
        List<?> treePath = treePaths.next();
        Collection<?> mappedObjects = mapping.getMappedObjects();
        mappedObjects.retainAll(treePath);

        // If the intersection is empty, i.e., no ancestor is in the mapping...
        //
        if (mappedObjects.isEmpty()) {
          // If this mapping isn't a parent, it's children definitely won't be either.
          //
          mappings.prune();
          continue OuterLoop;
        }
      }

      // Make sure the collections aren't identical...
      //
      Collection<?> mappedObjects = mapping.getMappedObjects();
      if (!collection.containsAll(mappedObjects) || !mappedObjects.containsAll(collection)) {
        result = mapping;
      }
    }

    return result;
  }
コード例 #6
0
  public boolean canRemoveMapping(Mapping mapping) {
    int enablementFlags = domain.getMappingEnablementFlags();
    if (mapping.getNestedIn() == null
        || (enablementFlags & MappingDomain.ENABLE_UNMAPPED_PARENTS) == 0
            && hasMappedChildren(mapping)) {
      return false;
    }

    return true;
  }
コード例 #7
0
  protected void initializeNewMapping(
      Mapping newMapping, Collection<?> inputs, Collection<?> outputs) {
    @SuppressWarnings("unchecked")
    Collection<EObject> eObjectInputs = (Collection<EObject>) inputs;
    @SuppressWarnings("unchecked")
    Collection<EObject> eObjectOutputs = (Collection<EObject>) outputs;
    newMapping.getInputs().addAll(eObjectInputs);
    newMapping.getOutputs().addAll(eObjectOutputs);

    if (getTypeMappingRoot() != null) {
      Collection<?> inputTypes = getTypeClassifiers(inputs);
      if (!inputTypes.isEmpty()) {
        Collection<?> outputTypes = getTypeClassifiers(outputs);

        Collection<?> typeMappings = getTypeMappings(inputTypes, outputTypes);
        if (!typeMappings.isEmpty()) {
          newMapping.setTypeMapping((Mapping) typeMappings.iterator().next());
        }
      }
    }
  }
コード例 #8
0
  @Override
  public Image getImage(final Object node) {
    if (node instanceof DifferenceReport) {
      return null;
    } else if (node instanceof Mapping) {
      Mapping mapping = (Mapping) node;
      MappingHelper helper = mapping.getHelper();
      if (helper instanceof DifferenceDescriptor) {
        final DifferenceDescriptor desc = (DifferenceDescriptor) helper;
        final DifferenceType type = desc.getType();
        if (type.getValue() == DifferenceType.DELETION) {
          final List<EObject> inputs = mapping.getInputs();
          final EObject input = inputs.isEmpty() ? null : inputs.get(0);
          if (input != null) {
            return lpImageLabelProvider.getImage(input);
          }
        } else {
          final List<EObject> outputs = mapping.getOutputs();
          final EObject output = outputs.isEmpty() ? null : outputs.get(0);
          final List<EObject> inputs = mapping.getInputs();
          final EObject input = inputs.isEmpty() ? null : inputs.get(0);
          if (output != null) {
            return lpImageLabelProvider.getImage(output);
          } else if (input != null) {
            return lpImageLabelProvider.getImage(input);
          }
        }
      }
    } else if (node instanceof EObject) {
      return lpImageLabelProvider.getImage(node);
    }

    if (node instanceof ModelWorkspaceItem) {
      return workbenchProvider.getImage(((ModelWorkspaceItem) node).getResource());
    }
    return null;
  }
コード例 #9
0
  public void refreshMappedObjectStates(Mapping subtree) {
    for (Object input : subtree.getInputs()) {
      for (Iterator<?> objects = domain.treeIterator(input); objects.hasNext(); ) {
        Object object = objects.next();
        MappedObjectState mappedObjectState = getMappedObjectState(object);
        if (mappedObjectState != null) {
          mappedObjectState.setInput();
        }
      }
    }

    for (Object output : subtree.getOutputs()) {
      for (Iterator<?> objects = domain.treeIterator(output); objects.hasNext(); ) {
        MappedObjectState mappedObjectState = getMappedObjectState(objects.next());
        if (mappedObjectState != null) {
          mappedObjectState.setOutput();
        }
      }
    }

    for (Iterator<Mapping> mappings = subtree.treeIterator(); mappings.hasNext(); ) {
      Mapping mapping = mappings.next();
      for (Object input : mapping.getInputs()) {
        MappedObjectState mappedObjectState = getMappedObjectState(input);
        if (mappedObjectState != null) {
          mappedObjectState.getMappings().add(mapping);
        }
      }

      for (Object output : mapping.getOutputs()) {
        MappedObjectState mappedObjectState = getMappedObjectState(output);
        if (mappedObjectState != null) {
          mappedObjectState.getMappings().add(mapping);
        }
      }
    }
  }
コード例 #10
0
 protected boolean hasMappedChildren(Mapping mapping) {
   return !mapping.getNested().isEmpty();
 }
コード例 #11
0
  @Override
  public String getText(final Object node) {
    if (node instanceof DifferenceReport) {
      DifferenceReport diffReport = (DifferenceReport) node;
      String result = diffReport.getTitle();

      if (result == null) {
        result = diffReport.getResultUri();
      }

      return result;
    } else if (node instanceof Mapping) {
      Mapping mapping = (Mapping) node;
      MappingHelper helper = mapping.getHelper();
      if (helper instanceof DifferenceDescriptor) {
        final DifferenceDescriptor desc = (DifferenceDescriptor) helper;
        final DifferenceType type = desc.getType();
        int typeValue = type.getValue();
        if (typeValue == DifferenceType.ADDITION) {
          final List<EObject> outputs = mapping.getOutputs();
          final EObject output = outputs.isEmpty() ? null : outputs.get(0);
          if (output != null) {
            return ModelUtilities.getEMFLabelProvider().getText(output);
          }
        } else if (typeValue == DifferenceType.DELETION) {
          final List<EObject> inputs = mapping.getInputs();
          final EObject input = inputs.isEmpty() ? null : inputs.get(0);
          if (input != null) {
            return ModelUtilities.getEMFLabelProvider().getText(input);
          }
        } else if (typeValue == DifferenceType.CHANGE) {
          final List<EObject> outputs = mapping.getOutputs();
          final EObject output = outputs.isEmpty() ? null : outputs.get(0);
          if (output != null) {
            return ModelUtilities.getEMFLabelProvider().getText(output);
          }
        } else if (typeValue == DifferenceType.NO_CHANGE) {
          final List<EObject> outputs = mapping.getOutputs();
          final EObject output = outputs.isEmpty() ? null : outputs.get(0);
          if (output != null) {
            return ModelUtilities.getEMFLabelProvider().getText(output);
          }
        } else if (typeValue == DifferenceType.CHANGE_BELOW) {
          final List<EObject> outputs = mapping.getOutputs();
          final EObject output = outputs.isEmpty() ? null : outputs.get(0);
          final List<EObject> inputs = mapping.getInputs();
          final EObject input = inputs.isEmpty() ? null : inputs.get(0);
          if (output != null) {
            return ModelUtilities.getEMFLabelProvider().getText(output);
          } else if (input != null) {
            return ModelUtilities.getEMFLabelProvider().getText(input);
          }
        }
      }
    } else if (node instanceof EObject) {
      return ModelUtilities.getEMFLabelProvider().getText(node);
    }

    if (node instanceof ModelWorkspaceItem) {
      return workbenchProvider.getText(((ModelWorkspaceItem) node).getResource());
    }
    return "UNKNOWN"; //$NON-NLS-1$
  }