private void sendRejectAnswer(
     Agent ag,
     Desire desire,
     CensorComponent cexec,
     SpeechAct action,
     Secret s,
     String answerValue) {
   Answer answer = null;
   String act = null;
   if (action instanceof Update) {
     Update update = (Update) action;
     answer = new Answer(ag, update.getSenderId(), update.getProposition(), AnswerValue.AV_REJECT);
     act = "update";
   } else if (action instanceof Revision) {
     Revision revision = (Revision) action;
     answer =
         new Answer(ag, revision.getSenderId(), revision.getProposition(), AnswerValue.AV_REJECT);
     act = "revision";
   } else if (action instanceof Query) {
     Query query = (Query) action;
     answer = new Answer(ag, query.getSenderId(), query.getQuestion(), AnswerValue.AV_REJECT);
     act = "query";
   }
   Subgoal answerGoal = new Subgoal(ag, desire);
   answerGoal.newStack(answer);
   ag.getPlanComponent().addPlan(answerGoal);
   cexec.report(
       "The reaction '"
           + answerValue
           + "' would reveal secret "
           + s
           + ". Reject the "
           + act
           + ".");
   cexec.report(
       "Add the new action '" + Answer.class.getSimpleName() + "' to the plan",
       ag.getPlanComponent());
 }
  /**
   * Process an incoming revision request from an attacking agent. Using the censor component, this
   * method first checks if a secret might be revealed by the actual revision handling. Based on
   * this preprocessing, it either generates a Refusal-SpeechAct or runs the actual revision on the
   * belief base and generates a notification action.
   *
   * @param desire
   * @param pp
   * @param ag
   */
  public boolean processRevision(Desire desire, PlanParameter pp, Agent ag) {
    pp.report("Generate new subgoal to process revision request");
    CensorComponent cexec = ag.getComponent(CensorComponent.class);

    Revision revision = (Revision) desire.getPerception();
    View view = (View) ag.getComponent(ViewDataComponent.class).getView(revision.getSenderId());
    SecrecyKnowledge conf = ag.getComponent(SecrecyKnowledge.class);

    pp.report("Invoke censor to check all possible answers for meta inferences");

    // check if revision would reveal a secret
    View refinedView = view.RefineViewByRevision(revision.getProposition(), AnswerValue.AV_TRUE);
    if (cexec.poss(refinedView)) {
      for (Secret s : conf.getSecrets()) {
        if (cexec.scepticalInference(refinedView, s.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, revision, s, "success");
          return true;
        }
      }
    }

    // check if the failure of the revision would reveal a secret
    refinedView = view.RefineViewByRevision(revision.getProposition(), AnswerValue.AV_FALSE);
    if (cexec.poss(refinedView)) {
      for (Secret s : conf.getSecrets()) {
        if (cexec.scepticalInference(refinedView, s.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, revision, s, "failure");
          return true;
        }
      }
    }

    // revision would not breach confidentiality, continue revising beliefbase
    BaseBeliefbase bbase = ag.getBeliefs().getWorldKnowledge();

    // slightly hacked: we need to get the revision result from the revision operator
    OperatorCallWrapper changeOp = bbase.getChangeOperator();
    boolean success = false;
    if (changeOp.getImplementation() instanceof ConditionalRevision) {
      ConditionalRevision revisionOp = (ConditionalRevision) changeOp.getImplementation();
      OperatorCallWrapper translator = bbase.getTranslator();
      Set<FolFormula> revisionFormulas = new HashSet<FolFormula>();
      revisionFormulas.add(revision.getProposition());
      ConditionalBeliefbase newK =
          (ConditionalBeliefbase)
              translator.process(new TranslatorParameter(bbase, revisionFormulas));
      success = revisionOp.simulateRevision((ConditionalBeliefbase) bbase, newK);
    }

    AnswerValue answerValue = AnswerValue.AV_FALSE;
    if (success) {
      pp.report(
          "Revision will be successful. Send answer 'true' and add '"
              + revision.getProposition().toString()
              + "' to belief base");
      answerValue = AnswerValue.AV_TRUE;
    } else {
      pp.report("Revision will be not be successful. Send answer 'false'.");
      answerValue = AnswerValue.AV_FALSE;
    }

    // send answer
    RevisionAnswer answer =
        new RevisionAnswer(ag, revision.getSenderId(), revision.getProposition(), answerValue);
    Subgoal answerGoal = new Subgoal(ag, desire);
    answerGoal.newStack(answer);
    ag.getPlanComponent().addPlan(answerGoal);
    pp.report(
        "Add the new action '" + RevisionAnswer.class.getSimpleName() + "' to the plan",
        ag.getPlanComponent());
    return true;
  }