/** @generated */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    Enumeration newElement = UMLFactory.eINSTANCE.createEnumeration();

    EObject target = getElementToEdit();
    ModelAddData data = PolicyChecker.getCurrent().getChildAddData(diagram, target, newElement);
    if (data.isPermitted()) {
      if (data.isPathDefined()) {
        if (!data.execute(target, newElement)) {
          return CommandResult.newErrorCommandResult(
              "Failed to follow the policy-specified for the insertion of the new element");
        }
      } else {

        Class qualifiedTarget = (Class) target;
        qualifiedTarget.getNestedClassifiers().add(newElement);
      }
    } else {
      return CommandResult.newErrorCommandResult(
          "The active policy restricts the addition of this element");
    }

    ElementInitializers.getInstance().init_Enumeration_3052(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Beispiel #2
0
 public org.eclipse.uml2.uml.Class buildClass(String name) {
   org.eclipse.uml2.uml.Class clazz = createClass();
   if (name != null) {
     clazz.setName(name);
   }
   return clazz;
 }
  /**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports (on node) from
   * the model content view , the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromModelContentView() {

    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    final Property firstProperty = class3.getOwnedAttribute("Prop3to2", class2);
    final Property secondProperty = class3.getOwnedAttribute("OtherProp3to2", class2);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
 /** @generated */
 protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
     throws ExecutionException {
   Interface newElement = UMLFactory.eINSTANCE.createInterface();
   Class owner = (Class) getElementToEdit();
   owner.getNestedClassifiers().add(newElement);
   ElementInitializers.getInstance().init_Interface_3036(newElement);
   doConfigure(newElement, monitor, info);
   ((CreateElementRequest) getRequest()).setNewElement(newElement);
   return CommandResult.newOKCommandResult(newElement);
 }
 public static void setStateMachineContextClasses(
     HashMap<org.eclipse.uml2.uml.StateMachine, Set<org.eclipse.uml2.uml.Class>> in_colContexts,
     ConfigurationSetter io_oConfigurationSetter) {
   for (StateMachine oStateMachine : in_colContexts.keySet()) {
     io_oConfigurationSetter.getName2StateMachine().put(oStateMachine.getName(), oStateMachine);
     HashMap<String, org.eclipse.uml2.uml.Class> oName2Class =
         new HashMap<String, org.eclipse.uml2.uml.Class>();
     io_oConfigurationSetter.getStateMachine2Name2Class().put(oStateMachine, oName2Class);
     for (org.eclipse.uml2.uml.Class oClass : in_colContexts.get(oStateMachine)) {
       oName2Class.put(oClass.getName(), oClass);
     }
   }
 }
  @Test
  public void shouldReturnFalseIfIsNotVariability2()
      throws ModelNotFoundException, ModelIncompleteException,
          SMartyProfileNotAppliedToModelExcepetion, IOException {

    String uri = getUrlToModel("variabilitySem");
    String absolutePath = new File(uri).getAbsolutePath();
    Package model = uml2Helper.load(absolutePath);

    org.eclipse.uml2.uml.Class klass = modelHelper.getAllClasses(model).get(0);
    assertNotNull(klass);

    assertEquals("Class1", klass.getName());
    assertFalse(StereotypeHelper.isVariability(klass));
  }
 public ComplexType find(Class source) {
   if (types == null) {
     types = Maps.newTreeMap(Comparators.stringComparator);
     for (IResourceDescription desc : index.getAllResourceDescriptions()) {
       for (IEObjectDescription objDesc :
           desc.getExportedObjectsByType(DatamodelPackage.eINSTANCE.getComplexType())) {
         ComplexType t = (ComplexType) objDesc.getEObjectOrProxy();
         types.put(t.getName(), t);
       }
     }
   }
   if (source.eIsProxy()) {
     throw new IllegalStateException("Proxy not resolved: " + source);
   }
   return types.get(source.getName());
 };
  void assertStereotypeApplication() {
    assertThat("Stereotype not applied to the class", class1.isStereotypeApplied(stereotype));
    EObject application = class1.getStereotypeApplication(stereotype);
    EClass eclass = application.eClass();

    // Verify an Enumeration value stored as an XML attribute
    Object value = application.eGet(eclass.getEStructuralFeature("alertLevel"));
    assertThat(
        "Alert level is not yellow",
        (value instanceof Enumerator) && ((Enumerator) value).getLiteral().equals("yellow"),
        is(true));

    // Verify a multi-valued attribute stored as XML elements
    value = application.eGet(eclass.getEStructuralFeature("tag"));
    assertThat("Wrong tags found", value, is((Object) Arrays.asList("p2", "silver")));

    // Verify a reference value stored as an XML IDREFS attribute
    value = application.eGet(eclass.getEStructuralFeature("appliesTo"));
    assertThat("Wrong appliesTo found", value, is((Object) class1.getOwnedAttributes()));

    // Verify a contained EObject that is a complex DataType value
    value = application.eGet(eclass.getEStructuralFeature("name"));
    {
      assertThat("Value is not an EList", value, instanceOf(EList.class));
      EList<?> list = (EList<?>) value;

      assertThat("List has wrong number of elements", list.size(), is(1));
      value = list.get(0);

      assertThat("Value is not an EObject", value, instanceOf(EObject.class));
      EObject name = (EObject) value;
      EClass dataType = name.eClass();

      assertThat(
          "Wrong firstName",
          name.eGet(dataType.getEStructuralFeature("firstName")),
          is((Object) "Christian"));
      assertThat(
          "Wrong lastName",
          name.eGet(dataType.getEStructuralFeature("lastName")),
          is((Object) "Damus"));
      assertThat(
          "Wrong initials",
          name.eGet(dataType.getEStructuralFeature("initials")),
          is((Object) Arrays.asList("W")));
    }
  }
Beispiel #9
0
  public RefOntoUML.Class DealClassStereotype(org.eclipse.uml2.uml.Class c1) {
    System.out.print("<Class> ");
    RefOntoUML.Class c2 = null;

    if (c1.getAppliedStereotypes().size() == 1) {
      org.eclipse.uml2.uml.Stereotype s = c1.getAppliedStereotypes().get(0);

      System.out.print("<<" + s.getName() + ">> ");
      String stereoname = s.getName();

      if (stereoname.compareTo("Kind") == 0) {
        c2 = myfactory.createKind();
      } else if (stereoname.compareTo("SubKind") == 0) {
        c2 = myfactory.createSubKind();
      } else if (stereoname.compareTo("Collective") == 0) {
        c2 = myfactory.createCollective();

        boolean isExtensional = (Boolean) c1.getValue(s, "isExtensional");
        ((RefOntoUML.Collective) c2).setIsExtensional(isExtensional);
      } else if (stereoname.compareTo("Quantity") == 0) {
        c2 = myfactory.createQuantity();
      } else if (stereoname.compareTo("Role") == 0) {
        c2 = myfactory.createRole();
      } else if (stereoname.compareTo("Phase") == 0) {
        c2 = myfactory.createPhase();
      } else if (stereoname.compareTo("Category") == 0) {
        c2 = myfactory.createCategory();
      } else if (stereoname.compareTo("Mixin") == 0) {
        c2 = myfactory.createMixin();
      } else if (stereoname.compareTo("RoleMixin") == 0) {
        c2 = myfactory.createRoleMixin();
      } else if (stereoname.compareTo("Relator") == 0) {
        c2 = myfactory.createRelator();
      } else if (stereoname.compareTo("Mode") == 0) {
        c2 = myfactory.createMode();
      } else if (stereoname.compareTo("Quality") == 0) {
        c2 = myfactory.createQuality();
      }
    } else if (c1.getAppliedStereotypes().size() == 0) {
      c2 = myfactory.createSubKind();
    }

    DealClass(c1, c2);
    return c2;
  }
Beispiel #10
0
  public void DealClass(org.eclipse.uml2.uml.Class c1, RefOntoUML.Class c2) {
    DealClassifier(c1, c2);

    // Attributes
    RefOntoUML.Property p2;
    for (org.eclipse.uml2.uml.Property p1 : c1.getAttributes()) {
      p2 = myfactory.createProperty();
      DealProperty(p1, p2);
      c2.getOwnedAttribute().add(p2);
    }
  }
  /**
   * Checks if a transition is one of the operations of its containing class. Pending: it only
   * checks against its name and not its entire signature.
   */
  public boolean isTransitionInClass(String transitionName, Class transitionClass) {

    // checks if the transition class is not empty. E.g. a feature that does not define that class
    if (transitionClass == null) return false;

    // Checks the operations looking for a name
    for (Operation operation : transitionClass.getOperations()) {
      if (operation.getName().equals(transitionName)) return true;
    }
    return false;
  }
Beispiel #12
0
 public Operation createOwnedOperation(
     Class aClass,
     String name,
     EList<String> paramNames,
     EList<Type> paramTypes,
     Type type,
     boolean isQuery) {
   Operation operation = aClass.createOwnedOperation(name, paramNames, paramTypes, type);
   if (isQuery) {
     operation.setIsQuery(true);
   }
   return operation;
 }
 /**
  * Retrieves all the connectors between subcomponents inside a given component model. (does not
  * retrieve connectors between component model boundaries and subcomponents inside the model).
  */
 public static List<org.eclipse.uml2.uml.Connector> getInternalConnectors(
     org.eclipse.uml2.uml.Class c) {
   LinkedList<org.eclipse.uml2.uml.Connector> connectors =
       new LinkedList<org.eclipse.uml2.uml.Connector>();
   for (Connector conn : c.getOwnedConnectors()) {
     if (conn.getEnds().size() >= 2
         && (conn.getEnds().get(0).getPartWithPort() != null)
         && (conn.getEnds().get(1).getPartWithPort() != null)) {
       connectors.add(conn);
     }
   }
   return connectors;
 }
Beispiel #14
0
  /** Tests that unrecognized data types are represented by themselves, not by OclAny. */
  public void test_dataTypes_137158() {
    Package upackage = umlf.createPackage();
    upackage.setName("mypkg");
    Class uclass = upackage.createOwnedClass("B", false);
    DataType datatype = (DataType) pkg.createOwnedType("Thread", uml.getDataType());
    Operation operation = uclass.createOwnedOperation("f", null, null, datatype);
    operation.setIsQuery(true);

    helper.setContext(uclass);

    try {
      OCLExpression<Classifier> expr = helper.createQuery("self.f()");

      Classifier type = expr.getType();
      assertSame(datatype, type);

      operation.setUpper(LiteralUnlimitedNatural.UNLIMITED);

      expr = helper.createQuery("self.f()");

      type = expr.getType();
      assertTrue(type instanceof CollectionType<?, ?>);
      type = ((org.eclipse.ocl.uml.CollectionType) type).getElementType();
      assertSame(datatype, type);

      operation.setUpper(1);
      operation.setType(ocl.getEnvironment().getOCLStandardLibrary().getOclAny());

      expr = helper.createQuery("self.f()");

      type = expr.getType();
      assertSame(getOCLStandardLibrary().getOclAny(), type);
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
        public ComplexType configure(Class source, ComplexType target) {
          target.setName(source.getName());
          if (!source.getSuperClasses().isEmpty()) {
            ComplexType baseType = apply(source.getSuperClasses().get(0));
            target.setBaseType(baseType);
          }

          List<Property> properties =
              Lists.newArrayList(
                  Iterables.concat(
                      source.getOwnedAttributes(), getNavigableAssociationEnds(source)));
          Collections.sort(properties, Comparators.namedElementComparator);
          for (Property p : properties) {
            ElementDeclaration element = createElementDeclaration.apply(p);
            target.getElements().add(element);
          }

          target.setDoc(JavaExtensions.getDocumentationText(source));

          addXmiId(source, getXmiId(source));
          // target.getAnnotations().add(createTraceAnnotation.apply(source));

          return target;
        }
 /**
  * On a given class (a RobotML system), retrieve all the contained systems. Not recursive.
  * Retrieves only one level deep.
  */
 public static List<org.eclipse.uml2.uml.Property> getLevel1SubComponentsForComponent(
     org.eclipse.uml2.uml.Class c) {
   LinkedList<org.eclipse.uml2.uml.Property> sub_components =
       new LinkedList<org.eclipse.uml2.uml.Property>();
   for (org.eclipse.uml2.uml.Property prop : c.getAllAttributes()) {
     Type t = prop.getType();
     if (t instanceof org.eclipse.uml2.uml.Class) {
       if (GeneralQueries.hasStereotype(
           (org.eclipse.uml2.uml.Class) t, org.eclipse.papyrus.RobotML.System.class)) {
         sub_components.add(prop);
       }
     }
   }
   return sub_components;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public org.eclipse.uml2.uml.Class getBase_Class() {
   if (base_Class != null && base_Class.eIsProxy()) {
     InternalEObject oldBase_Class = (InternalEObject) base_Class;
     base_Class = (org.eclipse.uml2.uml.Class) eResolveProxy(oldBase_Class);
     if (base_Class != oldBase_Class) {
       if (eNotificationRequired())
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 GenericconstraintsPackage.GENERIC_CONSTRAINT_SET__BASE_CLASS,
                 oldBase_Class,
                 base_Class));
     }
   }
   return base_Class;
 }
 /**
  * On a given class (a RobotML system), retrieve all the contained systems. Not recursive.
  * Retrieves only one level deep.
  *
  * @deprecated replaced by getLevel1SubComponentsForComponent(org.eclipse.uml2.uml.Class c) which
  *     uses the RobotML API instead of stereotype names.
  */
 @Deprecated
 public static List<org.eclipse.uml2.uml.Property>
     getLevel1SubComponentsForComponentWithStereotype(
         org.eclipse.uml2.uml.Class c, String stereotype) {
   LinkedList<org.eclipse.uml2.uml.Property> sub_components =
       new LinkedList<org.eclipse.uml2.uml.Property>();
   for (Property prop : c.getAllAttributes()) {
     Type t = prop.getType();
     if (t instanceof org.eclipse.uml2.uml.Class) {
       // if(GeneralQueries.hasStereotype((org.eclipse.uml2.uml.Class) t, stereotype))
       if (GeneralQueries.inheritsFrom((org.eclipse.uml2.uml.Class) t, stereotype)) {
         sub_components.add(prop);
       }
     }
   }
   return sub_components;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public org.eclipse.uml2.uml.Class getBase_Class() {
   if (base_Class != null && base_Class.eIsProxy()) {
     InternalEObject oldBase_Class = (InternalEObject) base_Class;
     base_Class = (org.eclipse.uml2.uml.Class) eResolveProxy(oldBase_Class);
     if (base_Class != oldBase_Class) {
       if (eNotificationRequired())
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 FCMPackage.IMPLEMENTATION_PROPERTIES__BASE_CLASS,
                 oldBase_Class,
                 base_Class));
     }
   }
   return base_Class;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public org.eclipse.uml2.uml.Class getBase_Class() {
   if (base_Class != null && base_Class.eIsProxy()) {
     InternalEObject oldBase_Class = (InternalEObject) base_Class;
     base_Class = (org.eclipse.uml2.uml.Class) eResolveProxy(oldBase_Class);
     if (base_Class != oldBase_Class) {
       if (eNotificationRequired())
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 BpmnprofPackage.MONITORING__BASE_CLASS,
                 oldBase_Class,
                 base_Class));
     }
   }
   return base_Class;
 }
  protected Iterable<Property> getNavigableAssociationEnds(final Class cls) {
    List<Property> result = Lists.newArrayList();
    for (Association assoc : cls.getAssociations()) {
      final Iterable<Property> ends =
          Iterables.filter(
              assoc.getMemberEnds(),
              new Predicate<Property>() {
                public boolean apply(Property input) {
                  return input.isNavigable() && input.getType() != cls;
                }
              });

      for (Property p : ends) {
        result.add(p);
      }
    }
    return result;
  }
  public static Boolean isAnAncestorOf(Class current_elt, Class other_elt) {
    Boolean result = false;
    if (current_elt != null && other_elt != null) {
      if (current_elt == other_elt) {
        result = true;
      } else {
        for (Class parent : current_elt.getSuperClasses()) {
          current_elt = parent;
          if (other_elt == current_elt) {
            result = true;
            break;
          }
        }
      }
    }

    return result;
  }
 /**
  * Retrieves all the connectors between subcomponents that are inside the component model and the
  * component model outputs. (does not retrieve connectors between subcomponents inside the
  * component model, nor connectors from component model inputs to subcomponents).
  */
 public static List<org.eclipse.uml2.uml.Connector> getExternalOutputConnectors(
     org.eclipse.uml2.uml.Class c) {
   LinkedList<org.eclipse.uml2.uml.Connector> connectors =
       new LinkedList<org.eclipse.uml2.uml.Connector>();
   for (Connector conn : c.getOwnedConnectors()) {
     if (conn.getEnds().size() >= 2) { // && (conn.getEnds().get(0).getPartWithPort() != null)) {
       if (conn.getEnds().get(0).getRole() instanceof Port
           && conn.getEnds().get(1).getRole() instanceof Port) {
         Port port_1 = (Port) conn.getEnds().get(0).getRole();
         Port port_2 = (Port) conn.getEnds().get(1).getRole();
         if ((isAnOutputPort(port_1) && conn.getEnds().get(0).getPartWithPort() == null)
             || (isAnOutputPort(port_2) && conn.getEnds().get(1).getPartWithPort() == null)) {
           connectors.add(conn);
         }
       }
     }
   }
   return connectors;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public org.eclipse.uml2.uml.Class getBase_Class() {
   if (base_Class != null && base_Class.eIsProxy()) {
     InternalEObject oldBase_Class = (InternalEObject) base_Class;
     base_Class = (org.eclipse.uml2.uml.Class) eResolveProxy(oldBase_Class);
     if (base_Class != oldBase_Class) {
       if (eNotificationRequired()) {
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 HardwaremodelingPackage.HARDWARE_PORT_CONNECTOR__BASE_CLASS,
                 oldBase_Class,
                 base_Class));
       }
     }
   }
   return base_Class;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public org.eclipse.uml2.uml.Class getBase_Class() {
   if (base_Class != null && base_Class.eIsProxy()) {
     InternalEObject oldBase_Class = (InternalEObject) base_Class;
     base_Class = (org.eclipse.uml2.uml.Class) eResolveProxy(oldBase_Class);
     if (base_Class != oldBase_Class) {
       if (eNotificationRequired()) {
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 SystemmodelingPackage.VEHICLE_LEVEL__BASE_CLASS,
                 oldBase_Class,
                 base_Class));
       }
     }
   }
   return base_Class;
 }
