예제 #1
0
  public ArrayList<Contact> getAllContacts() {

    ArrayList<Contact> contactList = new ArrayList<Contact>();

    String selectQuery = "SELECT  * FROM " + TABLE_DETAILS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) { // if (cursor != null)
      do {
        Contact contact = new Contact();
        contact.setName(cursor.getString(1));
        contact.setAddress(cursor.getString(4));
        contact.setPhone(cursor.getString(5));

        String interest = getInterest(cursor.getInt(0));
        contact.setInterest(interest);

        contactList.add(contact);

      } while (cursor.moveToNext());
    }
    return contactList;
  }
예제 #2
0
  public static void main(String[] args) {
    FileHandler fh = new FileHandler();
    Contact c = new Contact();
    List<Contact> contactList = new ArrayList<Contact>();

    String[] fields = fh.readFile(new File("/names.txt"));
    for (int i = 0; i < fields.length; i++) {
      if (!(fields[i].equals("-----"))) {
        c.setFirstName(fields[i++]);
        c.setLastName(fields[i++]);
        c.setAddress(fields[i++]);
        c.setCity(fields[i++]);
        c.setState(fields[i++]);
        c.setZip(fields[i++]);
        c.setEmail(fields[i++]);
        c.setPhone(fields[i++]);
      }
      contactList.add(c);
    }
    for (int i = 0; i < contactList.size(); i++) {
      System.out.println(
          contactList.get(i).getFirstName() + " " + contactList.get(i).getLastName());
      System.out.println(contactList.get(i).getAddress());
      System.out.println(
          contactList.get(i).getCity()
              + ", "
              + contactList.get(i).getState()
              + "  "
              + contactList.get(i).getZip());
      System.out.println(contactList.get(i).getPhone());
      System.out.println(contactList.get(i).getEmail());
      System.out.println();
    }
  }
예제 #3
0
  /**
   * Gets contact from view.
   *
   * @return a Contact
   */
  public Contact getContact() {
    Contact c = new Contact(personView.get());
    c.setAddress(getAddress());
    c.setTele(getTele());
    c.setEmail(getEmail());
    c.setWebSites(getSites());

    return c;
  }
예제 #4
0
  public ArrayList<Contact> getCustomizedContacts(String interest, String city, String area) {

    ArrayList<Contact> contactList = new ArrayList<Contact>();

    boolean flag = true;

    String selectQuery =
        "select * from " + TABLE_DETAILS + " as a" + " natural join " + TABLE_INTEREST + " as b ";

    if (interest.compareTo("ALL") != 0) {
      if (flag) {
        selectQuery += " where ";
        flag = false;
      } else selectQuery += " and ";

      selectQuery += " a.Sr = b.sr and b.Interest = '" + interest + "'";
    }

    if (city.compareTo("ALL") != 0) {
      if (flag) {
        selectQuery += " where ";
        flag = false;
      } else selectQuery += " and ";

      selectQuery += " a.City = '" + city + "'";
    }

    if (area.compareTo("ALL") != 0) {
      if (flag) {
        selectQuery += " where ";
        flag = false;
      } else selectQuery += " and ";

      selectQuery += " a.Area = '" + area + "'";
    }

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) { // if (cursor != null)
      do {
        Contact contact = new Contact();
        contact.setName(cursor.getString(1));
        contact.setAddress(cursor.getString(4));
        contact.setPhone(cursor.getString(5));
        contact.setInterest(cursor.getString(6));

        contactList.add(contact);

      } while (cursor.moveToNext());
    }
    return contactList;
  }
예제 #5
0
  /** @return the existing or newly created Contact */
  public Contact ensure(String name, Contact owner, String address) {
    Contact contact = (Contact) getNameColumn().firstWhereEq(name);
    if (contact != null) return contact;
    else {
      contact = (Contact) newPersistent();
      contact.setName(name);
      contact.setOwner(owner);
      contact.setAddress(address);

      return (Contact) getNameColumn().ensure(contact);
    }
  }
예제 #6
0
  private void generateContacts() {

    Contact contact1 = new Contact();
    contact1.setFirstName("Al");
    contact1.setLastName("Bundy");
    contact1.setAddress(new Address(9764, "Jeopardy Ln", "Chicago", "IL", 60290));
    addressService.saveAddress(contact1.getAddress());
    contactService.saveContact(contact1);

    Contact contact2 = new Contact();
    contact2.setFirstName("Ned");
    contact2.setLastName("Flanders");
    contact2.setAddress(new Address(740, "Evergreen Terrace", "Springfield", "OR", 97477));
    addressService.saveAddress(contact2.getAddress());
    contactService.saveContact(contact2);

    Contact contact3 = new Contact();
    contact3.setFirstName("Peter");
    contact3.setLastName("Griffin");
    contact3.setAddress(new Address(31, "Spooner St", "Quahog", "RI", 12908));
    addressService.saveAddress(contact3.getAddress());
    contactService.saveContact(contact3);
  }
  /** 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());
    }
  }