/**
   * Test of handleEvent method, of class Conversation. Tests both local and remote side
   *
   * @throws UnknownHostException
   * @throws InterruptedException
   * @throws IOException
   */
  @Test
  public void testHandleEvent() throws UnknownHostException, IOException, InterruptedException {
    // clear the converstion created in setUp()
    EventPool.getAppPool().removeListener(conversation);

    // get the local app-pool and let it start
    EventPool localPool = EventPool.getAppPool();
    Thread.sleep(100);

    // create a remote eventpool and connect it to the local one
    EventPool remotePool = new EventPool();
    Connection remoteConnection = new Connection(InetAddress.getLocalHost(), remotePool, null);
    Thread.sleep(100);

    // create a contact out of the local user (as seen from the other side)
    Account localAccount = ChatApplication.getInstance().getAccount();
    Contact localContact = new Contact(localAccount.getUsername(), InetAddress.getLocalHost());
    Contact remoteContact = new Contact("Jaspervdj", InetAddress.getLocalHost());

    // add both of these contacts to our list, so we can look them up later
    ContactList contactList = localAccount.getContactList();
    contactList.addContact(localContact);
    contactList.addContact(remoteContact);

    // conversation manager will contain the conversation with the remote user, as
    // well as the conversation with the local one
    ConversationManager conversationManager =
        ChatApplication.getInstance().getConversationManager();
    Conversation localConversation = conversationManager.startConversation(remoteContact, false);
    Conversation remoteConversation = conversationManager.startConversation(localContact, false);

    // register the remoteConversation specifically with the remote pool
    remotePool.addListener(remoteConversation, new ConversationEventFilter(remoteConversation));
    // remove remoteListener from localPool
    localPool.removeListener(remoteConversation);

    // now everything is setup, and a user can type a message
    ChatMessage chatMessage =
        new ChatMessage(localContact.getUsername(), "Dag Javache, jij jij remoteUser!");
    ConversationEvent localEvent = new NewChatMessageEvent(localConversation, chatMessage);

    // raise the event on the local pool, should get sent to remotePool too
    localPool.raiseNetworkEvent(localEvent);
    Thread.sleep(100);

    // let's check the results!
    assertEquals(1, remoteConversation.getChatMessages(10).length);
    assertEquals(
        "Dag Javache, jij jij remoteUser!", remoteConversation.getChatMessages(1)[0].getText());

    assertEquals(1, localConversation.getChatMessages(10).length);
    assertEquals(
        "Dag Javache, jij jij remoteUser!", localConversation.getChatMessages(1)[0].getText());
  }
Exemple #2
0
 public void populate(int count) {
   String[] firstNames = {"James", "Mary", "Joe", "Jane", "Andrew"};
   String[] surNames = {"Smith", "Bloggs", "Doe"};
   String[] numbers = {"200564758", "202283940", "206958473"};
   for (int i = 0; i < count; i++) {
     contactList.add(new Contact());
     contactList.edit(0, "firstName", firstNames[(int) (Math.random() * firstNames.length)]);
     contactList.edit(0, "surName", surNames[(int) (Math.random() * surNames.length)]);
     contactList.edit(0, "number", "01" + numbers[(int) (Math.random() * numbers.length)]);
     contactList.edit(0, "number", "07" + numbers[(int) (Math.random() * numbers.length)]);
   }
 }
