KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > pipeline > PipelineManager


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.engine.pipeline;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.Level JavaDoc;
24
25 import sync4j.framework.logging.Sync4jLogger;
26
27 import sync4j.framework.core.SyncML;
28 import sync4j.framework.core.Sync4jException;
29
30 import sync4j.framework.engine.pipeline.StopProcessingException;
31
32 /**
33  * This class represents the manager of the pipeline. It supplies a hook for
34  * adding additional processing and manipulation of the message between the
35  * server and the client.
36  * <p>
37  * This pipeline manager handles the <i>StopProcessingException</i> event
38  * stopping the input or output message processing. No other actions are taken.
39  *
40  * @version $Id: PipelineManager.java,v 1.9 2005/03/02 20:57:37 harrie Exp $
41  */

42 public class PipelineManager
43 implements InputMessageProcessor, OutputMessageProcessor, Serializable JavaDoc {
44     
45     // --------------------------------------------------------------- Constants
46

47     // ------------------------------------------------------------ Private data
48

49     private static final Logger JavaDoc log = Sync4jLogger.getLogger("engine");
50     
51     // ------------------------------------------------------------ Constructors
52

53     // -------------------------------------------------------------- Properties
54

55     private InputMessageProcessor inputProcessors[] = null;
56     private OutputMessageProcessor outputProcessors[] = null;
57     
58     /** Getter for property inputProcessors.
59      * @return Value of property inputProcessors.
60      */

61     public InputMessageProcessor[] getInputProcessors() {
62         return this.inputProcessors;
63     }
64     
65     /** Setter for property inputProcessors.
66      * @param inputProcessors New value of property inputProcessors.
67      */

68     public void setInputProcessors(InputMessageProcessor[] inputProcessors) {
69         this.inputProcessors = inputProcessors;
70     }
71     
72     /** Getter for property outputProcessors.
73      * @return Value of property outputProcessors.
74      */

75     public OutputMessageProcessor[] getOutputProcessors() {
76         return this.outputProcessors;
77     }
78     
79     /** Setter for property outputProcessors
80      * @param outputProcessors New value of property outputProcessors.
81      */

82     public void setOutputProcessors(OutputMessageProcessor[] outputProcessors) {
83         this.outputProcessors = outputProcessors;
84     }
85     
86     // ---------------------------------------------------------- Public methods
87

88     /**
89      * Process the message with the input processors.
90      *
91      * @param processingContext message processing context
92      * @param message the message to be processed
93      */

94     public void preProcessMessage(MessageProcessingContext processingContext, SyncML message) {
95         if (log.isLoggable(Level.FINEST)) {
96             log.finest("Starting preprocessing");
97         }
98         
99         int size = inputProcessors.length;
100         for (int i=0; i<size; i++) {
101             try {
102                 inputProcessors[i].preProcessMessage(processingContext, message);
103             } catch (StopProcessingException e) {
104                 if (log.isLoggable(Level.INFO)) {
105                     log.info( "Input processing stopped by "
106                             + inputProcessors[i]
107                             + " (reason: "
108                             + e.getMessage()
109                             + ")"
110                             );
111                 }
112                 break;
113             } catch(Sync4jException e) {
114                 log.info("preProcessMessage error: " + e);
115             }
116         }
117     }
118     
119     /**
120      * Process the message with the output processors.
121      *
122      * @param processingContext message processing context
123      * @param message the message to be processed
124      */

125     public void postProcessMessage(MessageProcessingContext processingContext, SyncML message) {
126         if (log.isLoggable(Level.FINEST)) {
127             log.finest("Starting postprocessing");
128         }
129         
130         int size = outputProcessors.length;
131         for (int i=0; i<size; i++) {
132             try {
133                 outputProcessors[i].postProcessMessage(processingContext, message);
134             } catch (StopProcessingException e) {
135                 if (log.isLoggable(Level.INFO)) {
136                     log.info( "Output processing stopped by "
137                             + outputProcessors[i]
138                             + " (reason: "
139                             + e.getMessage()
140                             + ")"
141                             );
142                 }
143                 break;
144             } catch(Sync4jException e) {
145                 log.info("postProcessMessage error: " + e);
146             }
147         }
148     }
149     
150 }
151
Popular Tags