Beispiel #26
0
 @Override
 protected Activity createProduct() {
   Class parentClass = (Class) getParent().as(ClassifierBuilder.class).getProduct();
   Activity activity = (Activity) parentClass.createNestedClassifier(null, getEClass());
   return activity;
 }
  @Override
  public Map<Feature, SortedSet<Feature>> apply(SPL spl) {

    // Obtains the list of features of the SPL where this rule will be applied
    List<Feature> listFeatures = spl.getFeatures();

    // ***********************************************************************
    // ***********************************************************************

    // ******************* Gathers the information from the features

    // **************** Creates necessary data structures
    StateMachine stateMachine;
    List<Class> classes;
    List<TransitionData> transitions;

    // Maps features to the classes that they define
    Map<Feature, List<Class>> mapFeatureToClasses = new HashMap<Feature, List<Class>>();

    // Maps features to the transition data that they contain
    Map<Feature, List<TransitionData>> mapFeatureToTransitionData =
        new HashMap<Feature, List<TransitionData>>();

    // Reads the messages of all features
    for (Feature feature : listFeatures) {

      // @debug
      // System.out.println("\n\transition of feature " + feature.getName());

      // if the package diagram does not exists, add the entries with no objects and skip
      if (feature.getClassDiagram() == null) {
        transitions = new LinkedList<TransitionData>();
        mapFeatureToTransitionData.put(feature, transitions);

        classes = new LinkedList<Class>();

        // Adds the collected classes to the feature
        mapFeatureToClasses.put(feature, classes);

        continue;
      }

      // Gets the classes of a feature
      classes =
          SCUtils.filterList(
              feature.getClassDiagram().getPackagedElements(), UMLPackage.Literals.CLASS);

      // The list of associations will be sorted by name of association
      Collections.sort(classes, new ClassComparator());

      // maps a feature to its classes
      mapFeatureToClasses.put(feature, classes);

      // Resets the list of transitions for the feature
      transitions = new LinkedList<TransitionData>();

      // Gets the state machines out of the classes
      for (Class klass : classes) {
        for (Behavior behavior : klass.getOwnedBehaviors()) {

          // @debug
          // System.out.println("Behavior name " + behavior.getName());

          // if the owned behavior is a state machine record its information
          if (behavior instanceof StateMachine) {

            // @debug
            // System.out.println("It is state machine");

            stateMachine = (StateMachine) behavior;

            // Traverses all regions in the state machine to get their transitions
            for (Region region : stateMachine.getRegions()) {
              for (Transition transition : region.getTransitions()) {
                transitions.add(
                    new TransitionData(
                        transition.getName(), stateMachine.getName(), klass, region.getName()));

                // @debug
                // System.out.println("transition " + transition.getName());

              } // for all transitions
            } // for all regions
          } // of state machine
        } // for all behaviors in the class
      } // for all classes

      // The list of associations will be sorted by name of association
      Collections.sort(transitions, new TransitionDataComparator());

      // maps the transition data to the features
      mapFeatureToTransitionData.put(feature, transitions);
    } // for all features

    // @debug
    /*
    System.out.println("Printing collected feature data");
    for (Feature feature : listFeatures) {
    	transitions = mapFeatureToTransitionData.get(feature);
    	System.out.println("Feature "  + feature.getName());
    	for (TransitionData transitionData :  transitions) {
    		System.out.println(transitionData);
    	}
    } // of all features
    */

    // ***********************************************************************
    // ***********************************************************************

    // ******************* Performs the Safe Composition Checking
    /* Algorithm to follow
     1. For each feature f
      2. for each transition t in f
         3. if t is an operation of its containing class
             done --- create instance rule but do not evaluate
         4. otherwise, if t is not an operation in containing class
             create a new rule instance <transition_name, source feature, class_name, requiringFeatures>
            5. for each compatible feature g
              6. if transition is operation of a class in g
                7. add the feature to requiringFeatures of rule instance

    */

    // Map of a feature to the features it is compatible with
    Map<Feature, SortedSet<Feature>> compatibleFeatures = spl.getCompatibleFeatures();

    // List with the rule instances detected
    List<IRuleInstance<TransitionData>> listRuleInstances =
        new LinkedList<IRuleInstance<TransitionData>>();

    //  List of the features that re required by an instance of a rule
    Set<Feature> requiringFeatures = new TreeSet<Feature>();

    // @debug
    // System.out.println("\n\n Detecting inconsistencies ");

    // 1. For each feature
    for (Feature f : listFeatures) {

      // @debug
      // System.out.println("\nFeature " +  f.getName());

      // Get message data
      transitions = mapFeatureToTransitionData.get(f);

      // Writes the header of the feature being checked
      spl.writeAnalysisResult(f.getName());

      // 2. for each transition in f
      for (TransitionData transitionData : transitions) {

        // 3. if t is an operation of its containing class done ! --- create instance rule but do
        // not evaluate
        if (isTransitionInClass(transitionData.name, transitionData.klass)) {
          // create instance rule that is not evaluated evaluate
          listRuleInstances.add(
              new RuleInstance(
                  transitionData.name, f, new TreeSet<Feature>(), false, transitionData));

          // @debug
          // System.out.println("Transition " + transitionData.name + " already defined in class");

          continue;
        }

        // 4. otherwise, if t is not an operation in containing class
        //     create a new rule instance <transition_name, source feature, class_name,
        // requiringFeatures>
        // creates a blank copy for the required features of this message
        requiringFeatures = new TreeSet<Feature>();

        // 5. for each compatible feature g
        for (Feature g : compatibleFeatures.get(f)) {

          // 6. if transition is operation of a class in g
          if (isTransitionInClass(
              transitionData.name,
              SCUtils.findClass(transitionData.klass.getName(), mapFeatureToClasses.get(g)))) {
            // add the feature to requiringFeatures of rule instance
            requiringFeatures.add(g);

            // @debug
            // System.out.println("\t defined in feature " + g.getName());
          }
        } // of compatible features

        // create a new rule instance <message_name, source feature, source class, target class,
        // requiringFeatures>
        listRuleInstances.add(
            new RuleInstance(transitionData.name, f, requiringFeatures, true, transitionData));
      } // for each transition data
    } // for each feature f

    // ******************* Computes the propositional logic formulas

    // Checks safe composition on each of the rule instances
    SCUtils.checkSafeComposition(this, listRuleInstances, spl);

    // Displays the result in a table
    String[] columnNames = {
      "Transition", "QName", "SC", "Error", "Imp", "Consistent", "msec", "Remarks"
    };
    int[] columnWidths = {100, 300, 100, 100, 100, 100, 100, 100};
    int[] columnAlignments = {
      SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT
    };

    RuleInstanceTableViewer<TransitionData> tableViewer =
        new RuleInstanceTableViewer<TransitionData>(
            "Rule 6 for product line " + spl.getSPLName(),
            columnNames,
            columnWidths,
            columnAlignments,
            new RuleLabelProvider(),
            listRuleInstances);
    tableViewer.open();

    // @debug
    System.out.println("Rule 6 instances " + listRuleInstances.size());

    // TODO Auto-generated method stub
    return null;
  } // of apply
 /**
  * Computes the comma separated string for cvs output
  *
  * @return
  */
 public String commaSeparated() {
   String result = new String();
   result =
       "< " + name + "," + stateMachineName + "," + klass.getName() + "," + regionName + ">";
   return result;
 }
 /**
  * Overrides default toString
  *
  * @see java.lang.Object#toString()
  */
 public String toString() {
   String result = new String();
   result =
       "< " + name + " " + stateMachineName + " " + klass.getName() + " " + regionName + ">";
   return result;
 }
