Exemplo n.º 1
0
  @Before
  public void before() {
    ePackage = FACTORY.createEPackage();
    ePackage.setName("Package");

    eClass0 = FACTORY.createEClass();
    eClass0.setName("EClass0");
    ePackage.getEClassifiers().add(eClass0);

    eClass1 = FACTORY.createEClass();
    eClass1.setName("EClass1");
    ePackage.getEClassifiers().add(eClass1);

    singleRef = FACTORY.createEReference();
    singleRef.setName("singleRef");
    singleRef.setUpperBound(1);
    singleRef.setEType(eClass1);
    singleRef.setContainment(true);
    eClass0.getEStructuralFeatures().add(singleRef);

    multiRef = FACTORY.createEReference();
    multiRef.setName("multiRef");
    multiRef.setUpperBound(-1);
    multiRef.setEType(eClass0);
    multiRef.setContainment(true);
    eClass1.getEStructuralFeatures().add(multiRef);
  }
Exemplo n.º 2
0
  /**
   * 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!");
    }
  }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
 }