Package easysm.executors

Source Code of easysm.executors.Invalidator

package easysm.executors;

import easysm.datatypes.Name;
import easysm.stores.*;
import easysm.stores.Class;

/**
* @author Alessio Parma
*/
public class Invalidator
{
  private Main main;

  public Invalidator(Main main)
  {
    this.main = main;
  }
 
  /*
   *
   * Input class diagram
   *
   */
 
  /**
   * Input class diagram dependents:
   * - NONE
   */
  public void invalidateInputCDAndDependents()
  {
    // Input class diagram
    main.inputCD().invalidate();
  }
 
  /**
   * Elements also validated:
   * - All classes
   * - All enumerations
   */
  public void validateInputCD()
  {
    // Input class diagram
    main.inputCD().validate();
    // All classes
    for (Class cl : main.inputCD().classes()) {
      validate(cl);
    }
    // All enumerations
    for (Enumeration en : main.inputCD().enums()) {
      validate(en);
    }
  }
 
  /*
   *
   * State observers part
   *
   */
 
  /**
   * State observers dependents:
   * - The state table
   * - The output class diagram
   */
  public void invalidateSOAndDependents()
  {
    // State observers
    main.stateObservers().invalidate();
    // State table
    main.stateTable().invalidate();
    invalidateDependentsOfST();
    // Output class diagram
    invalidateOutputCDAndDependents();
  }
 
  /**
   * Elements also validated:
   * - All state observers
   */
  public void validateSO()
  {
    // State observers part
    main.stateObservers().validate();
    // All state observers
    for (StateObserver so : main.stateObservers().soList()) {
      validate(so);
    }
  }
 
  /*
   *
   * Events part
   *
   */
 
  /**
   * Events dependents:
   * - State machine
   * - Output class diagram
   */
  public void invalidateEventsAndDependents()
  {
    // Events
    main.events().invalidate();
    // State machine
    invalidateSMAndDependents();
    // Output class diagram
    invalidateOutputCDAndDependents();
  }
 
  /**
   * Elements also validated:
   * - All events
   */
  public void validateEvents()
  {
    // Events part
    main.events().validate();
    // All events
    for (Event event : main.events().eventList()) {
      validate(event);
    }
  }
 
  /*
   *
   * State table
   *
   */
 
