Exemplo n.º 1
0
  /**
   * Converts the values of an FeatureMap, the values of the collection are converted to and added
   * to the list in the correct feature in the modelObject.
   *
   * @param eObject the eObject from which the value is read
   * @param modelObject the {@link ModelObject} in which the value is to be set
   * @param eFeature the eFeature which is converted
   */
  protected void convertFeatureMap(
      final EObject eObject, final ModelObject<?> modelObject, final EStructuralFeature eFeature) {
    final Collection<?> eValues = (Collection<?>) eObject.eGet(eFeature);

    @SuppressWarnings("unchecked")
    final Collection<Object> values = (Collection<Object>) modelObject.eGet(eFeature);

    // clear as the object may have been read from the db
    values.clear();

    for (final Object eValue : eValues) {
      final FeatureMap.Entry eEntry = (FeatureMap.Entry) eValue;

      final Object featureMapEntry = ModelResolver.getInstance().createFeatureMapEntry(eFeature);
      final ModelFeatureMapEntry<?> mEntry =
          ModelResolver.getInstance().getModelFeatureMapEntry(eFeature, featureMapEntry);
      mEntry.setEStructuralFeature(eEntry.getEStructuralFeature());

      final Object convertedValue;
      if (mEntry.getEStructuralFeature() instanceof EAttribute) {
        convertedValue =
            convertEAttributeValue(
                eEntry.getValue(),
                ((EAttribute) eEntry.getEStructuralFeature()).getEAttributeType());
      } else {
        convertedValue = createTarget((EObject) eEntry.getValue());
      }

      mEntry.setValue(convertedValue);
      values.add(featureMapEntry);
    }
  }
Exemplo n.º 2
0
  /**
   * Converts the values of an FeatureMap, the values of the collection are converted to and added
   * to the list in the correct feature in the modelObject.
   *
   * @param eObject the eObject from which the value is read
   * @param modelObject the {@link ModelObject} in which the value is to be set
   * @param eFeature the eFeature which is converted
   */
  protected void convertFeatureMap(
      final ModelObject<?> modelObject, final EObject eObject, final EStructuralFeature eFeature) {
    final Collection<?> mValues = (Collection<?>) modelObject.eGet(eFeature);

    @SuppressWarnings("unchecked")
    final Collection<Object> values = (Collection<Object>) eObject.eGet(eFeature);
    for (final Object mValue : mValues) {
      final ModelFeatureMapEntry<?> mEntry =
          ModelResolver.getInstance().getModelFeatureMapEntry(eFeature, mValue);
      EStructuralFeature entryFeature = mEntry.getEStructuralFeature();
      Object entryValue = mEntry.getValue();

      // flatten the tree of feature map entries, feature maps maybe nested
      // EMF uses a flattened api, while Texo builds this actual tree of
      // featuremaps, the findFeature and findValue find the deepest featureMap entry
      if (FeatureMapUtil.isFeatureMap(entryFeature)) {
        final ModelFeatureMapEntry<?> modelFeatureMapEntry =
            ModelResolver.getInstance().getModelFeatureMapEntry(entryFeature, entryValue);
        entryFeature = ModelUtils.findFeature(modelFeatureMapEntry);
        entryValue = ModelUtils.findValue(modelFeatureMapEntry);
      }

      final Object convertedValue;
      if (entryFeature instanceof EAttribute) {
        convertedValue =
            convertEAttributeValue(entryValue, ((EAttribute) entryFeature).getEAttributeType());
      } else {
        convertedValue = createTarget(entryValue);
      }
      final FeatureMap.Entry eEntry = FeatureMapUtil.createEntry(entryFeature, convertedValue);
      values.add(eEntry);
    }
  }