KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > main > DeploymentListBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: DeploymentListBean.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.webadmin.main;
46
47 import java.io.IOException JavaDoc;
48 import java.io.PrintWriter JavaDoc;
49 import java.util.Arrays JavaDoc;
50 import java.util.HashMap JavaDoc;
51
52 import org.openejb.DeploymentInfo;
53 import org.openejb.OpenEJB;
54 import org.openejb.webadmin.HttpRequest;
55 import org.openejb.webadmin.HttpResponse;
56 import org.openejb.webadmin.WebAdminBean;
57 import org.openejb.alt.assembler.classic.ContainerInfo;
58 import org.openejb.alt.assembler.classic.EjbReferenceInfo;
59 import org.openejb.alt.assembler.classic.EnterpriseBeanInfo;
60 import org.openejb.alt.assembler.classic.EnvEntryInfo;
61 import org.openejb.alt.assembler.classic.JndiEncInfo;
62 import org.openejb.alt.assembler.classic.ResourceReferenceInfo;
63 import org.openejb.alt.config.ConfigurationFactory;
64 import org.openejb.util.StringUtilities;
65
66 /**
67  * A bean which lists all deployed beans.
68  *
69  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
70  * @author <a HREF="mailto:tim_urberg@yahoo.com">Tim Urberg</a>
71  */

