Пример #1
0
  private void createModel() {
    EFactory factory = metamodelPackage.getEFactoryInstance();
    netObject = factory.create(getNetClass());

    place1Object = factory.create(getPlaceClass());
    setName(place1Object, "place1");
    setTokens(place1Object, 1);

    place2Object = factory.create(getPlaceClass());
    setName(place2Object, "place2");

    transitionObject = factory.create(getTransitionClass());
    setIncoming(transitionObject, place1Object);
    setOutgoing(transitionObject, place2Object);

    EList<EObject> placesValue = new BasicEList<EObject>();
    placesValue.add(place1Object);
    placesValue.add(place2Object);
    EReference placesReference = getPlacesReference(netObject.eClass());
    netObject.eSet(placesReference, placesValue);

    EList<EObject> transitionsValue = new BasicEList<EObject>();
    transitionsValue.add(transitionObject);
    EReference transitionsReference = getTransitionsReference(netObject.eClass());
    netObject.eSet(transitionsReference, transitionsValue);
  }
Пример #2
0
  private void createContainment(
      EObject eObject, EReference reference, JsonNode root, JsonNode node, Resource resource) {
    if (node.isArray()) {
      if (reference.isMany()) {
        @SuppressWarnings("unchecked")
        EList<EObject> values = (EList<EObject>) eObject.eGet(reference);

        for (Iterator<JsonNode> it = node.getElements(); it.hasNext(); ) {
          JsonNode current = it.next();
          EObject contained = createContainedObject(reference, root, current, resource);
          if (contained != null) values.add(contained);
        }
      } else if (node.getElements().hasNext()) {
        JsonNode current = node.getElements().next();
        EObject contained = createContainedObject(reference, root, current, resource);
        if (contained != null) eObject.eSet(reference, contained);
      }
    } else {
      EObject contained = createContainedObject(reference, root, node, resource);

      if (reference.isMany()) {
        @SuppressWarnings("unchecked")
        EList<EObject> values = (EList<EObject>) eObject.eGet(reference);
        if (contained != null) values.add(contained);
      } else {
        if (contained != null) eObject.eSet(reference, contained);
      }
    }
  }
 @SuppressWarnings({"unchecked", "rawtypes"})
 private void setSourceRef(
     DataAssociation association,
     ItemAwareElement value,
     EObject container,
     EStructuralFeature containerFeature) {
   if (association.getSourceRef().size() == 0) {
     if (container != null) {
       if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
       else container.eSet(containerFeature, value);
     }
     if (value == null) association.getSourceRef().clear();
     else association.getSourceRef().add(value);
     updateConnectionIfNeeded(association, value);
   } else {
     if (container != null) {
       if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
       else container.eSet(containerFeature, value);
     }
     updateConnectionIfNeeded(association, value);
     if (value == null) association.getSourceRef().clear();
     else association.getSourceRef().set(0, value);
     updateConnectionIfNeeded(association, value);
   }
   if (association.getTargetRef() != null) {
     ItemAwareElement targetRef = association.getTargetRef();
     if (value != null) targetRef.setItemSubjectRef(value.getItemSubjectRef());
     else targetRef.setItemSubjectRef(null);
     updateConnectionIfNeeded(association, value);
   }
 }
Пример #4
0
  @SuppressWarnings("deprecation")
  private EObject createEntry(String key, JsonNode value) {
    EObject eObject = EcoreUtil.create(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY);
    eObject.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__KEY, key);
    eObject.eSet(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY__VALUE, value.getValueAsText());

    return eObject;
  }
