Ejemplo n.º 1
0
  /**
   * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support
   * is only enabled for EMF with fixed bug #247130. These compile errors do not affect native
   * models!
   */
  protected void resolveProxies(EStructuralFeature feature) {
    Object value = getInstanceValue(instance, feature);
    if (value != null) {
      if (feature.isMany()) {
        @SuppressWarnings("unchecked")
        InternalEList<Object> list = (InternalEList<Object>) value;
        int size = list.size();

        boolean deliver = instance.eDeliver();
        if (deliver) {
          instance.eSetDeliver(false);
        }

        for (int i = 0; i < size; i++) {
          Object element = list.get(i);
          if (element instanceof LegacyProxy) {
            CDOID id = ((LegacyProxy) element).getID();
            InternalCDOObject resolved = (InternalCDOObject) viewAndState.view.getObject(id);
            InternalEObject instance = resolved.cdoInternalInstance();

            // TODO LEGACY
            // // TODO Is InternalEList.basicSet() needed???
            // if (list instanceof
            // org.eclipse.emf.ecore.util.DelegatingInternalEList)
            // {
            // list =
            // ((org.eclipse.emf.ecore.util.DelegatingInternalEList)list).getDelegateInternalEList();
            // }

            // if (list instanceof NotifyingListImpl<?>)
            // {
            // ((NotifyingListImpl<Object>)list).basicSet(i, instance, null);
            // }
            // else
            // {
            list.set(i, instance);
            // }
          }
        }

        if (deliver) {
          instance.eSetDeliver(true);
        }
      } else {
        if (value instanceof LegacyProxy) {
          CDOID id = ((LegacyProxy) value).getID();
          InternalCDOObject resolved = (InternalCDOObject) viewAndState.view.getObject(id);
          InternalEObject instance = resolved.cdoInternalInstance();
          setInstanceValue(instance, feature, instance);
        }
      }
    }
  }
 void resolve(EObject object, EReference reference, EObject proxy) {
   EReference opposite = reference.getEOpposite();
   if (opposite != null) {
     if (opposite.isMany()) {
       InternalEList<?> list = (InternalEList<?>) object.eGet(opposite, false);
       int index = list.basicIndexOf(proxy);
       if (index >= 0) {
         list.get(index); // resolve just this index
       }
     } else {
       object.eGet(opposite, true); // resolve the scalar reference
     }
   }
 }
Ejemplo n.º 3
0
  protected void clearEList(InternalEList<?> list) {
    for (int i = list.size() - 1; i >= 0; --i) {
      Object obj = list.get(i);

      // Disable notifications from value during the
      // invalidation in case of
      // eInverseAdd/eInverseRemove
      boolean eDeliver = false;
      if (obj instanceof Notifier) {
        Notifier notifier = (Notifier) obj;
        eDeliver = notifier.eDeliver();
        if (eDeliver) {
          notifier.eSetDeliver(false);
        }
      }

      list.basicRemove(obj, null);

      if (obj instanceof Notifier && eDeliver) {
        Notifier notifier = (Notifier) obj;
        notifier.eSetDeliver(eDeliver);
      }
    }
  }
Ejemplo n.º 4
0
  private void adjustTransientOppositeReference(
      InternalEObject instance, InternalEObject object, EReference oppositeReference) {
    boolean wasDeliver = object.eDeliver(); // Disable notifications
    if (wasDeliver) {
      object.eSetDeliver(false);
    }

    try {
      if (oppositeReference.isMany()) {
        @SuppressWarnings("unchecked")
        InternalEList<Object> list = (InternalEList<Object>) object.eGet(oppositeReference);
        list.basicAdd(instance, null);
      } else {
        if (object.eGet(oppositeReference) != instance) {
          object.eInverseAdd(
              instance, oppositeReference.getFeatureID(), ((EObject) instance).getClass(), null);
        }
      }
    } finally {
      if (wasDeliver) {
        object.eSetDeliver(true);
      }
    }
  }
 public <T> T[] basicToArray(T[] array) {
   return copy.basicToArray(array);
 }
 public Object[] basicToArray() {
   return copy.basicToArray();
 }
 public java.util.ListIterator<org.eclipse.emf.ecore.EObject> basicListIterator(int index) {
   return copy.basicListIterator(index);
 }
 public java.util.List<org.eclipse.emf.ecore.EObject> basicList() {
   return copy.basicList();
 }
 public int basicLastIndexOf(Object object) {
   return copy.basicLastIndexOf(object);
 }
