Examples: IsEnabled property

  1. This agent prints the status for each agent in the current database: enabled or disabled.
    import lotus.domino.*;
    import java.util.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Vector agents = db.getAgents();
          System.out.println("Agents in database:");
          Enumeration e = db.getAgents().elements();
          while (e.hasMoreElements()) {
            Agent agent = (Agent)e.nextElement();
            String an = agent.getName();
            if (agent.isEnabled())
              System.out.println(an + " is enabled");
            else
              System.out.println(an + " is disabled");
            }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent enables the agent named "Agent To Enable" if it exists in the current database.
    import lotus.domino.*;
    import java.util.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Vector agents = db.getAgents();
          Enumeration e = db.getAgents().elements();
          String msg = "Agent not found";
          while (e.hasMoreElements()) {
            Agent agent = (Agent)e.nextElement();
            String name = agent.getName();
            if (name.compareTo("Agent To Enable") == 0){
              agent.setEnabled(true);
              agent.save();
              msg = "Agent found and enabled";
              break;
              }
            }
          System.out.println(msg);
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }