[1009] | 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 | */ |
---|
| 16 | package br.com.prognus.psync.phones.s55; |
---|
| 17 | |
---|
| 18 | import java.util.ArrayList; |
---|
| 19 | |
---|
| 20 | import com.funambol.framework.core.*; |
---|
| 21 | import com.funambol.framework.engine.pipeline.InputMessageProcessor; |
---|
| 22 | import com.funambol.framework.engine.pipeline.MessageProcessingContext; |
---|
| 23 | import com.funambol.framework.logging.FunambolLogger; |
---|
| 24 | import com.funambol.framework.logging.FunambolLoggerFactory; |
---|
| 25 | import com.funambol.framework.protocol.ProtocolUtil; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * This class store the synchronization alert code into processingContext. |
---|
| 29 | * |
---|
| 30 | * @version $Id: SyncRequestStore.java,v 1.3 2007-01-11 19:20:19 nichele Exp $ |
---|
| 31 | */ |
---|
| 32 | public class SyncRequestStore implements InputMessageProcessor { |
---|
| 33 | |
---|
| 34 | // ------------------------------------------------------------ Private data |
---|
| 35 | private static final FunambolLogger log = |
---|
| 36 | FunambolLoggerFactory.getLogger("engine.pipeline"); |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | // ---------------------------------------------------------- Public methods |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Process input message and set MessageProcessingContext property. |
---|
| 43 | * |
---|
| 44 | * @param processingContext the message processing context |
---|
| 45 | * @param message the message to be processed |
---|
| 46 | * @throws Sync4jException |
---|
| 47 | */ |
---|
| 48 | public void preProcessMessage(MessageProcessingContext processingContext, |
---|
| 49 | SyncML message) throws Sync4jException { |
---|
| 50 | if (log.isTraceEnabled()) { |
---|
| 51 | log.trace("preProcessMessage: SyncRequestStore of input message"); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | Put clientCapabilities = null; |
---|
| 55 | |
---|
| 56 | try { |
---|
| 57 | AbstractCommand[] allCmd = |
---|
| 58 | (AbstractCommand[])message.getSyncBody().getCommands().toArray( |
---|
| 59 | new AbstractCommand[0]); |
---|
| 60 | // |
---|
| 61 | //Extract only alert commands |
---|
| 62 | // |
---|
| 63 | for (int i=0; (allCmd != null) && (i<allCmd.length); i++) { |
---|
| 64 | if (Alert.COMMAND_NAME.equals(allCmd[i].getName())) { |
---|
| 65 | Alert alertCmd = (Alert)allCmd[i]; |
---|
| 66 | int code = alertCmd.getData(); |
---|
| 67 | processingContext.setRequestProperty(SlowFastSyncManagement.PROPERTY_CODE, String.valueOf(code)); |
---|
| 68 | }//end if cmds |
---|
| 69 | }//end allCmd |
---|
| 70 | |
---|
| 71 | // |
---|
| 72 | //Extract the type of device |
---|
| 73 | // |
---|
| 74 | ArrayList clientCapabilitiesList = ProtocolUtil.filterCommands(allCmd, Put.class); |
---|
| 75 | |
---|
| 76 | if (clientCapabilitiesList.size()>0) { |
---|
| 77 | clientCapabilities = (Put)clientCapabilitiesList.get(0); |
---|
| 78 | |
---|
| 79 | if (log.isTraceEnabled()) { |
---|
| 80 | log.trace("preProcessMessage: name clientCapabilities " |
---|
| 81 | + clientCapabilities.getName()); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | DevInfItem item = (DevInfItem)clientCapabilities.getItems().get(0); |
---|
| 85 | DevInf di = item.getDevInfData().getDevInf(); |
---|
| 86 | String man = di.getMan(); |
---|
| 87 | processingContext.setRequestProperty(SlowFastSyncManagement.PROPERTY_MANTYPE, man); |
---|
| 88 | } |
---|
| 89 | } catch(Exception e) { |
---|
| 90 | log.error("Errore preprocessing the request", e); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | } |
---|