public void commit(User parsed) throws IOException {
     try {
         cachedStorage().write(parsed);
     } catch (SessionUnavailableException e) {
         e.printStackTrace();
         throw new UserStorageClosedException("User databse closed while writing case.");
     } catch (StorageFullException e) {
         e.printStackTrace();
         throw new IOException("Storage full while writing case!");
     }
 }
    public User parse() throws InvalidStructureException, IOException, XmlPullParserException {
        this.checkNode("registration");
        
        //parse (with verification) the next tag
        this.nextTag("username");
        String username = parser.nextText();
        
        this.nextTag("password");
        String passwordHash = parser.nextText();
        
        this.nextTag("uuid");
        String uuid = parser.nextText();
        
        this.nextTag("date");
        String dateModified = parser.nextText();
        Date modified = DateUtils.parseDateTime(dateModified);

        User u;
        try {
            u = retrieve(uuid);
        } catch (SessionUnavailableException e) {
            // User db's closed so escape since saving isn't possible.
            throw new UserStorageClosedException(e.getMessage());
        }
        
        if(u == null) {
            u = new User(username, passwordHash, uuid);
            u.setWrappedKey(wrappedKey);
        } else {
            if(passwordHash != null && !passwordHash.equals(u.getPassword())) {
                u.setPassword(passwordHash);
                u.setWrappedKey(wrappedKey);
            } 
        }
        
        //Now look for optional components
        while (this.nextTagInBlock("registration")) {
            String tag = parser.getName().toLowerCase();
            
            if(tag.equals("registering_phone_id")) {
                String phoneid = parser.nextText();
            } else if(tag.equals("token")) {
                String token = parser.nextText();
            } else if(tag.equals("user_data")) {
                while(this.nextTagInBlock("user_data")) {
                    this.checkNode("data");
                    
                    String key = this.parser.getAttributeValue(null, "key");
                    String value = this.parser.nextText();
                    
                    u.setProperty(key, value);
                }
                
                //This should be the last block in the registration stuff...
                break;
            } else {
                throw new InvalidStructureException("Unrecognized tag in user registraiton data: " + tag,parser);
            }
        }
        
        commit(u);
        return u;
    }