KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > justobjects > pushlet > core > XMLAdapter


1 // Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
2
// Distributable under LGPL license. See terms of license at gnu.org.
3

4 package nl.justobjects.pushlet.core;
5
6 import nl.justobjects.pushlet.util.Log;
7
8 import javax.servlet.ServletOutputStream JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import java.io.IOException JavaDoc;
11
12 /**
13  * ClientAdapter that sends Events as XML.
14  *
15  * @version $Id: XMLAdapter.java,v 1.3 2005/02/28 12:45:59 justb Exp $
16  * @author Just van den Broecke - Just Objects &copy;
17  */

18 class XMLAdapter implements ClientAdapter {
19     private ServletOutputStream JavaDoc out = null;
20     private HttpServletResponse JavaDoc servletRsp;
21
22     /** Initialize. */
23     public XMLAdapter(HttpServletResponse JavaDoc aServletResponse) {
24         servletRsp = aServletResponse;
25     }
26
27     public void start() throws IOException JavaDoc {
28
29         // Set content to plain text
30
// NB this is not a complete XML document, but rather
31
// a stream of XML documents where each document is
32
// an Event.
33
servletRsp.setContentType("text/plain");
34
35         out = servletRsp.getOutputStream();
36
37         // Don't need this further
38
servletRsp = null;
39
40     }
41
42     /** Force client to refresh the request. */
43     public void push(Event anEvent) throws IOException JavaDoc {
44         debug("event=" + anEvent);
45
46         // Send the event as XML to the client and flush.
47
out.print(anEvent.toXML());
48         out.flush();
49     }
50
51     /** No action. */
52     public void stop() throws IOException JavaDoc {
53     }
54
55     private void debug(String JavaDoc s) {
56         Log.debug("[XMLAdapter]" + s);
57     }
58 }
59
60 /*
61  * $Log: XMLAdapter.java,v $
62  * Revision 1.3 2005/02/28 12:45:59 justb
63  * introduced Command class
64  *
65  * Revision 1.2 2005/02/21 11:50:47 justb
66  * ohase1 of refactoring Subscriber into Session/Controller/Subscriber
67  *
68  * Revision 1.1 2005/02/18 10:07:23 justb
69  * many renamings of classes (make names compact)
70  *
71  * Revision 1.7 2004/09/03 22:35:37 justb
72  * Almost complete rewrite, just checking in now
73  *
74  * Revision 1.6 2004/03/10 14:01:55 justb
75  * formatting and *Subscriber refactoring
76  *
77  * Revision 1.5 2003/08/15 08:37:40 justb
78  * fix/add Copyright+LGPL file headers and footers
79  *
80  * Revision 1.4 2003/08/13 14:00:00 justb
81  * some testing for applets; no real change
82  *
83  * Revision 1.3 2003/08/12 09:57:06 justb
84  * replaced all print statements to Log.*() calls
85  *
86  * Revision 1.2 2003/05/19 21:56:29 justb
87  * various fixes for applet clients
88  *
89  * Revision 1.1 2003/05/18 16:12:28 justb
90  * adding support for XML encoded Events
91  */

92
Popular Tags