Exemple #3
0
  public static void main(String[] args) {
    ContactList list = new ContactList("Contacts.txt");
    Scanner input = new Scanner(System.in);
    boolean exit = false;

    System.out.println("Welcome to the Contact Manager!");

    do {
      System.out.println("-------------------");
      System.out.println(
          "Do you want to:\n1) See all contacts\n2)See a specific contact\n3)Enter a new contact\n4+)Quit");
      int userInput = Integer.parseInt(input.nextLine());

      switch (userInput) {
        case 1:
          System.out.println("-------------------");
          System.out.println("All contacts:");
          list.listContactNames();
          break;
        case 2:
          System.out.println("-------------------");
          System.out.println("Enter the name of the contact that you wish to see");
          String userInput2 = input.nextLine();
          System.out.println("-------------------");
          list.getContact(userInput2);
          System.out.println();
          break;
        case 3:
          System.out.println("-------------------");
          System.out.println(
              "Enter the name, then the email, and the number in order to add the contact");
          String name = input.nextLine();
          String email = input.nextLine();
          String number = input.nextLine();
          list.addContact(name, email, number);
          System.out.println("-------------------");
          System.out.println("\n" + name + "'s Contact has been added:\n" + list.getContact(name));
          break;
        default:
          System.out.println("-------------------");
          System.out.println("Goodbye.");
          exit = true;
          break;
      }
    } while (exit == false);
  }
  public void setPosition(int position) {
    mPosition = position;

    if (mAdapter != null) {
      mContact = ContactList.getInstance().get(position);
      mAdapter.setContact(mContact);
      updateUI();
    }
  }