Пример #5
0
  /** Tests the &gt;= operator. */
  public void test_greaterThanOrEqual() {
    helper.setContext(thingType);

    try {
      // primitives
      assertTrue(check(helper, thing, "2 >= 1"));
      assertTrue(check(helper, thing, "2 >= 2"));
      assertFalse(check(helper, thing, "2 >= 21"));
      assertTrue(check(helper, thing, "2 >= 1.0"));
      assertTrue(check(helper, thing, "2 >= 2.0"));
      assertFalse(check(helper, thing, "2 >= 21.0"));
      assertTrue(check(helper, thing, "2.0 >= 1"));
      assertTrue(check(helper, thing, "2.0 >= 2"));
      assertFalse(check(helper, thing, "2.0 >= 21"));
      assertTrue(check(helper, thing, "2.0 >= 1.0"));
      assertTrue(check(helper, thing, "2.0 >= 2.0"));
      assertFalse(check(helper, thing, "2.0 >= 21.0"));
      assertTrue(check(helper, thing, "'b' >= 'a'"));
      assertTrue(check(helper, thing, "'b' >= 'b'"));
      assertFalse(check(helper, thing, "'a' >= 'b'"));

      // BigDecimal tests
      thing.eSet(ebdValue, new BigDecimal("1"));
      assertTrue(check(helper, thing, "bdValue >= 1"));
      assertTrue(check(helper, thing, "bdValue >= 1.0"));
      assertTrue(check(helper, thing, "bdValue >= 0.9"));
      thing.eSet(ebdValue, new BigDecimal("1.0"));
      assertTrue(check(helper, thing, "bdValue >= 1"));
      assertTrue(check(helper, thing, "bdValue >= 1.0"));
      assertTrue(check(helper, thing, "bdValue >= 0.9"));
      thing.eSet(ebdValue, new BigDecimal("1.1"));
      assertTrue(check(helper, thing, "bdValue >= 1"));
      assertTrue(check(helper, thing, "bdValue >= 1.0"));
      assertTrue(check(helper, thing, "bdValue >= 1.1"));

      // BigInteger tests
      thing.eSet(ebiValue, new BigInteger("1"));
      assertTrue(check(helper, thing, "biValue >= 0.9"));
      assertTrue(check(helper, thing, "biValue >= 1"));
      assertTrue(check(helper, thing, "biValue >= 1.0"));

      @SuppressWarnings("unchecked")
      List<Value> valuesList = (List<Value>) thing.eGet(evalues);

      valuesList.add(new Value("b"));
      valuesList.add(new Value("a"));

      assertTrue(check(helper, thing, "values->at(1) >= values->at(2)"));

      assertTrue(check(helper, thing, "values->at(1) >= values->at(1)"));

      assertFalse(check(helper, thing, "values->at(2) >= values->at(1)"));
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
Пример #6
0
 /**
  * This basically calls a setter via EMF reflection to set a structural feature.
  *
  * <ul>
  *   <li>If <code>value</code> is a {@link List} of elements, the feature <code>ref</code> must,
  *       of course, also be a list.
  *   <li>If <code>value</code> is a single element, then <code>ref</code> might have multiplicity
  *       <code>1</code> or it might also be a list. In the latter case, <code>value</code> is
  *       added to the list.
  * </ul>
  *
  * @param obj The object which holds the feature to set.
  * @param ref The feature which should be set.
  * @param value The value that should be set.
  * @return <code>true</code>, if the value could be set or <b>if it was already set</b>; <code>
  *     false</code> otherwise.
  */
 @SuppressWarnings("unchecked")
 public static boolean setStructuralFeature(EObject obj, EStructuralFeature ref, Object value) {
   if (!ref.isChangeable()) {
     throw new IllegalArgumentException(
         "Cannot set a non-changeable reference: " + obj.eClass().getName() + "." + ref.getName());
   }
   try {
     if (ref.isMany()) {
       final List<Object> list = (List<Object>) obj.eGet(ref);
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         for (final Object listValue : valueList) {
           if (!list.contains(listValue) && !list.add(listValue)) {
             return false;
           }
         }
       } else {
         if (!list.contains(value) && !list.add(value)) {
           return false;
         }
       }
       return true;
     } else {
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         if (valueList.size() > 1) {
           throw new IllegalArgumentException(
               "Cannot set a list of values to a non-many feature!");
         } else if (valueList.size() == 1) {
           if (obj.eGet(ref) == null || !obj.eGet(ref).equals(valueList.get(0))) {
             obj.eSet(ref, valueList.get(0));
           }
         } else {
           obj.eSet(ref, null);
         }
       } else {
         if (obj.eGet(ref) == null || !obj.eGet(ref).equals(value)) {
           obj.eSet(ref, value);
         }
       }
       return true;
     }
   } catch (final Exception e) {
     throw new IllegalArgumentException(
         "Could not set value ("
             + value
             + ") to: "
             + obj.eClass().getName()
             + "."
             + ref.getName()
             + " of object "
             + obj,
         e);
   }
 }
 /**
  * @param copyObjs
  * @return 转换为粘贴对象
  */
 private Collection<Object> getPasteObjs(Collection<Object> copyObjs, EClass eclass) {
   List<Object> objs = new ArrayList<Object>();
   Map<EStructuralFeature, EStructuralFeature> map =
       new HashMap<EStructuralFeature, EStructuralFeature>();
   // 由第一个复制对象,找出复制对象和粘贴对象匹配的属性
   Iterator<Object> it = copyObjs.iterator();
   if (it.hasNext()) {
     Object obj = it.next();
     if (obj instanceof EObject) {
       EObject copyObj = (EObject) obj;
       // 如果是同一个编辑器内进行粘贴,直接返回复制对象集合
       if (copyObj.eClass().equals(eclass)) {
         return copyObjs;
       }
       // name一样,则表示属性匹配
       for (EStructuralFeature copyFeature : copyObj.eClass().getEAllStructuralFeatures()) {
         if (!exclude.contains(copyFeature)) {
           for (EStructuralFeature pasteFeature : eclass.getEAllStructuralFeatures()) {
             if (StringUtils.equals(copyFeature.getName(), pasteFeature.getName())) {
               map.put(copyFeature, pasteFeature);
               break;
             }
           }
         }
       }
     }
   }
   // 如果没有匹配的属性,则返回空集合
   if (map.isEmpty()) {
     return objs;
   }
   for (Object obj : copyObjs) {
     EObject copyObj = (EObject) obj;
     EObject pasteObj = eclass.getEPackage().getEFactoryInstance().create(eclass);
     for (Entry<EStructuralFeature, EStructuralFeature> entry : map.entrySet()) {
       EStructuralFeature copyFeature = entry.getKey();
       EStructuralFeature pasteFeature = entry.getValue();
       if (copyFeature instanceof EAttribute) {
         // 设置匹配属性值
         pasteObj.eSet(pasteFeature, copyObj.eGet(copyFeature));
       } else if (copyFeature instanceof EReference) {
         // 设置匹配子集
         Collection<Object> tmp = (Collection<Object>) copyObj.eGet(copyFeature);
         if (tmp != null) {
           pasteObj.eSet(
               pasteFeature,
               getPasteObjs(
                   EcoreUtil.copyAll(tmp), ((EReference) pasteFeature).getEReferenceType()));
         }
       }
     }
     objs.add(pasteObj);
   }
   return objs;
 }
