+ // Then tokenize it
+ // @TODO Move this into separate method
+ tokenizer = new StringTokenizer(line, ";");
+
+ // Count round
+ int count = 0;
+
+ // Init contact object
+ Contact contact = null;
+
+ // The tokens are now available, so get all
+ while (tokenizer.hasMoreElements()) {
+ // Get next token
+ String token = tokenizer.nextToken();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("token={0}", token));
+
+ // Verify token, it must have double-quotes on each side
+ if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {
+ // Something bad was read
+ throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));
+ }
+
+ // All fine, so remove it
+ String strippedToken = token.substring(1, token.length() - 1);
+
+ // Is the string's content "null"?
+ if (strippedToken.equals("null")) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - NULL!", strippedToken));
+
+ // This needs to be set to null
+ strippedToken = null;
+ }
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0}", strippedToken));
+
+ // Init number/string data values
+ String strData = strippedToken;
+ Long num = null;
+ Boolean bool = null;
+ char gender = '?';
+
+ // Now, let's try a number check, if no null
+ if (strippedToken != null) {
+ // Okay, no null, maybe the string bears a decimal number?
+ try {
+ num = Long.valueOf(strippedToken);
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - NUMBER!", strippedToken));
+ } catch (final NumberFormatException ex) {
+ // No number, then set default
+ num = null;
+ }
+ }
+
+ // Now, let's try a boolean check, if no null
+ if ((strippedToken != null) && (num == null) && ((strippedToken.equals("true")) || (strippedToken.equals("false")))) {
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("strippedToken={0} - BOOLEAN!", strippedToken));
+
+ // parseBoolean() is relaxed, so no exceptions
+ bool = Boolean.valueOf(strippedToken);
+ }
+
+ // Now, let's try a boolean check, if no null
+ if ((strippedToken != null) && (num == null) && (bool == null) && ((strippedToken.equals("M")) || (strippedToken.equals("F")) || (strippedToken.equals("C")))) {
+ // Get first character
+ gender = strippedToken.charAt(0);
+ }
+
+ // Now it depends on the counter which position we need to check
+ switch (count) {
+ case 0: // isOwnContact
+ assert ((bool instanceof Boolean));
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("bool={0}", bool));
+
+ // Is it own contact?
+ if (true == bool) {
+ // Debug message
+ this.getLogger().debug("Creating UserContact object ...");
+
+ // Own entry
+ contact = new UserContact();
+ } else {
+ // Debug message
+ this.getLogger().debug("Creating BookContact object ...");
+
+ // Other contact
+ contact = new BookContact();
+ }
+ break;
+
+ case 1: // Gender
+ assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender != '?') : "Gender is not detected.";
+
+ // Update data
+ contact.updateNameData(gender, null, null, null);
+ break;
+
+ case 2: // Surname
+ assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender != '?') : "Gender is not detected.";
+
+ // Update data
+ contact.updateNameData(gender, strippedToken, null, null);
+ break;
+
+ case 3: // Family name
+ assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender != '?') : "Gender is not detected.";
+
+ // Update data
+ contact.updateNameData(gender, null, strippedToken, null);
+ break;
+
+ case 4: // Company name
+ assert (contact instanceof Contact) : "First token was not boolean";
+ assert (gender != '?') : "Gender is not detected.";
+
+ // Update data
+ contact.updateNameData(gender, null, null, strippedToken);
+ break;
+
+ case 5: // Street number
+ assert (contact instanceof Contact) : "First token was not boolean";
+
+ // Update data
+ contact.updateAddressData(strippedToken, 0, null, null);
+ break;
+
+ case 6: // ZIP code
+ assert (contact instanceof Contact) : "First token was not boolean";
+
+ // Update data
+ contact.updateAddressData(null, num, null, null);
+ break;
+
+ case 7: // City name
+ assert (contact instanceof Contact) : "First token was not boolean";
+
+ // Update data
+ contact.updateAddressData(null, 0, strippedToken, null);
+ break;