Exemple #5
0
 // Delete a contact given by contactId (between 0 and max contacts). Returns
 // 1 if success otherwish returns 0.
 static int deleteContact(int contactId) {
   // #ifdef api.pim
   if (contactId >= 0 && contactId < s_contacts.length) {
     try {
       ContactList list = (ContactList) s_contacts[contactId].m_contact.getPIMList();
       list.removeContact((s_contacts[contactId].m_contact));
       s_contacts[contactId] = null;
       s_nbContacts--;
       for (int i = contactId; i < s_nbContacts; i++) {
         s_contacts[i] = s_contacts[i + 1];
       }
       return 1;
     } catch (Exception e) {
       Logger.println("Exception while deleting contact: " + e);
     }
   }
   // #endif
   return 0;
 }
 public SIPHeader parse() throws ParseException {
   // past the header name and the colon.
   headerName(TokenTypes.CONTACT);
   ContactList retval = new ContactList();
   while (true) {
     Contact contact = new Contact();
     if (lexer.lookAhead(0) == '*') {
       this.lexer.match('*');
       contact.setWildCardFlag(true);
     } else super.parse(contact);
     retval.add(contact);
     this.lexer.SPorHT();
     if (lexer.lookAhead(0) == ',') {
       this.lexer.match(',');
       this.lexer.SPorHT();
     } else if (lexer.lookAhead(0) == '\n') break;
     else throw createParseException("unexpected char");
   }
   return retval;
 }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // Если не задан параметр action, то возвратить ошибку 400.
    if (request.getParameter("action") == null) {
      response.sendError(400, "Bad Request");
      return;
    }

    // Отправить ответ клиенту в формате JSON
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      ContactList cl = new ContactList();

      if (request.getParameter("action").equals("list")) {
        out.println(cl.list());
      }

      if (request.getParameter("action").equals("add")) {
        Contact c =
            new Contact(
                null,
                request.getParameter("fio"),
                request.getParameter("phone"),
                request.getParameter("email"));
        out.println(cl.add(c));
      }

      if (request.getParameter("action").equals("remove")) {
        out.println(cl.remove(request.getParameter("id")));
      }

      if (request.getParameter("action").equals("createdb")) {
        out.println(cl.createDB());
      }
    } finally {
      out.close();
    }
  }
 public void actionPerformed(ActionEvent e) {
   if (to == e.getSource()) {
     toSendWindow();
     // Display list for user selection
     // puts user selection into JTextField to
   } else if (addContacts == e.getSource()) {
     addContactWindow();
     // Display prompt for information for new contact
     // Uses information to add to ContactList collection
     //
   } else if (removeContacts == e.getSource()) {
     removeContactWindow();
     // Display prompt for removing contacts
     // Uses information to remove from ContactList collection
   } else if (editContacts == e.getSource()) {
     editContactWindow();
     // UI for editing contacts
   } else if (save == e.getSource()) {
     cList.addContact(
         new Contact(
             newContactFields[0].getText(),
             newContactFields[1].getText(),
             newContactFields[2].getText()));
     JOptionPane.showMessageDialog(
         null, "The contact has been added.", "Success!", JOptionPane.INFORMATION_MESSAGE);
     addWindow.dispose();
   } else if (deleteContact == e.getSource()) {
     ContactList cDeleted = contactList.getContacts();
     for (int i = 0; i < cDeleted.getLength(); i++) {
       cList.removeContact(cDeleted.getContact(i));
       /*
       PLACEHOLDER FOR REPAINT
       */
     }
     removeWindow.dispose();
   } else if (addSendContacts == e.getSource()) {
     toText.setText(toText.getText() + contactList.getEmails());
     toWindow.dispose();
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact_list);

    Contact temp = new Contact();
    PhoneContact = ContactList.getsInstance();

    ContentResolver cont = getContentResolver();
    Cursor c = cont.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

    ArrayList<String> contacts = new ArrayList<>(); // Storing ContactNumber
    ArrayList<String> name = new ArrayList<>(); // Storing ContactName

    if (c.moveToFirst()) {

      do {
        String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
        if (Integer.parseInt(
                c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))
            > 0) {
          Cursor num =
              cont.query(
                  ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                  null,
                  ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                  new String[] {contactId},
                  null);
          while (num.moveToNext()) {
            String contactNum =
                num.getString(num.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            contacts.add(contactNum);
            String contactName =
                num.getString(
                    num.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            name.add(contactName);
          }
          num.close();
        }
      } while (c.moveToNext());
    }

    for (int i = 0; i < contacts.size(); i++) {
      Log.d(tag, contacts.get(i));
      Log.d(tag, name.get(i));
      temp.setCNum(contacts.get(i));
      temp.setCName(name.get(i));
      PhoneContact.add(temp);
    }

    ListView listView = (ListView) findViewById(R.id.Contact_list_view);
    mAdapter = new ContactAdapter(PhoneContact);
    listView.setAdapter(mAdapter);
    listView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          int previousFirstItem = 0;

          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {}

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem > previousFirstItem) {
              getSupportActionBar().hide();
            } else if (firstVisibleItem < previousFirstItem) {
              getSupportActionBar().show();
            }

            previousFirstItem = firstVisibleItem;
          }
        });

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(ContactListActivity.this, ContactViewActivity.class);
            i.putExtra(ContactViewActivity.EXTRA, position);
            startActivity(i);
          }
        });

    c.close();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_contact_view, container, false);

    // Use this to indicate the ratio
    /*Display display = getWindowManager().getDefaultDisplay();
    Point point = new Point();
    display.getSize(point);
    int width = point.x;
    int height = point.y;

    // This indicate ratio based on Material design
    RelativeLayout headerSection = (RelativeLayout) v.findViewById(R.id.contact_view_header);

    // We are using LinearLayout is because in activity_contact_view the root layout is LinearLayout
    // and this layout contains contact_view_header
    headerSection.setLayoutParams(new LinearLayout.LayoutParams(width, (int) (width * (9.0 / 16.0))));*/

    mContact = ContactList.getInstance().get(mPosition);

    mContactName = (TextView) v.findViewById(R.id.contact_name);

    Toolbar toolbar = (Toolbar) v.findViewById(R.id.contact_view_toolbar);
    //  setSupportActionBar(toolbar);

    // To catch the click on the menu item edit (icon)
    toolbar.setOnMenuItemClickListener(
        new Toolbar.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.contact_view_edit) {
              getContrat().selectedEditPosition(mPosition);
              // Before we use Intent here so fragment was couple with activity
              /* Intent intent = new Intent(getActivity(), ContactEditActivity.class);
              intent.putExtra(ContactEditActivity.EXTRA, mPosition);
              startActivity(intent);*/
              Log.d(TAG, "Edit is clicked");
            }

            return false;
          }
        });

    toolbar.inflateMenu(R.menu.menu_contact_view);

    ListView listView = (ListView) v.findViewById(R.id.contact_view_fields);
    mAdapter = new FieldsAdapter(mContact);
    listView.setAdapter(mAdapter);

    // To use this palette we have to add an external library
    // compile "com.android.support:palette-v7:21.0.+"  in build.gradle (Module:app)

    // Palette takes an image, analyzes it and finds the prominent colors.
    // To do this we need a bitmap which is an object that holds image data.
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.parrots);
    Palette palette = Palette.generate(bitmap);

    // With our Palette now created, we can get a color from it and use that to change the color of
    // our icons.
    mColor = palette.getDarkVibrantSwatch().getRgb();

    updateUI();
    return v;
  }