Beispiel #30
0
  public ArrayList<SM> getRefModelDetails(ModelFile modelFile) throws Exception {
    ArrayList<SM> stateMachineDetails = new ArrayList<>();
    UMLModelLoader umlModel = new UMLModelLoader();
    EList<PackageableElement> packageableElements;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len;
    while ((len = modelFile.getModel().read(buffer)) > -1) {
      baos.write(buffer, 0, len);
    }
    baos.flush();
    modelFile.setModel(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())));
    Model _model =
        umlModel.loadModel(
            new ModelFile(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray()))));

    if (_model == null) {
      Package _package = umlModel.loadPackage(modelFile);
      packageableElements = _package.getPackagedElements();
    } else {
      packageableElements = _model.getPackagedElements();
    }

    for (PackageableElement element : packageableElements) {
      if (element.eClass() == UMLPackage.Literals.CLASS) {
        Class c = (Class) element;
        EList<Behavior> ownedBehaviors = c.getOwnedBehaviors();
        for (Behavior beh : ownedBehaviors) {
          if (beh.eClass() == UMLPackage.Literals.STATE_MACHINE) {

            // System.out.println("Class Name : "+parentClassName);
            // if (element.eClass() == UMLPackage.Literals.STATE_MACHINE) {
            StateMachine stateMachine = (StateMachine) beh;
            // System.out.println("Parent  :  "+parentClassName);

            EList<Region> regions = stateMachine.getRegions();
            for (Region reg : regions) {
              // System.out.println("Region : " + reg.getLabel());
              EList<Vertex> vertices = reg.getSubvertices();

              for (Vertex vertex : vertices) {
                SM smDetails = new SM();
                if (vertex.eClass() == UMLPackage.Literals.STATE) {
                  //		System.out.println("Vertex : "+vertex.getName());

                  smDetails.setName(vertex.getLabel());
                  ArrayList<TransitionDetails> transition = new ArrayList<>();
                  transition = readVertices(vertex, smDetails);
                  smDetails.setTransitions(transition);
                  stateMachineDetails.add(smDetails);
                }
              }
            }

            //			EList<Behavior> ownedBehaviors = c.getOwnedBehaviors();
            //			for (Behavior beh : ownedBehaviors) {
            //				if (beh.eClass() == UMLPackage.Literals.STATE_MACHINE){
            //					System.out.println(beh.getName());
            //					readBehaviours(beh);
          }
        }
      }
    }

    return stateMachineDetails;
  }