1 45 package org.openejb.webadmin.main; 46 47 import java.io.IOException ; 48 import java.io.PrintWriter ; 49 import java.util.Arrays ; 50 import java.util.HashMap ; 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 72 public class DeploymentListBean extends WebAdminBean { 73 private HashMap deploymentIdIndex; 74 private HashMap containerIdIndex; 75 76 77 public void ejbCreate() { 78 this.section = "DeploymentList"; 79 } 80 81 87 public void postProcess(HttpRequest request, HttpResponse response) throws IOException {} 88 89 95 public void preProcess(HttpRequest request, HttpResponse response) throws IOException { 96 createIndexes(); 97 } 98 99 106 public void writeBody(PrintWriter body) throws IOException { 107 String 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 (); 117 containerIdIndex = new HashMap (); 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 body, String id) throws IOException { 130 EnterpriseBeanInfo bean = getBeanInfo(id); 131 132 if (bean == null) 134 return; 135 136 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 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 = (String )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 id) { 223 return (EnterpriseBeanInfo) deploymentIdIndex.get(id); 224 } 225 226 private void printDeployments(PrintWriter out) throws IOException { 227 DeploymentInfo[] deployments = OpenEJB.deployments(); 228 String [] deploymentString = new String [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 ) 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 265 public void writeHtmlTitle(PrintWriter body) throws IOException { 266 body.println(HTML_TITLE); 267 } 268 269 276 public void writePageTitle(PrintWriter body) throws IOException { 277 body.println("EnterpriseBean Details"); 278 } 279 280 300 public void writeSubMenuItems(PrintWriter body) throws IOException {} 301 302 } 303 | Popular Tags |