Package com.funambol.syncclient.sps

Examples of com.funambol.syncclient.sps.Record


        Vector  replaceTags = new Vector();
        Vector  deleteTags  = new Vector();
        //Vector  statusTags = new Vector();

        String msgId       = null;
        Record  record     = null;
        boolean ret        = false;

        // Get message id
        try {
            msgId = getXMLTagValue(modifications, TAG_MSGID );
        }
        catch (StringIndexOutOfBoundsException e){
            sdh.log("[processModification]Invalid message Id from server: " + modifications);
            throw new SyncException("Invalid message from server.");
        }

        // Get message parts
        xmlResponse.addElement(modifications);
        bodyTags    = getXMLTag(getXMLTag(xmlResponse, TAG_SYNCML),   TAG_SYNCBODY );
        addTags     = getXMLTag(bodyTags, TAG_ADD      );
        replaceTags = getXMLTag(bodyTags, TAG_REPLACE  );
        deleteTags  = getXMLTag(bodyTags, TAG_DELETE   );
        //statusTags  = getXMLTag(bodyTags, TAG_STATUS   );

        if (modifications.indexOf("<" + TAG_SYNC + ">") != - 1) {
            ret = true;
        }

        Hashtable cmd = null;

        // ADD
        for (int i=0, l = addTags.size(); i < l; i++) {
           
            cmd = processModificationCommand( (String)addTags.elementAt(i) );
            // If there is an error status,
            if(cmd.get(TAG_STATUS) != null){
                // Add the status command for this item to the list
                addStatusCommand(TAG_ADD, msgId, cmd);
                continue;
            }

            record = new Record( (String)cmd.get(TAG_LOC_URI), ' ',
                                 (String)cmd.get(TAG_DATA));
            String bbKey = "";
           
            try {
                bbKey = dataStore.setRecord(record, false).getKey();
                // Okay, set status code 200
                cmd.put(TAG_STATUS, String.valueOf(STATUS_CODE_OK));
            }
            catch (DataAccessException e) {
                StaticDataHelper.log("[ERROR]Exception in SyncManagerImpl.processModifications(add) invoking setRecord(...): " + e.toString());
                //e.printStackTrace();
                // Set error status code for this item
                cmd.put(TAG_STATUS, String.valueOf(STATUS_CODE_ERROR));
                String msg = e.getMessage();
                throw new SyncException(msg);//it should be enough to break the sync process
            }
            finally {
                // Add the status command for this item to the list
                addStatusCommand(TAG_ADD, msgId, cmd);
            }

            if (bbKey != null) {   
                ret = true;
                mappings.put(bbKey, cmd.get(TAG_LOC_URI));
            }
        }

        // REPLACE
        for (int i = 0, l = replaceTags.size(); i < l; i++) {
            
            cmd = processModificationCommand((String)replaceTags.elementAt(i));
            // If there is an error status,
            if(cmd.get(TAG_STATUS) != null){
                // Add the status command for this item to the list
                addStatusCommand(TAG_REPLACE, msgId, cmd);
                continue;
            }

            record = new Record( (String)cmd.get(TAG_LOC_URI), ' ',
                                 (String)cmd.get(TAG_DATA) );

            try {
                dataStore.setRecord(record, true);
                // Okay, set status code
                cmd.put(TAG_STATUS, String.valueOf(STATUS_CODE_OK));
            }
            catch(DataAccessException e) {
               
                StaticDataHelper.log("[ERROR]Exception in SyncManagerImpl.processModifications(Replace) invoking setRecord(...): " + e.toString());
                e.printStackTrace();

                // Set error status code for this item
                cmd.put(TAG_STATUS, String.valueOf(STATUS_CODE_ERROR));
            }
            finally {
                // Add the status command for this item to the list
                addStatusCommand(TAG_REPLACE, msgId, cmd);
            }
            ret = true;
        }

        // Delete
        for (int i=0, l = deleteTags.size(); i < l; i++) {
            String key = getXMLTagValue((String) deleteTags.elementAt(i), TAG_LOC_URI );
            String cmdId = getXMLTagValue((String) deleteTags.elementAt(i), TAG_CMDID );
           
            record = new Record();
            record.setKey(key);
           
            // Set cmd info for the status handling
            cmd = new Hashtable();
            cmd.put(TAG_CMDID, cmdId);
            cmd.put(TAG_LOC_URI, key);
View Full Code Here


        StringBuffer deleteCmd    = new StringBuffer();
        StringBuffer syncTag      = new StringBuffer();

        int cmdId = 2;

        Record record = null;
        String encryptXmlTag = "";
       
        if (sourceName.equals("xcard") || sourceName.equals("xcal")) {
            encryptXmlTag = "<Format xmlns=\'syncml:metinf\'>b64</Format>";
        }
        if (encryptType != null && !encryptType.equals("none")) {
            encryptXmlTag = "<Format xmlns=\'syncml:metinf\'>"+encryptType+";b64</Format>";  
        }  

        //
        // NOTE: for JDK 1.1.8 compatibility we cannot use StringBuffer.append(StringBuffer)
        //

        // FIXME: this test is not very smart....
        if(msgID == 2) {
            syncTag.append("<Status>\n")
                .append("<CmdID>" + cmdId++ + "</CmdID>\n")
                .append("<MsgRef>1</MsgRef><CmdRef>1</CmdRef><Cmd>Alert</Cmd>\n")
                .append("<TargetRef>")
                .append(sourceURI)
                .append("</TargetRef>\n")
                .append("<SourceRef>")
                .append(sourceURI)
                .append("</SourceRef>\n")
                .append("<Data>200</Data>\n")
                .append("<Item>\n")
                .append("<Data>" + "\n")
                .append("<Anchor xmlns=\"syncml:metinf\"><Next>")
                .append(nextTimestamp)
                .append("</Next></Anchor>\n")
                .append("</Data>\n")
                .append("</Item>\n")
                .append("</Status>\n");
        }

        // Build status commands
        for (int i = 0, l = statusCommands.size(); i < l; i++) {
            syncTag.append("<Status>\n")
                .append("<CmdID>" + cmdId++ + "</CmdID>\n")
                .append(statusCommands.elementAt(i))
                .append("</Status>\n");
        }
        // and cleanup the status vector
        statusCommands.removeAllElements();

        // Build items
        for (int i = 0, l = records.size(); i < l; i++) {
            record = (Record)records.elementAt(i);

            try {
                switch (record.getState()) {

                    case RECORD_STATE_DELETED:
                        deleteItems.append("<Item>\n")
                            .append("<Source><LocURI>")
                            .append(record.getKey())
                            .append("</LocURI></Source>\n")
                            .append("</Item>\n");
                        break;

                    case RECORD_STATE_UPDATED:
                        replaceItems.append("<Item>\n")
                            .append("<Source><LocURI>")
                            .append(record.getKey())
                            .append("</LocURI></Source>\n")
                            .append("<Data>")
                            .append(record.getUid())
                            .append("</Data>\n")
                            .append("</Item>\n");
                        break;

                    case RECORD_STATE_NEW:
                        addItems.append("<Item>\n")
                            .append("<Source><LocURI>")
                            .append(record.getKey())
                            .append("</LocURI></Source>\n")
                            .append("<Data>")
                            .append(record.getUid())
                            .append("</Data>\n")
                            .append("</Item>\n");
                        break;
                }// end switch
            } catch (OutOfMemoryError oom) {
View Full Code Here

TOP

Related Classes of com.funambol.syncclient.sps.Record

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.