/**
   * {@inheritDoc}
   *
   * @see
   *     org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object,
   *     int, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.resource.ResourceSet)
   * @generated
   */
  public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
      editingPart.setContext(elt, allResource);

      final StateMachine stateMachine = (StateMachine) elt;
      final GeneralPropertiesEditionPart generalPart = (GeneralPropertiesEditionPart) editingPart;
      // init values
      if (isAccessible(UmlViewsRepository.General.name))
        generalPart.setName(
            EEFConverterUtil.convertToString(TypesPackage.Literals.STRING, stateMachine.getName()));

      // FIXME NO VALID CASE INTO template public updater(editionElement :
      // PropertiesEditionElement, view : View, pec :
      // PropertiesEditionComponent) in widgetControl.mtl module, with the
      // values : region, General, StateMachine.
      // init filters

      // FIXME NO VALID CASE INTO template public
      // filterUpdater(editionElement : PropertiesEditionElement, view :
      // View, pec : PropertiesEditionComponent) in widgetControl.mtl
      // module, with the values : region, General, StateMachine.
      // init values for referenced views

      // init filters for referenced views

    }
    setInitializing(false);
  }
 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);
     }
   }
 }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
  * @generated
  */
 public void updateSemanticModel(final IPropertiesEditionEvent event) {
   StateMachine stateMachine = (StateMachine) semanticObject;
   if (UmlViewsRepository.General.name == event.getAffectedEditor()) {
     stateMachine.setName(
         (java.lang.String)
             EEFConverterUtil.createFromString(
                 TypesPackage.Literals.STRING, (String) event.getNewValue()));
   }
   if (UmlViewsRepository.General.region == event.getAffectedEditor()) {
     // FIXME INVALID CASE you must override the template
     // 'declareEObjectUpdater' for the case : region, General,
     // StateMachine.
   }
 }
  public static StateMachine loadStateMachine(URI modelUri) {
    org.eclipse.uml2.uml.Package model = UMLLoader.loadUMLModel(modelUri);

    StateMachine umlStateMachine = null;
    if (model != null) {
      umlStateMachine =
          (StateMachine)
              model.getPackagedElement(null, true, UMLPackage.Literals.STATE_MACHINE, false);
    }

    if (umlStateMachine != null && logger.isDebugEnabled()) {
      logger.debug(
          "loadStateMachine() loaded state machine with owned elements "
              + umlStateMachine.getOwnedElements());
    }

    return umlStateMachine;
  }
  @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
Esempio n. 6
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;
  }