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.synclet; |
---|
17 | |
---|
18 | import com.funambol.framework.core.Sync4jException; |
---|
19 | import com.funambol.framework.core.SyncML; |
---|
20 | import com.funambol.framework.engine.pipeline.*; |
---|
21 | import com.funambol.framework.logging.FunambolLogger; |
---|
22 | import com.funambol.framework.logging.FunambolLoggerFactory; |
---|
23 | import com.funambol.framework.tools.SyncMLUtil; |
---|
24 | |
---|
25 | /** |
---|
26 | * This class just logs input and output messages. This synclet can then be |
---|
27 | * inserted in any position in a pipeline in order to trace how a message is |
---|
28 | * changed during the pipeline processing. It is at the same time an input and |
---|
29 | * an output pipeline component.<br> |
---|
30 | * Logging is done at INFO level |
---|
31 | * |
---|
32 | * @version $Id: LoggingSynclet.java,v 1.4 2007-01-11 19:20:19 nichele Exp $ |
---|
33 | */ |
---|
34 | public class LoggingSynclet implements InputMessageProcessor, OutputMessageProcessor { |
---|
35 | |
---|
36 | // ------------------------------------------------------------ Private data |
---|
37 | |
---|
38 | private static final FunambolLogger log = |
---|
39 | FunambolLoggerFactory.getLogger("engine.pipeline"); |
---|
40 | |
---|
41 | // ---------------------------------------------------------- Public methods |
---|
42 | |
---|
43 | /** |
---|
44 | * Logs the input message and context |
---|
45 | * |
---|
46 | * @param processingContext the message processing context |
---|
47 | * @param message the message to be processed |
---|
48 | * |
---|
49 | * @throws Sync4jException |
---|
50 | */ |
---|
51 | public void preProcessMessage(MessageProcessingContext processingContext, |
---|
52 | SyncML message) |
---|
53 | throws Sync4jException { |
---|
54 | if (log.isInfoEnabled()) { |
---|
55 | log.info("--------------------------------------------------------------------------------"); |
---|
56 | log.info("Input message processing context" ); |
---|
57 | log.info(" "); |
---|
58 | log.info(processingContext.toString() ); |
---|
59 | log.info("--------------------------------------------------------------------------------"); |
---|
60 | log.info("Input message" ); |
---|
61 | log.info(" "); |
---|
62 | log.info(SyncMLUtil.toXML(message) ); |
---|
63 | log.info("--------------------------------------------------------------------------------"); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Logs the output message and context |
---|
69 | * |
---|
70 | * @param processingContext the message processing context |
---|
71 | * @param message the message to be processed |
---|
72 | * |
---|
73 | * @throws Sync4jException |
---|
74 | */ |
---|
75 | public void postProcessMessage(MessageProcessingContext processingContext, |
---|
76 | SyncML message) |
---|
77 | throws Sync4jException { |
---|
78 | if (log.isInfoEnabled()) { |
---|
79 | log.info("--------------------------------------------------------------------------------"); |
---|
80 | log.info("Output message processing context" ); |
---|
81 | log.info(" "); |
---|
82 | log.info(processingContext.toString() ); |
---|
83 | log.info("--------------------------------------------------------------------------------"); |
---|
84 | log.info("Output message" ); |
---|
85 | log.info(" "); |
---|
86 | log.info(SyncMLUtil.toXML(message) ); |
---|
87 | log.info("--------------------------------------------------------------------------------"); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | } |
---|