Ejemplo 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);
    }
  }