public Value getValue() {
   DataValue value = new DataValue();
   DataType statusType = getStatusType();
   value.type = statusType;
   for (Property attribute : statusType.getOwnedAttributes()) {
     PrimitiveValue attributeValue = null;
     if (attribute.getName().equals("context")) {
       attributeValue = new StringValue();
       attributeValue.type = this.stringType;
       ((StringValue) attributeValue).value = this.context;
     } else if (attribute.getName().equals("code")) {
       attributeValue = new IntegerValue();
       attributeValue.type = this.integerType;
       ((IntegerValue) attributeValue).value = this.code;
     } else if (attribute.getName().equals("description")) {
       attributeValue = new StringValue();
       attributeValue.type = this.stringType;
       ((StringValue) attributeValue).value = this.description;
     }
     List<Value> values = new ArrayList<Value>();
     values.add(attributeValue);
     value.setFeatureValue(attribute, values, 0);
   }
   return value;
 }
  /** @generated */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    Property newElement = UMLFactory.eINSTANCE.createProperty();

    DataType owner = (DataType) getElementToEdit();
    owner.getOwnedAttributes().add(newElement);

    ElementInitializers.getInstance().init_Property_3014(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Esempio n. 3
0
  public RefOntoUML.DataType DealDataType(org.eclipse.uml2.uml.DataType dt1) {
    RefOntoUML.DataType dt2 = null;

    if (dt1 instanceof org.eclipse.uml2.uml.PrimitiveType) {
      // FIXME: Esperar consertarem esse Bug 262140 -  UML primitive types cannot be accessed
      System.out.print("<PrimitiveType> ");
      dt2 = myfactory.createPrimitiveType();
    } else if (dt1 instanceof org.eclipse.uml2.uml.Enumeration) {
      System.out.print("<Enumeration> ");
      dt2 = myfactory.createEnumeration();
    } else {
      System.out.print("<DataType> ");
      dt2 = myfactory.createDataType();
    }

    DealClassifier(dt1, dt2);

    // Attributes
    RefOntoUML.Property p2;
    for (org.eclipse.uml2.uml.Property p1 : dt1.getAttributes()) {
      p2 = myfactory.createProperty();
      DealProperty(p1, p2);
      dt2.getOwnedAttribute().add(p2);
    }

    // Enumeration Literals
    if (dt1 instanceof org.eclipse.uml2.uml.Enumeration) {
      org.eclipse.uml2.uml.Enumeration enum1 = (org.eclipse.uml2.uml.Enumeration) dt1;
      RefOntoUML.Enumeration enum2 = (RefOntoUML.Enumeration) dt2;

      RefOntoUML.EnumerationLiteral el2;
      for (org.eclipse.uml2.uml.EnumerationLiteral el1 : enum1.getOwnedLiterals()) {
        System.out.print("    <EnumLiteral> ");
        el2 = myfactory.createEnumerationLiteral();
        DealNamedElement(el1, el2);

        enum2.getOwnedLiteral().add(el2);
      }
    }

    return dt2;
  }
Esempio n. 4
0
  @Override
  protected void setUp() {
    super.setUp();

    pkg = umlf.createPackage();
    pkg.setName("pkg");

    valueType = pkg.createOwnedPrimitiveType("Value");
    valueType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);

    thingType = pkg.createOwnedClass("Thing", false);

    values = thingType.createOwnedAttribute("values", valueType);
    values.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    values.setIsOrdered(true);
    values.setIsUnique(true);

    bdValue = thingType.createOwnedAttribute("bdValue", getEcoreBigDecimal());
    biValue = thingType.createOwnedAttribute("biValue", getEcoreBigInteger());

    numeroType = pkg.createOwnedClass("Numero", false);

    numeroType
        .createOwnedOperation(
            "+",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "-",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "*",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "/",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "-", ECollections.<String>emptyEList(), ECollections.<Type>emptyEList(), numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "asLong",
            ECollections.<String>emptyEList(),
            ECollections.<Type>emptyEList(),
            getEcoreLong())
        .setIsQuery(true);

    numeros = thingType.createOwnedAttribute("numeros", numeroType);
    numeros.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    numeros.setIsOrdered(true);
    numeros.setIsUnique(true);

    comparable = pkg.createOwnedClass("Comparable", true);
    comparable
        .createOwnedOperation(
            "compareTo",
            new BasicEList<String>(Collections.singleton("c")),
            new BasicEList<Type>(Collections.singleton(comparable)),
            getUMLInteger())
        .setIsQuery(true);

    // the Ecore counterpart

    epkg = UMLUtil.convertToEcore(pkg, null).iterator().next();

    ethingType = (EClass) epkg.getEClassifier(thingType.getName());
    enumeros = (EReference) ethingType.getEStructuralFeature(numeros.getName());
    evalues = (EAttribute) ethingType.getEStructuralFeature(values.getName());
    ebdValue = (EAttribute) ethingType.getEStructuralFeature(bdValue.getName());
    ebiValue = (EAttribute) ethingType.getEStructuralFeature(biValue.getName());

    enumeroType = (EClass) epkg.getEClassifier(numeroType.getName());
    enumeroType.setInstanceClass(Numero.class);

    evalueType = (EDataType) epkg.getEClassifier(valueType.getName());
    evalueType.setInstanceClass(Value.class);

    efactory = epkg.getEFactoryInstance();
    thing = efactory.create(ethingType);

    EPackage.Registry.INSTANCE.put(epkg.getNsURI(), epkg);

    @SuppressWarnings("unchecked")
    EList<Numero> list = (EList<Numero>) thing.eGet(enumeros);
    list.add(new Numero(6));
    list.add(new Numero(2));
  }