  /**
   * State table dependents:
   * - The state machine
   */
  public void invalidateDependentsOfST()
  {
    // State machine
    invalidateSMAndDependents();
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validateST()
  {
    // State table
    main.stateTable().validate();
  }
 
  /*
   *
   * State machine
   *
   */
 
  /**
   * State machine dependents:
   * - NONE
   */
  public void invalidateSMAndDependents()
  {
    // State machine
    if (main.stateMachine() != null) {
      main.stateMachine().invalidate();
    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validateSM()
  {
    // State machine
    if (main.stateMachine() != null) {
      main.stateMachine().validate();
    }
  }
 
  /*
   *
   * Output class diagram
   *
   */
 
  /**
   * Output class diagram dependents:
   * - NONE
   */
  public void invalidateOutputCDAndDependents()
  {
    // Output class diagram
    if (main.outputCD() != null) {
      main.outputCD().invalidate();
    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validateOutputCD()
  {
    // Output class diagram
    if (main.outputCD() != null) {
      main.outputCD().validate();
    }
  }

  /*
   *
   * Class
   *
   */
 
  /**
   * Class dependents:
   * - Input class diagram
   * - The corresponding type
   */
  public void invalidateDependentsOf(Class cl)
  {
    // Input class diagram
    invalidateInputCDAndDependents();
    // The corresponding type
    Type type = getTypeByName(cl.name());
    type.invalidate();
    invalidateDependentsOf(type);
  }
 
  /**
   * Elements also validated:
   * - All class attributes
   * - All class operations
   * - The corresponding type
   */
  public void validate(Class cl)
  {
    // Class
    cl.validate();
    // All class attributes
    for (Attribute attr : cl.attributes()) {
      validate(attr);
    }
    // All class operations
    for (Operation op : cl.operations()) {
      validate(op);
    }
    // The corresponding type
    validate(getTypeByName(cl.name()));
  }
 
  /*
   *
   * Enumeration
   *
   */
 
  /**
   * Enumeration dependents:
   * - Input class diagram
   * - The corresponding type
   */
  public void invalidateDependentsOf(Enumeration en)
  {
    // Input class diagram
    invalidateInputCDAndDependents();
    // The corresponding type
    Type type = getTypeByName(en.name());
    type.invalidate();
    invalidateDependentsOf(type);
  }
 
  /**
   * Elements also validated:
   * - The corresponding type
   */
  public void validate(Enumeration en)
  {
    // The corresponding type
    validate(getTypeByName(en.name()));
  }
 
  /*
   *
   * Type
   *
   */
 
  /**
   * Type dependents:
   * - All attributes with that type
   * - All operations with that return type and whose parameters have that type
   * - All state observers with that type
   * - All events whose parameters have that type
   */
  public void invalidateDependentsOf(Type type)
  {
    for (Class cl : main.inputCD().classes()) {
      // All attributes with that type
      for (Attribute attr : cl.attributes()) {
        if (attr.type().equals(type)) {
          attr.invalidate();
          invalidateDependentsOf(attr);
        }
      }
      // All operations with that return type and their parameters with that type
      for (Operation op : cl.operations()) {
        Type opReturnType = op.returnType();
        if (opReturnType != null && opReturnType.equals(type)) {
          op.invalidate();
          invalidateDependentsOf(op);
          break;
        }
        for (Parameter param : op.parameters()) {
          if (param.type().equals(type)) {
            op.invalidate();
            invalidateDependentsOf(op);
            break;
          }
        }
      }
    }
    // All state observers with that type
    for (StateObserver so : main.stateObservers().soList()) {
      if (so.type().equals(type)) {
        so.invalidate();
        invalidateDependentsOf(so);
      }
    }
    // All events whose parameters have that type
    for (Event event : main.events().eventList()) {
      for (Parameter param : event.parameters()) {
        if (param.type().equals(type)) {
          event.invalidate();
          invalidateDependentsOf(event);
          break;
        }
      }
    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validate(Type type)
  {
    // Type
    type.validate();
  }
 
  /*
   *
   * Attribute
   *
   */

  /**
   * Attribute dependents:
   * - Container class
   * - Invariants referencing it
   * - Conditions and reactions referencing it
   */
  public void invalidateDependentsOf(Attribute attr)
  {
    // Container class
    Class container = (Class) attr.containedIn();
    container.invalidate();
    invalidateDependentsOf(container);
   
//    // Invariants
//    for (StateObserver so : main().stateObservers().stateObserverSet()) {
//      if (so.invariant().contains(attr)) {
//        so.invalidate();
//        invalidateDependentsOf(so);
//      }
//    }
//    // Conditions and reactions
//    for (Event ev : main().events().eventSet()) {
//      for (CondReact cr : ev.conditionsReactions()) {
//        if (cr.cond().contains(attr) || cr.react().contains(attr)) {
//          cr.invalidate();
//          invalidateDependentsOf(cr);
//        }
//      }
//    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validate(Attribute attr)
  {
    // Attribute
    attr.validate();
  }
 
  /*
   *
   * Operation
   *
   */
 
  /**
   * Elements that depend on an operation:
   * - Container class
   * - Invariants referencing it
   * - Conditions and reactions referencing it
   */
  public void invalidateDependentsOf(Operation op)
  {
    // Container class
    Class container = (Class) op.containedIn();
    container.invalidate();
    invalidateDependentsOf(container);
   
//    // Invariants
//    for (StateObserver currSo : main().stateObservers().stateObserverSet()) {
//      if (currSo.invariant().contains(op)) {
//        currSo.invalidate();
//      }
//    }
//    // Conditions and reactions
//    for (Event ev : main().events().eventSet()) {
//      for (CondReact cr : ev.conditionsReactions()) {
//        if (cr.cond().contains(op) || cr.react().contains(op)) {
//          cr.invalidate();
//        }
//      }
//    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validate(Operation op)
  {
    // Operation
    op.validate();
  }
 
  /*
   *
   * State observer
   *
   */

  /**
   * State observer dependents:
   * - The state observers part
   * - Invariants referencing it
   * - Conditions and reactions referencing it
   */
  public void invalidateDependentsOf(StateObserver so)
  {
    // The state observers part
    invalidateSOAndDependents();
   
//    // Invariants
//    for (StateObserver currSo : main().stateObservers().stateObserverSet()) {
//      if (currSo.invariant().contains(so)) {
//        currSo.invalidate();
//      }
//    }
//    // Conditions and reactions
//    for (Event ev : main().events().eventSet()) {
//      for (CondReact cr : ev.conditionsReactions()) {
//        if (cr.cond().contains(so) || cr.react().contains(so)) {
//          cr.invalidate();
//        }
//      }
//    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validate(StateObserver so)
  {
    // State observer
    so.validate();
  }
 
  /*
   *
   * Event
   *
   */

  /**
   * Elements that depend on an event: 
   * - The events part
   */
  public void invalidateDependentsOf(Event event)
  {
    // The events part
    invalidateEventsAndDependents();
  }
 
  /**
   * Elements also validated:
   * - All its conditions reactions
   */
  public void validate(Event event)
  {
    // Event
    event.validate();
    // All its conditions reactions
    for (CondReact cr : event.condsReacts()) {
      validate(cr);
    }
  }
 
  /*
   *
   * Condition reaction
   *
   */
 
  /**
   * Elements that depend on a condition reaction:
   * - The event it belongs to
   */
  public void invalidateDependentsOf(CondReact cr)
  {
    // The event it belongs to
    for (Event event : main.events().eventList()) {
      if (event.condsReacts().contains(cr)) {
        event.invalidate();
        invalidateDependentsOf(event);
        break;
      }
    }
  }
 
  /**
   * Elements also validated:
   * - NONE
   */
  public void validate(CondReact cr)
  {
    // Condition reaction
    cr.validate();
  }
 
  /*
   *
   * Private methods
   *
   */
 
  private Type getTypeByName(Name typeName)
  {
    for (Type type : main.inputCD().types()) {
      if (type.name().equals(typeName)) {
        return type;
      }
    }
    return null;
  }
}
TOP

Related Classes of easysm.executors.Invalidator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.