コード例 #1
0
ファイル: ExtEcoreUtils.java プロジェクト: cbrun/emf-compare
  /**
   * Dynamically create an {@link EObject} with a collection called <code>children</code> which
   * contains the given elements.
   *
   * @param collection The initial filling of the collection.
   * @return An {@link EObject} which just has a containment list (named <code>children</code>) of
   *     type {@link EObject}.
   */
  @SuppressWarnings("unchecked")
  public static EObject wrapInGenericContainer(Collection<? extends EObject> collection) {

    // create the wrapper containment reference
    final EReference children = EcoreFactory.eINSTANCE.createEReference();
    children.setName("children");
    children.setLowerBound(0);
    children.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    children.setContainment(true);
    children.setEType(EcorePackage.Literals.EOBJECT);

    // create the wrapper class
    final EClass containerClass = EcoreFactory.eINSTANCE.createEClass();
    containerClass.setName("GenericEContainer");
    containerClass.getEStructuralFeatures().add(children);

    // create a package for our wrapper class
    final EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    ePackage.setName("dynamic");
    ePackage.setNsPrefix("dynamic");
    ePackage.setNsURI("http://www.example.org/dynamic");
    ePackage.getEClassifiers().add(containerClass);

    // validate what we just created
    if (Diagnostician.INSTANCE.validate(ePackage).getCode() == Diagnostic.OK) {

      // instantiate our class, fill the children and return it
      final EObject container = ePackage.getEFactoryInstance().create(containerClass);
      ((EList<EObject>) container.eGet(children)).addAll(collection);
      return container;
    } else {
      throw new UnknownError(
          "Dynamic EMF wrapper model creation failed for whatever reason. Developer, please debug better!");
    }
  }
コード例 #2
0
 private void addOutgoingReference(EClass eClass) {
   EReference outgoingReference = EcoreFactory.eINSTANCE.createEReference();
   outgoingReference.setName(OUTGOING);
   outgoingReference.setLowerBound(0);
   outgoingReference.setUpperBound(-1);
   outgoingReference.setEType(getPlaceClass());
   outgoingReference.setContainment(false);
   eClass.getEStructuralFeatures().add(outgoingReference);
 }
コード例 #3
0
 private void addReference(EClass eClass, String name, EClassifier eType, boolean containment) {
   EReference placesReference = EcoreFactory.eINSTANCE.createEReference();
   placesReference.setName(name);
   placesReference.setLowerBound(0);
   placesReference.setUpperBound(-1);
   placesReference.setEType(eType);
   placesReference.setContainment(containment);
   eClass.getEStructuralFeatures().add(placesReference);
 }