Ejemplo n.º 1
0
  public ControlLimit(Element gElement) throws TspRuntimeException {

    value = new Double(0);

    if (blocks == null) blocks = new BlockAccessor();

    monitor = gElement.getChildText("Monitor");
    id = gElement.getChildText("Name");
    enableFlag = gElement.getChildText("EnableFlag");

    String alarmTypeStr = gElement.getChildText("AlarmType");
    String sRate = gElement.getChildText("SampleRate");

    if (alarmTypeStr == null
        || id == null
        || monitor == null
        || sRate == null
        || enableFlag == null) {
      StringBuffer msg = new StringBuffer();
      msg.append("While processing Control Limit[monitor=" + monitor + "][id=" + id + "]");
      msg.append("\nencountered invalid XML exception.  Missing required elements:\n");

      if (alarmTypeStr == null) msg.append("Missing AlarmType\n");
      if (id == null) msg.append("Missing Name\n");
      if (monitor == null) msg.append("Missing Monitor\n");
      if (sRate == null) msg.append("Missing SampleRate\n");
      if (enableFlag == null) msg.append("Missing EnableFlag\n");

      throw new InputFileException(msg);
    }

    // Set the enable flag
    TSPProperties props = TSPProperties.instance();
    if (props.containsKey(enableFlag)) {
      String key = (String) props.get(enableFlag);
      if (key.equalsIgnoreCase("true")) {
        enabled = true;
      } else {
        CoreTsp.out("SPCControlLimit: " + monitor + " disabled by input XML.");
        enabled = false;
        return;
      }
    }

    for (int i = 0; i < ALARMTYPES.length; i++)
      if (alarmTypeStr.equals(ALARMTYPES[i])) alarmType = i;

    if (alarmType == NOTYPE) {
      StringBuffer msg = new StringBuffer();
      msg.append("While processing Control Limit[monitor=" + monitor + "][id=" + id + "]\n");
      msg.append(
          "Encountered invalid XML exception.  AlarmType[" + alarmTypeStr + "] is invalid.\n");
      msg.append("Valid Types:\n");
      for (int i = 0; i < ALARMTYPES.length; i++) msg.append(" " + ALARMTYPES[i]);
      throw new InputFileException(msg);
    }

    sampleRate = Integer.parseInt(sRate);

    targetData = gElement.getChildText("TargetVariable");

    if (targetData != null) {
      if (equationVars == null) {
        HandlerManager hm = HandlerManager.instance();

        TspHandler handler = hm.getHandler();
        int siteCount = handler.getSiteCount();

        equationVars = new HashMap[siteCount];
      }
      for (int i = 0; i < equationVars.length; i++) {
        if (equationVars[i] == null) equationVars[i] = new HashMap();
        equationVars[i].put(targetData, new Double(-1.0));
      }
    }

    loadArguments(gElement);

    inControl = true;

    if (activeLimits == null) activeLimits = new HashMap();

    CoreTsp.out(
        "Activating SPC Control Limit: \n"
            + " Name="
            + id
            + "\n"
            + " MonitorType="
            + monitor
            + "\n"
            + " AlarmType="
            + alarmTypeStr
            + "\n"
            + " SampleRate="
            + sampleRate
            + "\n"
            + " TargetVariable="
            + targetData
            + "\n");

    activeLimits.put(monitor + ":" + id, this);
  }