Search in sources :

Example 1 with DispatchTrigger

use of org.osate.ba.aadlba.DispatchTrigger in project osate2 by osate.

the class AadlBaConsistencyRulesChecker method D_3_C4_Check.

/**
 * Document: AADL Behavior Annex draft
 * Version : 0.94
 * Type    : Consistency rule
 * Section : D.3 Behavior Specification
 * Object  : Check consistency rule D.3.(C4)
 * Keys    : complete state mode behavior condition mode transition triggers
 */
public boolean D_3_C4_Check(BehaviorTransition btOwner, Identifier srcState) {
    // [OPTIM] -------------------------------------------------------------
    // these checking can be moved to the rules driver in order to optimize.
    BehaviorState bs = (BehaviorState) srcState.getBaRef();
    BehaviorState declaredState = null;
    if (bs.getName().equalsIgnoreCase(srcState.getId())) {
        declaredState = bs;
    }
    // with true.
    if (declaredState.getBindedMode() == null) {
        return true;
    }
    // ---------------------------------------------------------------------
    // At this point, one of the current behavior transtion's src states
    // represent a mode.
    DispatchTriggerLogicalExpression dtle;
    Mode mode = declaredState.getBindedMode();
    // trigger logical expression is analyzed.
    if (btOwner.getCondition() instanceof DispatchCondition) {
        DispatchCondition dc = (DispatchCondition) btOwner.getCondition();
        if (dc.getDispatchTriggerCondition() instanceof DispatchTriggerLogicalExpression) {
            dtle = (DispatchTriggerLogicalExpression) dc.getDispatchTriggerCondition();
        } else {
            // At least, there is one mode transition trigger in a mode
            // transition. So this transition is not consistency.
            reportConsistencyError(srcState, "The behavior transition tries " + "to refine a transition mode but it hasn't got any dispatch " + "trigger logical expression: Behavior Annex D.3.(C4) " + "consistency rule failed");
            return false;
        }
    } else {
        // exit with false result.
        return false;
    }
    EList<ModeTransition> lModeTrans = Aadl2Visitors.getElementsInNamespace(_baParentContainer, ModeTransition.class);
    // any transition mode.
    if (lModeTrans.isEmpty()) {
        reportConsistencyError(srcState, "The behavior transition tries to " + "refine a transition mode while " + _baParentContainer.getQualifiedName() + " component hasn't got any transition mode: " + "Behavior Annex D.3.(C4) consistency rule failed");
        return false;
    }
    // At this point preliminary checking has been passed.
    List<String> lModeTriggs = new ArrayList<String>();
    // Fetches dispatch trigger names in the given behavior transition.
    List<String> ldispTriggs = new ArrayList<String>();
    for (DispatchTrigger trigg : AadlBaVisitors.getDispatchTriggers(dtle)) {
        ActualPortHolder portHolder = (ActualPortHolder) trigg;
        ldispTriggs.add(portHolder.getPort().getName());
    }
    // Otherwise reports an error.
    for (ModeTransition mTrans : lModeTrans) {
        // If the transition mode contains the considered mode:
        if (mTrans.getSource().getName().equalsIgnoreCase(mode.getName())) {
            // Fetches mode transition trigger names.
            for (ModeTransitionTrigger mtt : mTrans.getOwnedTriggers()) {
                lModeTriggs.add(AadlBaUtils.getName(mtt));
            }
            // considering their order.
            if (Aadl2Utils.compareStringList(ldispTriggs, lModeTriggs)) {
                return true;
            } else {
                lModeTriggs.clear();
                continue;
            }
        }
    // Else continue to the next transition mode.
    }
    // Error case : the given behavior transition which is out of a mode
    // is not consisting with any transition mode which involves the considered
    // mode.
    reportConsistencyError(srcState, "The behavior transition tries to " + "refine a transition mode but it is not consisting with any " + "transition mode of " + _baParentContainer.getQualifiedName() + " component: Behavior Annex D.3.(C4) consistency rule failed");
    return false;
}
Also used : DispatchCondition(org.osate.ba.aadlba.DispatchCondition) DispatchTriggerLogicalExpression(org.osate.ba.aadlba.DispatchTriggerLogicalExpression) Mode(org.osate.aadl2.Mode) ArrayList(java.util.ArrayList) ActualPortHolder(org.osate.ba.aadlba.ActualPortHolder) ModeTransition(org.osate.aadl2.ModeTransition) BehaviorState(org.osate.ba.aadlba.BehaviorState) DispatchTrigger(org.osate.ba.aadlba.DispatchTrigger) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Aggregations

ArrayList (java.util.ArrayList)1 Mode (org.osate.aadl2.Mode)1 ModeTransition (org.osate.aadl2.ModeTransition)1 ModeTransitionTrigger (org.osate.aadl2.ModeTransitionTrigger)1 ActualPortHolder (org.osate.ba.aadlba.ActualPortHolder)1 BehaviorState (org.osate.ba.aadlba.BehaviorState)1 DispatchCondition (org.osate.ba.aadlba.DispatchCondition)1 DispatchTrigger (org.osate.ba.aadlba.DispatchTrigger)1 DispatchTriggerLogicalExpression (org.osate.ba.aadlba.DispatchTriggerLogicalExpression)1