/**
   * Converts all model blocks of the given subsystem.
   *
   * @param subSys sub system which model references should be converted
   * @param builder builder to use
   */
  protected void convertDeltaModelBlocks(String subSys, DeltaMontiArcModelBuilder builder) {
    String[] modelReferences = getModelReference(subSys);
    for (String modelRef : modelReferences) {
      DeltaOperation op = getDeltaOperationForElement(modelRef);
      String simpleName = matlab.doGetSimpleNameLimiterBased(modelRef);
      switch (op) {
        case ADD:
          builder.printOperation(op);
          String type = getModelType(modelRef);
          // type = MontiArcStringBuilder.EXPORT_PACKAGE + "." + type.trim();
          builder.createComponentReference(type, simpleName);

          break;
        case REPLACE:
          int withIndex = simpleName.indexOf(DeltaSimulinkKeyWords.REPLACE_WITH);
          if (!simpleName.startsWith(DeltaSimulinkKeyWords.REPLACE) || withIndex == -1) {
            handler.addError("Unable to parse replace statement!", simpleName);
          } else {

            String toReplace =
                simpleName.substring(DeltaSimulinkKeyWords.REPLACE.length(), withIndex);
            String with =
                simpleName.substring(withIndex + DeltaSimulinkKeyWords.REPLACE_WITH.length());
            // with = MontiArcStringBuilder.EXPORT_PACKAGE + "." + with.trim();
            builder.createReplaceStatement(toReplace, with);
          }
          break;
        default:
          break;
      }
    }
  }
  /** @param deltaModelName */
  protected void convertDeltaSubSystems(String deltaModelName, DeltaMontiArcModelBuilder builder) {
    List<String> subSystems = loadSubSystems(deltaModelName);

    for (String subSys : subSystems) {
      DeltaOperation op = getDeltaOperationForElement(subSys);
      String simpleName = matlab.doGetSimpleNameLimiterBased(subSys);

      // modify block
      if (op == DeltaOperation.MODIFY) {
        modifySubSystemBlock(builder, subSys, simpleName);
      }
      // add subsystem block
      else if (op == DeltaOperation.ADD) {
        builder.printOperation(op);
        convertSubSystemsAndRoot(subSys, builder, true);
      }
      // replace subsystem block
      else if (op == DeltaOperation.REPLACE) {
        int withIndex = simpleName.indexOf(DeltaSimulinkKeyWords.REPLACE_WITH);
        if (!simpleName.startsWith(DeltaSimulinkKeyWords.REPLACE) || withIndex == -1) {
          handler.addError("Unable to parse replace statement!", simpleName);
        } else {
          String toReplace =
              simpleName.substring(DeltaSimulinkKeyWords.REPLACE.length(), withIndex);

          String newName = matlab.doGetSimpleNameLimiterBased(subSys);

          newName =
              newName.substring(
                  newName.indexOf(DeltaSimulinkKeyWords.REPLACE_WITH)
                      + DeltaSimulinkKeyWords.REPLACE_WITH.length());
          newName = newName.trim();

          StringBuffer typeName = new StringBuffer();
          String sep = "";
          for (String part : currentComponentName) {
            typeName.append(sep);
            sep = ".";
            typeName.append(part);
          }
          typeName.append(sep);
          typeName.append(newName);

          // remove old component definition
          builder.addSingleLineComment("replace subsystem " + toReplace);

          builder.printOperation(DeltaOperation.ADD);
          convertSubSystemsAndRoot(subSys, builder, false);
          builder.createReplaceStatement(toReplace, typeName.toString() + " " + newName);
        }
      }
    }
  }