Exemple #11
0
 public void printContactList(ContactList list) {
   for (Contact c : list.getList()) {
     printContact(c);
   }
 }
  /** Called by the sax parser when the start of an element is encountered. */
  public void startElement(String nameSpaceURI, String local, String name, Attributes attrs)
      throws SAXException {
    try {
      Debug.println("processing " + name);
      if (name.compareTo(TagNames.CALLFLOW) == 0) {
        callFlow = new CallFlow();
        callFlow.instantiateOn = attrs.getValue(Attr.instantiateOn);
        callFlow.description = attrs.getValue(Attr.description);

      } else if (name.compareTo(TagNames.AGENT) == 0) {
        Agent agent = new Agent();
        agent.agentId = attrs.getValue(Attr.agentId);
        agent.userName = attrs.getValue(Attr.userName);
        agent.requestURI = attrs.getValue(Attr.requestURI);
        agent.host = attrs.getValue(Attr.host);
        agent.contactPort = attrs.getValue(Attr.contactPort);
        agent.contactHost = attrs.getValue(Attr.contactHost);
        addAgent(agent);
      } else if (name.compareTo(TagNames.EXPECT) == 0) {
        // Make sure there are no unexpected attributes.
        for (int i = 0; i < attrs.getLength(); i++) {
          String attrname = attrs.getLocalName(i);
          if (attrname.equals(Attr.enablingEvent)
              || attrname.equals(Attr.triggerMessage)
              || attrname.equals(Attr.generatedEvent)
              || attrname.equals(Attr.nodeId)
              || attrname.equals(Attr.onTrigger)
              || attrname.equals(Attr.onCompletion)) continue;
          else
            throw new SAXException(
                "Unkown attribute in expect: nodeId = "
                    + attrs.getValue(Attr.nodeId)
                    + " attribute name =  "
                    + attrname);
        }
        String enablingEvent = attrs.getValue(Attr.enablingEvent);
        String triggerMessage = attrs.getValue(Attr.triggerMessage);
        String generatedEvent = attrs.getValue(Attr.generatedEvent);
        String nodeId = attrs.getValue(Attr.nodeId);
        currentExpectNode = new Expect(callFlow, enablingEvent, generatedEvent, triggerMessage);
        String onTrigger = attrs.getValue(Attr.onTrigger);
        String onCompletion = attrs.getValue(Attr.onCompletion);
        currentExpectNode.onTrigger = onTrigger;
        currentExpectNode.onCompletion = onCompletion;
        currentExpectNode.nodeId = nodeId;
      } else if (name.compareTo(TagNames.SIP_REQUEST) == 0) {
        if (this.messageTemplateContext) {
          // This is a SIPRequest template node.
          for (int i = 0; i < attrs.getLength(); i++) {
            String attrname = attrs.getLocalName(i);
            if (!attrs.getLocalName(i).equals(Attr.templateId))
              throw new SAXException(
                  "Unkown attribute in SIP_REQUEST node " + " attribute name =  " + attrname);
          }
          messageTemplate = new SIPRequest();
          id = attrs.getValue(Attr.templateId);
          jythonCode = null;
        }
      } else if (name.compareTo(TagNames.SIP_RESPONSE) == 0) {
        if (this.messageTemplateContext) {
          messageTemplate = new SIPResponse();
          jythonCode = null;
          for (int i = 0; i < attrs.getLength(); i++) {
            String attrname = attrs.getLocalName(i);
            if (!attrs.getLocalName(i).equals(Attr.templateId))
              throw new SAXException(
                  "Unkown attribute in SIP_REQUEST node " + " attribute name =  " + attrname);
          }
          id = attrs.getValue(Attr.templateId);
        }
      } else if (name.compareTo(TagNames.STATUS_LINE) == 0) {
        String scode = attrs.getValue(Attr.statusCode);
        if (messageTemplateContext) {
          StatusLine statusLine = new StatusLine();
          try {
            int statusCode = Integer.parseInt(scode);
            statusLine.setStatusCode(statusCode);
          } catch (NumberFormatException ex) {
            throw new SAXException(ex.getMessage());
          }
          SIPResponse response = (SIPResponse) this.messageTemplate;
          response.setStatusLine(statusLine);
        } else {
          int statusCode = Integer.parseInt(scode);
          generatedMessage.addStatusLine(statusCode);
        }
      } else if (name.compareTo(TagNames.REQUEST_LINE) == 0) {
        String method = attrs.getValue(Attr.method);
        Debug.println("tagname = " + TagNames.REQUEST_LINE);
        Debug.println("messageTemplateContext = " + messageTemplateContext);
        if (messageTemplateContext) {
          for (int i = 0; i < attrs.getLength(); i++) {
            String attrname = attrs.getLocalName(i);
            if (attrs.getLocalName(i).equals(Attr.requestURI)
                || attrs.getLocalName(i).equals(Attr.method)) continue;
            else
              throw new SAXException(
                  "Unkown attribute in REQUEST_LINE node " + " attribute name =  " + attrname);
          }
          requestLine = new RequestLine();
          requestLine.setMethod(method);
          String requestURI = attrs.getValue(Attr.requestURI);
          StringMsgParser smp = new StringMsgParser();
          if (requestURI != null) {
            try {
              URI uri = smp.parseSIPUrl(requestURI);
              requestLine.setUri(uri);
            } catch (SIPParseException e) {
              throw new SAXException("Bad URL " + requestURI);
            }
          }
          SIPRequest request = (SIPRequest) messageTemplate;
          request.setRequestLine(requestLine);
        } else {
          for (int i = 0; i < attrs.getLength(); i++) {
            String attrname = attrs.getLocalName(i);
            if (attrs.getLocalName(i).equals(Attr.method)
                || attrs.getLocalName(i).equals(Attr.templateId)
                || attrs.getLocalName(i).equals(Attr.agentId)) continue;
            else
              throw new SAXException(
                  "Unkown attribute in REQUEST_LINE node " + " attribute name =  " + attrname);
          }
          String requestURI = attrs.getValue(Attr.requestURI);
          if (requestURI == null) {
            String agentId = attrs.getValue(Attr.agentId);
            if (agentId != null) {
              Agent agent = getAgent(agentId);
              if (agent == null) throw new SAXException("Missing requestURI or agent attribute");
              requestURI = agent.requestURI;
            }
          }
          generatedMessage.addRequestLine(method, requestURI);
        }
      } else if (name.compareTo(TagNames.FROM) == 0) {
        for (int i = 0; i < attrs.getLength(); i++) {
          String attrname = attrs.getLocalName(i);
          if (attrs.getLocalName(i).equals(Attr.displayName)
              || attrs.getLocalName(i).equals(Attr.userName)
              || attrs.getLocalName(i).equals(Attr.host)
              || attrs.getLocalName(i).equals(Attr.agentId)) continue;
          else
            throw new SAXException(
                "Unkown attribute in FROM node " + " attribute name =  " + attrname);
        }
        String displayName = attrs.getValue(Attr.displayName);
        String userName = attrs.getValue(Attr.userName);
        String hostName = attrs.getValue(Attr.host);
        String agentId = attrs.getValue(Attr.agentId);
        if (agentId != null) {
          Agent agent = getAgent(agentId);
          if (agent == null) throw new SAXException("agent not found " + agentId);
          if (displayName == null) displayName = agent.displayName;
          if (userName == null) userName = agent.userName;
          if (hostName == null) hostName = agent.host;
        }

        if (this.messageTemplateContext) {
          From from = new From();
          Address address = new Address();
          address.setDisplayName(displayName);
          URI uri = new URI();
          Host host = new Host();
          host.setHostname(hostName);
          uri.setHost(host);
          uri.setUser(userName);
          address.setAddrSpec(uri);
          from.setAddress(address);
          try {
            messageTemplate.attachHeader(from, false);
          } catch (SIPDuplicateHeaderException ex) {
            throw new SAXException(ex.getMessage());
          }
        } else {
          generatedMessage.addFromHeader(displayName, userName, hostName);
        }

      } else if (name.compareTo(TagNames.TO) == 0) {
        for (int i = 0; i < attrs.getLength(); i++) {
          String attrname = attrs.getLocalName(i);
          if (attrs.getLocalName(i).equals(Attr.templateId)
              || attrs.getLocalName(i).equals(Attr.host)
              || attrs.getLocalName(i).equals(Attr.agentId)
              || attrs.getLocalName(i).equals(Attr.userName)) continue;
          else
            throw new SAXException(
                "Unkown attribute in FROM node " + " attribute name =  " + attrname);
        }
        String displayName = attrs.getValue(Attr.displayName);
        String userName = attrs.getValue(Attr.userName);
        String hostName = attrs.getValue(Attr.host);
        String agentId = attrs.getValue(Attr.agentId);
        if (agentId != null) {
          Agent agent = getAgent(agentId);
          if (agent == null) throw new SAXException("agent not found " + agentId);
          if (displayName == null) displayName = agent.displayName;
          if (userName == null) userName = agent.userName;
          if (hostName == null) hostName = agent.host;
        }
        if (this.messageTemplateContext) {
          To to = new To();
          Address address = new Address();
          address.setDisplayName(displayName);
          URI uri = new URI();
          Host host = new Host();
          host.setHostname(hostName);
          uri.setHost(host);
          uri.setUser(userName);
          address.setAddrSpec(uri);
          to.setAddress(address);
          try {
            messageTemplate.attachHeader(to, false);
          } catch (SIPDuplicateHeaderException ex) {
            throw new SAXException(ex.getMessage());
          }
        } else {
          generatedMessage.addToHeader(displayName, userName, hostName);
        }
      } else if (name.compareTo(TagNames.CALLID) == 0) {
        String lid = attrs.getValue(Attr.localId);
        String host = attrs.getValue(Attr.host);
        if (this.messageTemplateContext) {
          CallID cid = new CallID();
          CallIdentifier cidf = new CallIdentifier(lid, host);
          cid.setCallIdentifier(cidf);
        } else {
          generatedMessage.addCallIdHeader();
        }
      } else if (name.compareTo(TagNames.CONTACT) == 0) {
        for (int i = 0; i < attrs.getLength(); i++) {
          String attrname = attrs.getLocalName(i);
          if (attrs.getLocalName(i).equals(Attr.displayName)
              || attrs.getLocalName(i).equals(Attr.userName)
              || attrs.getLocalName(i).equals(Attr.action)
              || attrs.getLocalName(i).equals(Attr.contactHost)
              || attrs.getLocalName(i).equals(Attr.contactPort)
              || attrs.getLocalName(i).equals(Attr.agentId)
              || attrs.getLocalName(i).equals(Attr.expires)) continue;
          else
            throw new SAXException(
                "Unkown attribute in CONTACT node " + " attribute name =  " + attrname);
        }
        String displayName = attrs.getValue(Attr.displayName);
        String userName = attrs.getValue(Attr.userName);
        String hostName = attrs.getValue(Attr.contactHost);
        String portString = attrs.getValue(Attr.contactPort);
        String expiryTimeString = attrs.getValue(Attr.expires);
        String action = attrs.getValue(Attr.action);
        String agentId = attrs.getValue(Attr.agentId);
        if (action == null) action = "proxy";
        if (agentId != null) {
          Agent agent = getAgent(agentId);
          if (displayName == null) displayName = agent.displayName;
          if (userName == null) userName = agent.userName;
          if (hostName == null) hostName = agent.contactHost;
          if (portString == null) portString = agent.contactPort;
        }

        if (this.messageTemplateContext) {
          // Generating a message template for the expires header.
          ContactList clist = new ContactList();
          Contact contact = new Contact();
          clist.add(contact);
          URI uri = new URI();
          Host host = new Host();
          host.setHostname(hostName);
          uri.setHost(host);
          uri.setUser(userName);

          if (portString != null) {
            int port = new Integer(portString).intValue();
            uri.setPort(port);
          }
          Address address = new Address();
          address.setAddrSpec(uri);
          contact.setAddress(address);
          if (expiryTimeString != null) {
            long expiryTimeSec = new Long(expiryTimeString).longValue();
            contact.setExpires(expiryTimeSec);
          }
          messageTemplate.attachHeader(clist, false);

        } else {
          int port = 5060;
          if (portString != null) port = new Integer(portString).intValue();
          long expiryTimeSec = 3600;
          if (expiryTimeString != null) {
            expiryTimeSec = new Long(expiryTimeString).longValue();
          }
          if (userName == null) throw new Exception("Missing attribute userName");
          if (action == null) action = Attr.proxy;
          String uri;
          if (hostName == null) {
            uri =
                SIPKeywords.SIP
                    + Separators.COLON
                    + userName
                    + Separators.AT
                    + EventEngine.theStack.getHostAddress()
                    + Separators.COLON
                    + EventEngine.theStack.getDefaultPort()
                    + Separators.SEMICOLON
                    + SIPKeywords.TRANSPORT
                    + Separators.EQUALS
                    + EventEngine.theStack.getDefaultTransport();
          } else
            uri =
                SIPKeywords.SIP
                    + Separators.COLON
                    + userName
                    + Separators.AT
                    + hostName
                    + ":"
                    + port;
          generatedMessage.addContactHeader(displayName, uri, expiryTimeSec, action);
        }

      } else if (name.compareTo(TagNames.GENERATE) == 0) {
        generateContext = true;

        if (currentExpectNode == null) {
          throw new SAXException("Bad element nesting.");
        }
        String id = attrs.getValue(Attr.messageId);
        String retransmit = attrs.getValue(Attr.retransmit);
        String delayString = attrs.getValue(Attr.delay);
        int delay = 0;
        if (delayString != null) {
          try {
            delay = Integer.parseInt(delayString);
          } catch (NumberFormatException ex) {
            throw new SAXException("Bad integer value " + delayString);
          }
        }

        generatedMessage = new GeneratedMessage(id, callFlow, currentExpectNode, retransmit);
        generatedMessage.delay = delay;
        currentExpectNode.addGeneratedMessage(generatedMessage);
      } else if (name.compareTo(TagNames.MESSAGE_TEMPLATES) == 0) {
        messageTemplateContext = true;
      } else if (name.compareTo(TagNames.JYTHON_CODE) == 0) {
        this.jythonCode = null;
      } else if (name.compareTo(TagNames.STATE_MACHINE) == 0) {
      } else if (name.compareTo(TagNames.AGENTS) == 0) {
      } else {
        throw new SAXException("Unkown tag " + name);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      ex.fillInStackTrace();
      throw new SAXException(ex.getMessage());
    }
  }