Пример #8
0
 public static void setSimplifiedNestedField(
     final EObject owner,
     final EReference firstLevelFeature,
     EAttribute simplifiedFeature,
     final Object newSimpleValue) {
   Object complexObject = owner.eGet(firstLevelFeature);
   if (complexObject == null) {
     complexObject = EcoreUtil.create((EClass) firstLevelFeature.getEType());
     ((EObject) complexObject).eSet(simplifiedFeature, newSimpleValue);
     owner.eSet(firstLevelFeature, complexObject);
   } else {
     ((EObject) complexObject).eSet(simplifiedFeature, newSimpleValue);
   }
 }
 protected EObject createInitialModel() {
   EClass eClass = ExtendedMetaData.INSTANCE.getDocumentRoot(dsPackage);
   EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("data");
   EObject rootObject = dsFactory.create(eClass);
   rootObject.eSet(eStructuralFeature, EcoreUtil.create((EClass) eStructuralFeature.getEType()));
   return rootObject;
 }
Пример #10
0
  public void testCustomRegular() throws CommitException {
    EObject obj = EcoreUtil.create(cls);
    obj.eSet(att, new CustomType(23, 42));

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOTransaction tx = session.openTransaction();
      CDOResource res = tx.createResource(getResourcePath("/test"));
      res.getContents().add(obj);
      tx.commit();
      tx.close();
      session.close();
    }

    clearCache(getRepository().getRevisionManager());

    {
      CDOSession session = openSession();
      session.getPackageRegistry().putEPackage(pkg);
      CDOView v = session.openView();
      CDOResource res = v.getResource(getResourcePath("/test"));
      EObject persistent = res.getContents().get(0);

      CustomType pCustom = (CustomType) persistent.eGet(att);
      assertEquals(23, pCustom.getA());
      assertEquals(42, pCustom.getB());

      v.close();
      session.close();
    }
  }
