Source code: com/voytechs/html/application/ToolServlet.java
1 /*
2 * File: ToolServlet.java
3 * Auth: Mark Bednarczyk
4 * Date: DATE
5 * Id: $Id: ToolServlet.java,v 1.1.1.1 2002/01/23 23:52:49 voytechs Exp $
6 ********************************************
7 * $Log: ToolServlet.java,v $
8 * Revision 1.1.1.1 2002/01/23 23:52:49 voytechs
9 * Initial public release, BETA 1.0 - voytechs
10 *
11 */
12 package com.voytechs.html.application;
13
14 import com.voytechs.html.util.*;
15 import com.voytechs.html.event.*;
16 import com.voytechs.html.component.*;
17
18 import java.io.*;
19 import java.util.*;
20
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23
24 /**
25 * Base class for all tool servlets.
26 * One ToolServlet object exists and it manages individual
27 * ToolSession objects. One ToolSession object exists per each
28 * user session as created by the WebServer/WebBrowser.
29 * <BR>
30 * Tool servlets interact with each other in a way that allows
31 * commnitcation between any tools servlet and discoveries
32 * of tools by any of the tools. (ie. A desktop tool can discover
33 * all other tools and ask them to produce content that can be pluged into
34 * the desktop.)
35 */
36 public abstract class ToolServlet
37 extends HttpServlet {
38
39 /* Internal attributes */
40 private String servletName = "Default";
41 private String servletPath = "/tools";
42
43 private ServletConfig servletConfig = null;
44 static private Vector toolServlets = new Vector();
45
46 /**
47 *
48 * @param
49 * @exception
50 */
51 public ToolServlet(String name) {
52 servletName = name;
53
54 }
55
56 /**
57 * Get name of the servlet application
58 */
59 public String getName() {
60 return(servletName);
61 }
62
63 /**
64 * Get path to the servlet application
65 */
66 public String getPath() {
67 return(servletPath);
68 }
69
70 /**
71 * Get all the ToolServlets currently running.
72 * @return a Vector off all ToolServlets currently running.
73 */
74 public static Vector getToolServlets() {
75 return(toolServlets);
76 }
77
78 /**
79 * Get the servlet config object.
80 */
81 public ServletConfig getServletConfig() {
82 return(servletConfig);
83 }
84
85 public void init(ServletConfig conf)
86 throws ServletException {
87
88 LogFacility.log.println();
89 LogFacility.log.println();
90 LogFacility.log.println();
91 LogFacility.log.println();
92 LogFacility.log.println();
93
94 servletConfig = conf;
95
96 /** Add to the static list of tool servlets. */
97 if(getName().equals("Desktop") == false)
98 toolServlets.addElement(this);
99 }
100
101 /**
102 *
103 * @param
104 * @exception
105 */
106 public void doPost(HttpServletRequest req, HttpServletResponse res)
107 throws ServletException, IOException {
108 doGet(req, res);
109 }
110
111 public void doGet(HttpServletRequest req, HttpServletResponse res)
112 throws ServletException, IOException {
113
114 ServletFrame frame = retrieveSession(req);
115
116 try {
117 // Allow the application pre scan request
118 frame.preScan(req, res);
119
120 // Allow the application process the request
121 frame.scanServletRequest(req);
122
123 // Allow the application to respond to the request
124 frame.generateResponse(res);
125
126 // Allow the application to follow up and close up shop.
127 frame.postScan(res);
128
129 // LogFacility.log.println(frame.toStringTree(""));
130 }
131 catch(EventException ee) {
132 LogFacility.err.println(ee);
133 }
134 catch(ServletException se) {
135 LogFacility.err.println(se);
136 }
137 catch(IOException ie) {
138 LogFacility.err.println(ie);
139 }
140
141 }
142
143 /**
144 * Retrieves the GUI Frame stored in the HttpSession object. If a new session is created
145 * A ServletFrame is created and an abstract method createSessionPanel() is called to
146 * create a new HTTP Panel for this new session. This function should be defined in
147 * sub-classed application specific object.
148 * @param req Http request which contains the HttpSession object.
149 * @exception Any servlet related errors.
150 */
151 private ServletFrame retrieveSession(HttpServletRequest req) throws ServletException {
152
153 HttpSession httpSession = req.getSession(true);
154 ServletFrame frame = (ServletFrame)httpSession.getValue(getName());
155 if(frame == null) {
156 try {
157 LogFacility.log.println("ToolServlet::retrieveSession() - creating new session");
158 frame = new ServletFrame(getName(), getPath(), servletConfig);
159
160 frame.addElement(createSessionPanel());
161
162 /**
163 * After the application Panel has been bound to the frame with the dispatcher,
164 * we are ready to initialize the tree by recursive call to init().
165 */
166 frame.initTree();
167
168 httpSession.putValue(getName(), frame);
169 }
170 catch(EventException ee) {
171 LogFacility.err.println(ee);
172 }
173 }
174 else
175 LogFacility.log.println("ToolServlet::retrieveSession() - using existing session");
176
177 return(frame);
178 }
179
180 public abstract Panel createSessionPanel() throws EventException;
181
182 /**
183 * Test function for ToolServlet
184 * @param args command line arguments
185 */
186 public static void main(String [] args) {
187 }
188
189 } /* END OF: ToolServlet */