Exemplo n.º 1
0
  public void onStart() {
    if (ignoredConversations == null) {
      ignoredConversations = new ConversationList(myAgent);
    }

    // Unless a template is explicitly set, we get messages matching the ontology, the served
    // performatives.
    if (template == null) {
      if (servedPerformatives != null) {
        template =
            MessageTemplate.and(
                MessageTemplate.MatchOntology(onto.getName()),
                new MessageTemplate(
                    new MatchExpression() {
                      public boolean match(ACLMessage msg) {
                        int perf = msg.getPerformative();
                        for (int p : servedPerformatives) {
                          if (p == perf) {
                            return true;
                          }
                        }
                        return false;
                      }
                    }));
      } else {
        // No performative specified --> Match all
        template = MessageTemplate.MatchOntology(onto.getName());
      }
    }
    // Whatever template is used we avoid intercepting messages belonging to external conversations
    template = MessageTemplate.and(template, ignoredConversations.getMessageTemplate());

    // Register Ontology and Language
    ContentManager cm = myAgent.getContentManager();
    if (cm.lookupOntology(onto.getName()) == null) {
      cm.registerOntology(onto);
    }
    this.codec = (codec != null ? codec : new SLCodec());
    if (cm.lookupLanguage(codec.getName()) == null) {
      cm.registerLanguage(codec);
    }
  }
Exemplo n.º 2
0
  protected void setup() {
    // Register language and ontology
    ContentManager cm = getContentManager();
    cm.registerLanguage(codec);
    cm.registerOntology(onto);
    cm.setValidationMode(false);

    // Add initial behaviours
    addBehaviour(new ParticipantsManager(this));
    addBehaviour(new ChatListener(this));

    // Initialize the message used to convey spoken sentences
    spokenMsg = new ACLMessage(ACLMessage.INFORM);
    spokenMsg.setConversationId(CHAT_ID);

    // Activate the GUI
    // #MIDP_EXCLUDE_BEGIN
    myGui = new AWTChatGui(this);
    // #MIDP_EXCLUDE_END
    /*#MIDP_INCLUDE_BEGIN
    myGui = new MIDPChatGui(this);
    #MIDP_INCLUDE_END*/
  }