Пример #11
0
  @Test
  public void getAddedAndRemoved() {
    final EObject obj00 = EcoreUtil.create(eClass0);
    final EObject obj1 = EcoreUtil.create(eClass1);
    final EObject obj01 = EcoreUtil.create(eClass0);
    final EObject obj02 = EcoreUtil.create(eClass0);
    final List<Notification> messages = new ArrayList<Notification>();
    obj1.eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                messages.add(msg);
              }
            });

    // Add
    obj1.eSet(multiRef, Arrays.asList(new EObject[] {obj00, obj01}));
    EMFUtils.setOrAdd(obj1, multiRef, obj02);

    // Remove
    final List list = (List) obj1.eGet(multiRef);
    list.remove(obj00);
    list.removeAll(Arrays.asList(new EObject[] {obj01, obj02}));

    final List<EObject> addedObjects = new ArrayList<EObject>();
    final List<EObject> removedObjects = new ArrayList<EObject>();
    for (Notification msg : messages) {
      addedObjects.addAll(EMFUtils.getAddedObjects(msg, obj00.getClass()));
      removedObjects.addAll(EMFUtils.getRemovedObjects(msg, obj00.getClass()));
    }

    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), addedObjects);
    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), removedObjects);
  }
Пример #12
0
  /**
   * @see
   *     org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
   *     org.eclipse.core.runtime.IAdaptable)
   * @param arg0
   * @param arg1
   * @return
   * @throws ExecutionException
   */
  @SuppressWarnings("unchecked")
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor arg0, IAdaptable arg1)
      throws ExecutionException {
    Object createdElement = elementAdapter.getAdapter(EObject.class);
    if (createdElement instanceof EObject) {
      EObject eObjectCreatedElement = (EObject) createdElement;
      for (IGraphicalEditPart parent : graphicalParent) {
        EObject eObjectSourceReference = parent.resolveSemanticElement();
        AbstractContainerNodeDescriptor desc =
            GroupContainmentRegistry.getContainerDescriptor(parent);
        List<EReference> refs = desc.getReferenceFor(eObjectCreatedElement.eClass());
        for (EReference ref : refs) {
          if (ref != null && ref.isMany()) {
            Collection<EObject> collection = (Collection<EObject>) eObjectSourceReference.eGet(ref);
            if (!collection.contains(eObjectCreatedElement)) {
              collection.add(eObjectCreatedElement);
            }
          } else if (ref != null && !ref.isMany()) {
            eObjectSourceReference.eSet(ref, eObjectCreatedElement);
          }
        }
      }
    }

    return CommandResult.newOKCommandResult();
  }
Пример #13
0
  @Lock(LockType.WRITE)
  public void put(String id, EObject value) {
    if (store.get(id) == null) {
      EObject obj = getEObjectByID(id);
      store.put(id, obj);
    }

    EObject obj = store.get(id);
    EList<EAttribute> eAttributes = obj.eClass().getEAllAttributes();
    for (EAttribute eAttribute : eAttributes) {
      obj.eSet(eAttribute, value.eGet(eAttribute));
      store.remove(id);
    }
    if (validation.getFlag()) {
      Diagnostic d = Diagnostician.INSTANCE.validate(obj);
      if (d.getSeverity() == Diagnostic.ERROR)
        throw new WebApplicationException(Status.BAD_REQUEST);
    }
    try {
      resourceLoader.getResource().save(Collections.EMPTY_MAP);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #14
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void updateAttrs(
      EClass eClass, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {

    List<EAttribute> listMany = new LinkedList<EAttribute>();
    List<EAttribute> list = new LinkedList<EAttribute>();

    for (EAttribute eAttr : eClass.getEAllAttributes()) {
      if (eAttr.isMany()) {
        listMany.add(eAttr);
      } else {
        list.add(eAttr);
      }
    }

    for (EAttribute eAttr : listMany) {
      List<?> vList = (List<?>) eObj.eGet(eAttr);
      if (vList.size() == 0) {
        if (eRef != null && ((List<?>) eRef.eGet(eAttr)).size() > 0) {
          vList.addAll((List) eRef.eGet(eAttr));
        } else if (eDef != null) {
          vList.addAll((List) eDef.eGet(eAttr));
        }
      }
    }

    for (EAttribute eAttr : list) {
      Object val = eObj.eGet(eAttr);
      if (eAttr.isUnsettable()) {
        if (!eObj.eIsSet(eAttr)) {
          if (eRef != null && eRef.eIsSet(eAttr)) {
            eObj.eSet(eAttr, eRef.eGet(eAttr));
          } else if (eDef != null && eDef.eIsSet(eAttr)) {
            eObj.eSet(eAttr, eDef.eGet(eAttr));
          }
        }
      } else if (val == null) {
        if (eRef != null && eRef.eGet(eAttr) != null) {
          eObj.eSet(eAttr, eRef.eGet(eAttr));
        } else if (eDef != null) {
          eObj.eSet(eAttr, eDef.eGet(eAttr));
        }
      }
    }
  }
Пример #15
0
    public void doIt(EObject obj) {
      EObject referringInstance =
          (instance instanceof DynamicObject && ((DynamicObject) instance).hasStaticInstance())
              ? ((DynamicObject) instance).getStaticInstance()
              : instance;

      referringInstance.eSet(feature, obj);
      //                System.out.println("    R: " + feature.getName());
    }
Пример #16
0
 public static void eSetOrAdd(
     EObject obj, EStructuralFeature feature, Object value, int newIndex) {
   if (feature.isMany() && value != null) {
     List featureList = ((List) obj.eGet(feature));
     if (newIndex >= 0 && newIndex < featureList.size()) featureList.add(newIndex, value);
     else featureList.add(value);
   } else {
     obj.eSet(feature, value);
   }
 }
Пример #17
0
  @Override
  public void load() {
    Object value = getElementText(node);
    if (feature instanceof EAttribute) {
      EAttribute ea = (EAttribute) feature;
      value = EcoreUtil.createFromString(ea.getEAttributeType(), value.toString());
    }

    modelObject.eSet(feature, value);
  }
  public EObject GetObjectRoot(EObject param_obj) {

    EObject result = dslComponentFactoryImpl.eINSTANCE.create(param_obj.eClass());
    EList<EAttribute> result_attr = result.eClass().getEAllAttributes();
    for (EAttribute eAttribute : result_attr) {
      result.eSet(eAttribute, param_obj.eGet(eAttribute));
    }

    return result;
  }
Пример #19
0
  /**
   * Converts the value of an EReference with isMany==false, the value is converted to an EObject
   * and set in the correct feature in the eObject.
   *
   * @param modelObject the modelObject from which the value is retrieved.
   * @param eObject the eObject in which the value is set (after it has been converted)
   * @param eReference the eReference which is converted
   */
  protected void convertSingleEReference(
      final ModelObject<?> modelObject, final EObject eObject, final EReference eReference) {
    // containment/container features are always set from the
    // containment side
    if (eReference.isContainer()) {
      return;
    }

    if (eObject.eIsSet(eReference)) {
      return;
    }

    final Object value = modelObject.eGet(eReference);
    if (value == null) {
      eObject.eSet(eReference, null);
    } else {
      final InternalEObject eValue = (InternalEObject) createTarget(value);
      eObject.eSet(eReference, eValue);
    }
  }
Пример #20
0
 public static void replaceInContainer(final EObject search, final EObject replacement) {
   EObject container = search.eContainer();
   EStructuralFeature f = search.eContainingFeature();
   if (f.isMany()) {
     @SuppressWarnings("unchecked")
     EList<? super EObject> l = (EList<? super EObject>) container.eGet(f);
     l.set(l.indexOf(search), replacement);
   } else {
     container.eSet(f, replacement);
   }
 }
Пример #21
0
 private void createProxyReference(
     EObject eObject, JsonNode root, JsonNode node, EReference reference, Resource resource) {
   EObject proxy = getOrCreateProxyReference(reference, root, node, resource);
   if (proxy != null && reference.isMany()) {
     @SuppressWarnings("unchecked")
     EList<EObject> values = (EList<EObject>) eObject.eGet(reference);
     values.add(proxy);
   } else if (proxy != null) {
     eObject.eSet(reference, proxy);
   }
 }
Пример #22
0
 /**
  * Detach object from its container so that a child-stealing detection is avoided when attaching
  * to a new container.
  */
 public static void resetContainer(@NonNull EObject eObject) {
   EStructuralFeature eContainingFeature = eObject.eContainingFeature();
   if (eContainingFeature != null) {
     EObject eContainer = eObject.eContainer();
     if (eContainer != null) {
       if (!eContainingFeature.isMany()) {
         eContainer.eSet(eContainingFeature, null);
       } else {
         Object objects = eContainer.eGet(eContainingFeature);
         if (objects instanceof List<?>) {
           ((List<?>) objects).remove(eObject);
         }
       }
     }
   }
 }
Пример #23
0
  public void test_enumerationLiteralEquality_137546() {
    EObject ctx = fruitEFactory.create((EClass) fruitEPackage.getEClassifier(apple.getName()));
    helper.setContext(apple);

    EEnum ecolor = (EEnum) fruitEPackage.getEClassifier(color.getName());
    ctx.eSet(
        ctx.eClass().getEStructuralFeature(fruit_color.getName()),
        ecolor.getEEnumLiteral(color_green.getName()));

    try {
      assertTrue(check(helper, ctx, "ocltest::Color::green = self.color"));
      assertTrue(check(helper, ctx, "self.color = ocltest::Color::green"));
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
Пример #24
0
 /**
  * If the parameter is an EEnum, it is set to the first available literal which equalsIgnoreCase
  * matches newValue
  *
  * @param element
  * @param parameterName
  * @param newValue
  * @return The value the parameter was set to, in its proper case.
  * @throws UndefinedParameterException
  */
 public static String setParameterStringCaseInsensitive(
     EPlanElement element, String parameterName, String newValue)
     throws UndefinedParameterException {
   EObject data = element.getData();
   EStructuralFeature feature = getParameterFeature(data, parameterName);
   EClassifier type = feature.getEType();
   if (type instanceof EEnum) {
     EEnum enumType = (EEnum) type;
     EEnumLiteral literalValue = getCaseInsensitiveValue(enumType, newValue);
     data.eSet(feature, literalValue);
     return literalValue == null ? null : literalValue.getLiteral();
   } else {
     setParameterString(element, parameterName, newValue);
     return newValue;
   }
 }
Пример #25
0
  private void createMapEntry(EObject container, EReference reference, JsonNode node) {
    if (reference.isMany()) {
      @SuppressWarnings("unchecked")
      EList<EObject> values = (EList<EObject>) container.eGet(reference);

      for (Iterator<Entry<String, JsonNode>> it = node.getFields(); it.hasNext(); ) {
        Entry<String, JsonNode> element = it.next();
        values.add(createEntry(element.getKey(), element.getValue()));
      }
    } else {
      if (node.getFields().hasNext()) {
        Entry<String, JsonNode> element = node.getFields().next();
        container.eSet(reference, createEntry(element.getKey(), element.getValue()));
      }
    }
  }
Пример #26
0
  /**
   * Clones an eobject, with the option of performing a deep clone in which referenced eobjects are
   * also cloned.
   *
   * @param prototype The object to be cloned from.
   * @param factory The factory used to create the clone.
   * @param deepÊFlag indicating wether to perform a deep clone.
   * @return THe cloned object, with all properties the same to the original.
   */
  public static EObject clone(EObject prototype, EFactory factory, boolean deep) {
    EObject clone = factory.create(prototype.eClass());

    for (Iterator i = clone.eClass().getEStructuralFeatures().iterator(); i.hasNext(); ) {
      EStructuralFeature feature = (EStructuralFeature) i.next();
      Object value = prototype.eGet(feature);
      if (deep && value instanceof EObject) {
        EObject evalue = (EObject) value;
        // recursively call
        // TODO:handle cycles in reference graph
        value = clone(evalue, evalue.eClass().getEPackage().getEFactoryInstance(), deep);
      }

      clone.eSet(feature, value);
    }

    return clone;
  }
 /**
  * Called to handle the copying of a cross reference; this adds values or sets a single value as
  * appropriate for the multiplicity while <b>NOT</b> omitting any bidirectional reference that
  * isn't in the copy map.
  *
  * @param eReference the reference to copy.
  * @param eObject the object from which to copy.
  * @param copyEObject the object to copy to.
  */
 @Override
 protected void copyReference(
     final EReference eReference, final EObject eObject, final EObject copyEObject) {
   if (eObject.eIsSet(eReference)) {
     if (!eReference.isMany()) {
       Object referencedEObject = eObject.eGet(eReference, resolveProxies);
       if (referencedEObject != null) {
         Object copyReferencedEObject = get(referencedEObject);
         if (copyReferencedEObject == null) {
           if (useOriginalReferences) { // && eReference.getEOpposite() == null)
             copyEObject.eSet(getTarget(eReference), referencedEObject);
           }
         }
       }
     }
   }
   super.copyReference(eReference, eObject, copyEObject);
 }
 @SuppressWarnings({"unchecked", "rawtypes"})
 private void setTargetRef(
     DataAssociation association,
     ItemAwareElement value,
     EObject container,
     EStructuralFeature containerFeature) {
   if (container != null) {
     if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
     else container.eSet(containerFeature, value);
   }
   updateConnectionIfNeeded(association, value);
   association.setTargetRef(value);
   if (!association.getSourceRef().isEmpty()) {
     ItemAwareElement sourceRef = association.getSourceRef().get(0);
     if (value != null) sourceRef.setItemSubjectRef(value.getItemSubjectRef());
     else sourceRef.setItemSubjectRef(null);
   }
   updateConnectionIfNeeded(association, value);
 }
Пример #29
0
  /** @return an new object which is instance of <code>factoryChildClass</code>. */
  public EObject createFactoryChildObject() {
    String superType = ModelUtil.getSuperType(factoryChildClass);
    IProject project = (IProject) this.getPage().getEditor().getAdapter(IProject.class);
    String result =
        DialogUtil.openClassDialog(
            getSection().getShell(),
            project,
            superType,
            IJavaElementSearchConstants.CONSIDER_ALL_TYPES);

    if (result != null) {
      EObject component = FacesConfigFactory.eINSTANCE.create(factoryChildClass);
      // set the text content value.
      EStructuralFeature feature = factoryChildClass.getEStructuralFeatures().get(0);
      component.eSet(feature, result);
      return component;
    }
    return null;
  }
 /** Tests the basic name accesses */
 @Test
 public void test_container_navigation() throws InvocationTargetException {
   TestOCL ocl = createOCL();
   initFruitPackage(ocl);
   MetamodelManagerInternal metamodelManager = ocl.getMetamodelManager();
   IdResolver idResolver = ocl.getIdResolver();
   metamodelManager.addGlobalNamespace("fruit", fruitPackage);
   //
   //	Simple model: aTree contains redApple
   //
   EObject redApple = fruitEFactory.create(apple);
   redApple.eSet(fruit_color, color_red);
   //		EObject greenApple = fruitEFactory.create(apple);
   //		greenApple.eSet(fruit_color, color_green);
   EObject aTree = fruitEFactory.create(tree);
   @SuppressWarnings("unchecked")
   List<Object> treeFruits = (List<Object>) aTree.eGet(tree_fruits);
   treeFruits.add(redApple);
   //
   Type pivotTree = metamodelManager.getASOfEcore(Type.class, tree);
   //
   ocl.assertQueryEquals(redApple, color_red, "let aFruit : fruit::Fruit = self in aFruit.color");
   ocl.assertQueryEquals(
       aTree,
       idResolver.createOrderedSetOfEach(null, redApple),
       "let aTree : fruit::Tree = self in aTree.fruits");
   ocl.assertQueryEquals(aTree, idResolver.createOrderedSetOfEach(null, redApple), "self.fruits");
   ocl.assertQueryEquals(aTree, idResolver.createOrderedSetOfEach(null, redApple), "fruits");
   ocl.assertQueryEquals(redApple, aTree, "self.oclContainer()");
   ocl.assertQueryEquals(redApple, aTree, "self.Tree");
   //
   //	type/property ambiguity is resolved to type.
   //
   ocl.assertQueryEquals(redApple, pivotTree, "Tree");
   //
   //	type/property ambiguity is resolved to type.
   //
   ocl.assertQueryInvalid(redApple, "self.oclAsType(Tree)");
   //		ocl.assertQueryEquals(aTree, ValuesUtil.createOrderedSetValue(null, redApple),
   // "self.oclAsType(Tree).fruits");
   ocl.dispose();
 }