source: contrib/psync/src/main/java/br/com/prognus/psync/phones/s55/SlowFastSyncManagement.java @ 1009

Revision 1009, 3.7 KB checked in by wmerlotto, 15 years ago (diff)

Ticket #554 - Commit da versão inicial do psync.

Line 
1/**
2 * Copyright (C) 2003-2007 Funambol
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the Honest Public License.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * Honest Public License for more details.
11 *
12 * You should have received a copy of the Honest Public License
13 * along with this program; if not, write to Funambol,
14 * 643 Bair Island Road, Suite 305 - Redwood City, CA 94063, USA
15 */
16package br.com.prognus.psync.phones.s55;
17
18import com.funambol.framework.core.*;
19import com.funambol.framework.engine.pipeline.MessageProcessingContext;
20import com.funambol.framework.engine.pipeline.OutputMessageProcessor;
21import com.funambol.framework.logging.FunambolLogger;
22import com.funambol.framework.logging.FunambolLoggerFactory;
23
24/**
25 * This class check if the request of slow or fast sync is correct.
26 *
27 * @version $Id: SlowFastSyncManagement.java,v 1.3 2007-01-11 19:20:19 nichele Exp $
28 */
29public class SlowFastSyncManagement implements OutputMessageProcessor {
30
31    // --------------------------------------------------------------- Constants
32
33    public static final String PROPERTY_MANTYPE =
34        "funambol.foundation.slowfastsyncmanagement.MANTYPE";
35    public static final String PROPERTY_CODE    =
36        "funambol.foundation.slowfastsyncmanagement.CODE"   ;
37
38    // ------------------------------------------------------------ Private data
39    private static final FunambolLogger log =
40            FunambolLoggerFactory.getLogger("engine.pipeline");
41
42    private static final String PHONE_SIEMENS = "siemens";
43
44    // ---------------------------------------------------------- Public methods
45
46    /**
47     * Process and manipulate the output message.
48     *
49     * @param processingContext the message processing context
50     * @param message the message to be processed
51     * @throws Sync4jException
52     */
53    public void postProcessMessage(MessageProcessingContext processingContext,
54                                   SyncML message) throws Sync4jException {
55        if (log.isTraceEnabled()) {
56            log.trace("postProcessMessage: SlowFastSyncManagement of output message");
57        }
58
59        try {
60
61            //
62            //Only if the device is Siemens55 apply the code
63            //
64            String man = (String)processingContext.getRequestProperty(PROPERTY_MANTYPE);
65            if (log.isTraceEnabled()) {
66                log.trace("postProcessMessage: man: " + man);
67            }
68
69            if (man != null && man.toLowerCase().indexOf(PHONE_SIEMENS) != -1) {
70
71                AbstractCommand[] allCmd = (AbstractCommand[])
72                    message.getSyncBody().getCommands().toArray(
73                                                        new AbstractCommand[0]);
74                //
75                //Extract only alert commands
76                //
77                for (int i=0; (allCmd != null) && (i<allCmd.length); i++) {
78                    if (Alert.COMMAND_NAME.equals(allCmd[i].getName())) {
79                        Alert alertCmd = (Alert)allCmd[i];
80                        int code = alertCmd.getData();
81
82                        int codeRequest = Integer.parseInt("" + processingContext.getRequestProperty(PROPERTY_CODE));
83
84                        if (code != codeRequest) {
85                            if (code == AlertCode.SLOW) {
86                                alertCmd.setData(AlertCode.TWO_WAY);
87                            }
88                        }
89                    }//end if cmds
90                }//end allCmd
91            }
92
93        } catch(Exception e) {
94            log.error("Errore postprocessing the request", e);
95        }
96    }
97}
Note: See TracBrowser for help on using the repository browser.