コード例 #1
0
  public static void main(String[] args) {

    // create subjects with security label and inform
    ref_mgr.createSubj("Lyle", 2);
    ref_mgr.createSubj("Hal", 1);

    // create objects with security label and inform
    ref_mgr.createObj("Lobj", 2);
    ref_mgr.createObj("Hobj", 1);

    // read command line ########################################################

    try {
      File aFile = new File(args[0]);

      Scanner sc = new Scanner(aFile);

      System.out.println("Reading from file: " + args[0] + "\n");

      while (sc.hasNextLine()) {
        // case-insensitive, lower the case!
        String line = sc.nextLine().toLowerCase();

        // check for illegal commands
        if (check_cmd(line)) {

          if (cmd_length == 3) {
            System.out.println(subject_name + " " + main_cmd + " " + object_name);
          } else {
            System.out.println(
                subject_name + " " + main_cmd + " value " + cmd_value + " to " + object_name);
          }

          Scanner scLine = new Scanner(line);

          // parse command
          inst_obj.set_type(scLine.next());
          inst_obj.set_subj(scLine.next());
          inst_obj.set_obj(scLine.next());

          // exeception-prone (takes last cmd if there is one)
          try {
            inst_obj.set_value(scLine.next());
          } catch (NoSuchElementException e) {
            // System.out.println("Error message: " + e.getMessage());
            // e.printStackTrace();
          }
          scLine.close();

          // feed to ReferenceManager
          try {
            ref_mgr.validate(inst_obj);
          } catch (Exception e) {
            System.out.println(e.getMessage());
          }

          // print state
          printState();
        }
      }
      sc.close();
    } catch (IOException e) {
      e.getMessage();
      e.printStackTrace();
    }
    // done with read command line #############################################

    // execute commands

    // print states
  }