Esempio 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);
  }
Esempio 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!");
    }
  }
Esempio 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);
 }
Esempio 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);
 }
Esempio n. 5
0
  private static EPackage getEmployeePackage() {
    EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE;
    EcorePackage ecorePackage = EcorePackage.eINSTANCE;

    EPackage employeePackage = ecoreFactory.createEPackage();
    employeePackage.setName("emp");
    employeePackage.setNsPrefix("emp");
    employeePackage.setNsURI("http://www.example.com/Emp");

    employeeClass = ecoreFactory.createEClass();
    employeePackage.getEClassifiers().add(employeeClass);
    employeeClass.setName("Employee");

    EClass poClass = ecoreFactory.createEClass();
    employeePackage.getEClassifiers().add(poClass);
    poClass.setName("PurchaseOrder");

    nameAttr = ecoreFactory.createEAttribute();
    employeeClass.getEStructuralFeatures().add(nameAttr);
    nameAttr.setName("name");
    nameAttr.setEType(ecorePackage.getEString());

    // to test multiplicity-many attributes.
    ratingsAttr = ecoreFactory.createEAttribute();
    employeeClass.getEStructuralFeatures().add(ratingsAttr);
    ratingsAttr.setName("phoneNumbers");
    ratingsAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    ratingsAttr.setEType(ecorePackage.getEIntegerObject());

    // create a one-way reference to an Employee, employeesRef.
    // This is used to test cases described in cases.gif.
    employeesRef = ecoreFactory.createEReference();
    employeeClass.getEStructuralFeatures().add(employeesRef);
    employeesRef.setName("employees");
    employeesRef.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    employeesRef.setEType(employeeClass);

    // to test FeatureMaps with EAttributes Entries
    ordersAttr = ecoreFactory.createEAttribute();
    employeeClass.getEStructuralFeatures().add(ordersAttr);
    ordersAttr.setName("orders");
    ordersAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    ordersAttr.setEType(ecorePackage.getEFeatureMapEntry());
    ExtendedMetaData.INSTANCE.setFeatureKind(ordersAttr, ExtendedMetaData.GROUP_FEATURE);

    preferredAttr = ecoreFactory.createEAttribute();
    employeeClass.getEStructuralFeatures().add(preferredAttr);
    preferredAttr.setName("preferredOrders");
    preferredAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    preferredAttr.setEType(ecorePackage.getEString());
    preferredAttr.setVolatile(true);
    preferredAttr.setTransient(true);
    preferredAttr.setDerived(true);
    ExtendedMetaData.INSTANCE.setGroup(preferredAttr, ordersAttr);

    standardAttr = ecoreFactory.createEAttribute();
    employeeClass.getEStructuralFeatures().add(standardAttr);
    standardAttr.setName("standardOrders");
    standardAttr.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    standardAttr.setEType(ecorePackage.getEString());
    standardAttr.setVolatile(true);
    standardAttr.setTransient(true);
    standardAttr.setDerived(true);
    ExtendedMetaData.INSTANCE.setGroup(standardAttr, ordersAttr);

    return employeePackage;
  }