72 public class DeploymentListBean extends WebAdminBean {
73     private HashMap JavaDoc deploymentIdIndex;
74     private HashMap JavaDoc containerIdIndex;
75
76     /** Creates a new instance of DeploymentListBean */
77     public void ejbCreate() {
78         this.section = "DeploymentList";
79     }
80
81     /** called after all content is written to the browser
82      * @param request the http request
83      * @param response the http response
84      * @throws IOException if an exception is thrown
85      *
86      */

87     public void postProcess(HttpRequest request, HttpResponse response) throws IOException JavaDoc {}
88
89     /** called before any content is written to the browser
90      * @param request the http request
91      * @param response the http response
92      * @throws IOException if an exception is thrown
93      *
94      */

95     public void preProcess(HttpRequest request, HttpResponse response) throws IOException JavaDoc {
96         createIndexes();
97     }
98
99     /** writes the main body content to the broswer. This content is inside a <code>&lt;p&gt;</code> block
100      *
101      *
102      * @param body the output to write to
103      * @exception IOException if an exception is thrown
104      *
105      */

106     public void writeBody(PrintWriter JavaDoc body) throws IOException JavaDoc {
107         String JavaDoc id = request.getQueryParameter("id");
108         if (id != null) {
109             showDeployment(body, id);
110         } else {
111             printDeployments(body);
112         }
113     }
114
115     private void createIndexes() {
116         deploymentIdIndex = new HashMap JavaDoc();
117         containerIdIndex = new HashMap JavaDoc();
118         ContainerInfo[] cnt = ConfigurationFactory.sys.containerSystem.containers;
119
120         for (int i = 0; i < cnt.length; i++) {
121             containerIdIndex.put(cnt[i].containerName, cnt[i]);
122             EnterpriseBeanInfo[] beans = cnt[i].ejbeans;
123             for (int x = 0; x < beans.length; x++) {
124                 deploymentIdIndex.put(beans[x].ejbDeploymentId, beans[x]);
125             }
126         }
127     }
128
129     private void showDeployment(PrintWriter JavaDoc body, String JavaDoc id) throws IOException JavaDoc {
130         EnterpriseBeanInfo bean = getBeanInfo(id);
131
132         // TODO:0: Inform the user the id is bad
133
if (bean == null)
134             return;
135
136         // Assuming things are good
137
body = response.getPrintWriter();
138
139         body.println("<h2>General</h2><br>");
140         body.println("<table width=\"100%\" border=\"1\">");
141         body.println("<tr bgcolor=\"#5A5CB8\">");
142         body.println("<td><font face=\"arial\" color=\"white\">ID</font></td>");
143         body.println("<td><font color=\"white\">" + id + "</font></td>");
144         body.println("</tr>");
145
146         org.openejb.core.DeploymentInfo di =
147             (org.openejb.core.DeploymentInfo) OpenEJB.getDeploymentInfo(id);
148
149         printRow("Name", bean.ejbName, body);
150         printRow(
151             "Description",
152             StringUtilities.replaceNullOrBlankStringWithNonBreakingSpace(bean.description),
153             body);
154
155         String JavaDoc type = null;
156
157         switch (di.getComponentType()) {
158             case org.openejb.core.DeploymentInfo.CMP_ENTITY :
159                 type = "EntityBean with Container-Managed Persistence";
160                 break;
161             case org.openejb.core.DeploymentInfo.BMP_ENTITY :
162                 type = "EntityBean with Bean-Managed Persistence";
163                 break;
164             case org.openejb.core.DeploymentInfo.STATEFUL :
165                 type = "Stateful SessionBean";
166                 break;
167             case org.openejb.core.DeploymentInfo.STATELESS :
168                 type = "Stateless SessionBean";
169                 break;
170             default :
171                 type = "Unkown Bean Type";
172                 break;
173         }
174
175         printRow("Bean Type", type, body);
176         printRow("Bean Class", bean.ejbClass, body);
177         printRow("Home Interface", bean.home, body);
178         printRow("Remote Interface", bean.remote, body);
179         printRow("Jar location", bean.codebase, body);
180
181         //String container = URLEncoder.encode("" + di.getContainer().getContainerID());
182
String JavaDoc container = (String JavaDoc)di.getContainer().getContainerID();
183         printRow("Deployed in", container, body);
184
185         body.println("</table>");
186
187         JndiEncInfo enc = bean.jndiEnc;
188         EnvEntryInfo[] envEntries = enc.envEntries;
189         EjbReferenceInfo[] ejbReferences = enc.ejbReferences;
190         ResourceReferenceInfo[] resourceRefs = enc.resourceRefs;
191
192         if (envEntries.length > 0 || ejbReferences.length > 0 || resourceRefs.length > 0) {
193             body.println("<h2>JNDI Environment Details</h2><br>");
194             body.println("<table width=\"100%\" border=\"1\">");
195             body.println("<tr bgcolor=\"#5A5CB8\">");
196             body.println("<td><font face=\"arial\" color=\"white\">JNDI Name</font></td>");
197             body.println("<td><font face=\"arial\" color=\"white\">Value</font></td>");
198             body.println("<td><font face=\"arial\" color=\"white\">Type</font></td>");
199             body.println("</tr>");
200         }
201
202         for (int i = 0; i < envEntries.length; i++) {
203             EnvEntryInfo e = envEntries[i];
204             printRow(e.name, e.value, e.type, body);
205         }
206
207         for (int i = 0; i < ejbReferences.length; i++) {
208             EjbReferenceInfo e = ejbReferences[i];
209             printRow(e.referenceName, e.location.ejbDeploymentId, e.homeType, body);
210         }
211
212         for (int i = 0; i < resourceRefs.length; i++) {
213             ResourceReferenceInfo r = resourceRefs[i];
214             printRow(r.referenceName, r.resourceID, r.referenceType, body);
215         }
216
217         if (envEntries.length > 0 || ejbReferences.length > 0 || resourceRefs.length > 0) {
218             body.println("</table>");
219         }
220     }
221
222     private EnterpriseBeanInfo getBeanInfo(String JavaDoc id) {
223         return (EnterpriseBeanInfo) deploymentIdIndex.get(id);
224     }
225
226     private void printDeployments(PrintWriter JavaDoc out) throws IOException JavaDoc {
227         DeploymentInfo[] deployments = OpenEJB.deployments();
228         String JavaDoc[] deploymentString = new String JavaDoc[deployments.length];
229         out.println("<table width=\"100%\" border=\"1\">");
230         out.println("<tr bgcolor=\"#5A5CB8\">");
231         out.println("<td><font color=\"white\">Deployment ID</font></td>");
232         out.println("</tr>");
233
234         if (deployments.length > 0) {
235             for (int i = 0; i < deployments.length; i++) {
236                 deploymentString[i] = (String JavaDoc) deployments[i].getDeploymentID();
237             }
238             Arrays.sort(deploymentString);
239
240             for (int i = 0; i < deploymentString.length; i++) {
241                 if (i % 2 == 1) {
242                     out.println("<tr bgcolor=\"#c9c5fe\">");
243                 } else {
244                     out.println("<tr>");
245                 }
246
247                 out.print("<td><span class=\"bodyBlack\">");
248                 out.print("<a HREF=\"DeploymentList?id=" + deploymentString[i] + "\">");
249                 out.print(deploymentString[i]);
250                 out.print("</a>");
251                 out.println("</span></td></tr>");
252             }
253         }
254         out.println("</table>");
255     }
256
257     /** Write the TITLE of the HTML document. This is the part
258      * that goes into the <code>&lt;head&gt;&lt;title&gt;
259      * &lt;/title&gt;&lt;/head&gt;</code> tags
260      *
261      * @param body the output to write to
262      * @exception IOException of an exception is thrown
263      *
264      */

265     public void writeHtmlTitle(PrintWriter JavaDoc body) throws IOException JavaDoc {
266         body.println(HTML_TITLE);
267     }
268
269     /** Write the title of the page. This is displayed right
270      * above the main block of content.
271      *
272      * @param body the output to write to
273      * @exception IOException if an exception is thrown
274      *
275      */

276     public void writePageTitle(PrintWriter JavaDoc body) throws IOException JavaDoc {
277         body.println("EnterpriseBean Details");
278     }
279
280     /** Write the sub items for this bean in the left navigation bar of
281      * the page. This should look somthing like the one below:
282      *
283      * <code>
284      * &lt;tr&gt;
285      * &lt;td valign="top" align="left"&gt;
286      * &lt;a HREF="system?show=deployments"&gt;&lt;span class="subMenuOff"&gt;
287      * &nbsp;&nbsp;&nbsp;Deployments
288      * &lt;/span&gt;
289      * &lt;/a&gt;&lt;/td&gt;
290      * &lt;/tr&gt;
291      * </code>
292      *
293      * Alternately, the bean can use the method formatSubMenuItem(..) which
294      * will create HTML like the one above
295      *
296      * @param body the output to write to
297      * @exception IOException if an exception is thrown
298      *
299      */

300     public void writeSubMenuItems(PrintWriter JavaDoc body) throws IOException JavaDoc {}
301
302 }
303
Popular Tags