Ejemplo n.º 10
0
  /** @since 3.0 */
  protected void revisionToInstanceFeature(EStructuralFeature feature) {
    if (feature.isUnsettable() && !viewAndState.view.getStore().isSet(this, feature)) {
      // Clarify if this is sufficient for bidirectional references
      instance.eUnset(feature);
      return;
    }

    if (feature.isMany()) {
      if (TRACER.isEnabled()) {
        TRACER.format(
            "State of Object ("
                + this
                + "/"
                + instance
                + ") is : "
                + viewAndState.state); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }

      if (viewAndState.state == CDOState.CLEAN
          || viewAndState.state == CDOState.PROXY
          || viewAndState.state == CDOState.NEW
          || viewAndState.state == CDOState.DIRTY) {
        InternalCDORevision revision = cdoRevision();
        int size = revision.size(feature);

        @SuppressWarnings("unchecked")
        InternalEList<Object> list = (InternalEList<Object>) instance.eGet(feature);

        clearEList(list);
        for (int i = 0; i < size; i++) {
          Object object = getValueFromRevision(feature, i);

          if (TRACER.isEnabled()) {
            TRACER.format(
                "Adding "
                    + object
                    + " to feature "
                    + feature
                    + "in instance "
                    + instance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          }

          // Disable notifications from value during the
          // invalidation in case of
          // eInverseAdd/eInverseRemove
          boolean eDeliver = false;
          if (object instanceof Notifier) {
            Notifier notifier = (Notifier) object;
            eDeliver = notifier.eDeliver();
            if (eDeliver) {
              notifier.eSetDeliver(false);
            }
          }

          list.basicAdd(object, null);

          if (object instanceof Notifier && eDeliver) {
            Notifier notifier = (Notifier) object;
            notifier.eSetDeliver(eDeliver);
          }
        }
      }
    } else {
      // !feature.isMany()
      Object object = getValueFromRevision(feature, 0);
      if (feature instanceof EAttribute) {
        if (TRACER.isEnabled()) {
          TRACER.format(
              "Setting attribute value "
                  + object
                  + " to feature "
                  + feature
                  + " in instance "
                  + instance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }

        // Just fake it for the store :(
        if (feature.isUnsettable() && object.equals(CDORevisionData.NIL)) {
          eSet(feature, null);
        } else {
          if (object != null) {
            eSet(feature, object);
          } else {
            // TODO Unset for features with non-null default values would not lead to null values.
            // Probably CDORevisionData.NIL has to be used, but that impacts all IStores. Deferred
            // ;-(
            eUnset(feature);
          }
        }
      } else {
        // EReferences
        if (TRACER.isEnabled()) {
          TRACER.format(
              "Adding object "
                  + object
                  + " to feature "
                  + feature
                  + " in instance "
                  + instance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }

        // Disable notifications from value during the
        // invalidation in case of
        // eInverseAdd/eInverseRemove
        boolean eDeliver = false;
        if (object instanceof Notifier) {
          Notifier notifier = (Notifier) object;
          eDeliver = notifier.eDeliver();
          if (eDeliver) {
            notifier.eSetDeliver(false);
          }
        }
        EObject oldContainerOfValue = null;
        boolean eDeliverForOldContainerOfValue = false;
        if (object instanceof InternalEObject) {
          InternalEObject eObject = (InternalEObject) object;
          oldContainerOfValue = eObject.eInternalContainer();
          if (oldContainerOfValue != null) {
            eDeliverForOldContainerOfValue = oldContainerOfValue.eDeliver();
            if (eDeliverForOldContainerOfValue) {
              oldContainerOfValue.eSetDeliver(false);
            }
          }
        }

        int featureID = instance.eClass().getFeatureID(feature);
        Class<? extends Object> baseClass = object == null ? null : object.getClass();
        EStructuralFeature.Internal internalFeature = (EStructuralFeature.Internal) feature;
        EReference oppositeReference = internalFeature.getEOpposite();

        if (oppositeReference != null) {
          if (object != null && object != instance.eGet(feature)) {
            // If you have a containment reference but the container is not set, but the object is
            // attached to a
            // resource
            // do not set the feature to null. Otherwise the object will be removed from the
            // container which is the
            // resource instead of the original container. As a result the object will be detached.
            // See
            // MapTest.testEObjectToEObjectValueContainedMap for more information
            if (object != instance.eContainer() || !oppositeReference.isContainment()) {
              instance.eInverseAdd((InternalEObject) object, featureID, baseClass, null);
            }

            if (!classInfo.hasPersistentOpposite(internalFeature)) {
              adjustTransientOppositeReference(
                  instance, (InternalEObject) object, oppositeReference);
            }
          }
        } else {
          if (object != CDORevisionData.NIL) {
            EReference reference = (EReference) feature;
            if (reference.isContainment()) {
              if (object != null) {
                // Calling eSet it not the optimal approach, but currently there is no other way to
                // set the value here.
                // To avoid attaching already processed (clean) objects a check was introduced to
                // CDOResourceImpl.attached(EObject).
                // If we find a way to avoid the call of eSet and if we are able to only set the
                // feature value directly
                // this check can be removed from CDOResourceImpl. See also Bug 352204.
                instance.eSet(feature, object);
              } else {
                instance.eSet(feature, null);
              }
            } else {
              instance.eSet(feature, object);
            }
          } else {
            instance.eSet(feature, null);
          }
        }

        if (object instanceof Notifier && eDeliver) {
          Notifier notifier = (Notifier) object;
          notifier.eSetDeliver(eDeliver);
        }
        if (oldContainerOfValue != null && eDeliverForOldContainerOfValue) {
          oldContainerOfValue.eSetDeliver(eDeliverForOldContainerOfValue);
        }

        if (TRACER.isEnabled()) {
          TRACER.format(
              "Added object "
                  + object
                  + " to feature "
                  + feature
                  + " in instance "
                  + instance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
      }
    }
  }
 public boolean addAllUnique(
     int index, java.util.Collection<? extends org.eclipse.emf.ecore.EObject> collection) {
   copy.addAllUnique(index, collection);
   return original.addAllUnique(index, collection);
 }
 public boolean basicContainsAll(java.util.Collection<?> collection) {
   return copy.basicContainsAll(collection);
 }
 public boolean basicContains(Object object) {
   return copy.basicContains(object);
 }
 public org.eclipse.emf.ecore.EObject setUnique(int index, org.eclipse.emf.ecore.EObject object) {
   copy.setUnique(index, object);
   return original.setUnique(index, object);
 }
 public org.eclipse.emf.common.notify.NotificationChain basicRemove(
     Object object, org.eclipse.emf.common.notify.NotificationChain notifications) {
   copy.basicRemove(object, notifications);
   return original.basicRemove(object, notifications);
 }
 public boolean equals(Object o) {
   return copy.equals(o);
 }
 public int hashCode() {
   return copy.hashCode();
 }
 public org.eclipse.emf.ecore.EObject basicGet(int index) {
   return copy.basicGet(index);
 }
 public void addUnique(int index, org.eclipse.emf.ecore.EObject object) {
   copy.addUnique(index, object);
   original.addUnique(index, object);
 }
 public java.util.Iterator<org.eclipse.emf.ecore.EObject> basicIterator() {
   return copy.basicIterator();
 }