KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > jmx > renderer > html > OperationRenderer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.jmx.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ResourceBundle JavaDoc;
9
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import javax.management.MBeanOperationInfo JavaDoc;
14 import javax.management.MBeanParameterInfo JavaDoc;
15 import org.exoplatform.commons.debug.ObjectDebuger;
16 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
17 import org.exoplatform.portlets.jmx.component.UIOperation;
18
19 /**
20  * Jul 29, 2004
21  * @author: Tuan Nguyen
22  * @email: tuan08@users.sourceforge.net
23  * @version: $Id: OperationRenderer.java,v 1.2 2004/08/01 18:56:11 tuan08 Exp $
24  */

25 public class OperationRenderer extends HtmlBasicRenderer{
26     public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
27         UIOperation uiOperation = (UIOperation) component ;
28     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
29     MBeanOperationInfo JavaDoc operationInfo = uiOperation.getMBeanOperationInfo() ;
30     Object JavaDoc result = uiOperation.getResult() ;
31     String JavaDoc returnData = "" ;
32     if(result != null) returnData = ObjectDebuger.asString(result) ;
33     ResponseWriter w = context.getResponseWriter() ;
34     String JavaDoc baseURL = uiOperation.getBaseURL(context) ;
35     w.write("<form name='operation' action='"); w.write(baseURL); w.write("' method='post'>\n") ;
36     w.write("<input type='hidden' name='"+ ACTION + "' value=''/>") ;
37     w.write("<table class='"); w.write(uiOperation.getClazz()); w.write("'>") ;
38     w. write("<tr>") ;
39     w. write("<th colspan='2'>");
40     w. write(res.getString("UIOperation.header.operation")); w.write(operationInfo.getName());
41     w. write("</th>") ;
42     w. write("</tr>");
43     w. write("<tr>") ;
44     w. write("<td>");w.write(res.getString("UIOperation.label.description"));w.write("</td>") ;
45     w. write("<td>"); w.write(operationInfo.getDescription()); w.write("</td>") ;
46     w. write("</tr>");
47     w. write("<tr>") ;
48     w. write("<td>");w.write(res.getString("UIOperation.label.return-type"));w.write("</td>") ;
49     w. write("<td>"); w.write(operationInfo.getReturnType()); w.write("</td>") ;
50     w. write("</tr>");
51     MBeanParameterInfo JavaDoc[] params = operationInfo.getSignature() ;
52     for(int i = 0 ; i < params.length; i++) {
53       String JavaDoc index = Integer.toString(i) ;
54         w.write("<tr>") ;
55         w. write("<td><label>");w.write(res.getString("UIOperation.label.parameter")); w.write(index); w.write("</label></td>") ;
56       w. write("<td><input name='parameter' value=''/></td>") ;
57         w.write("</tr>");
58     }
59     w. write("<tr>") ;
60     w. write("<td colspan='2' align='center'>") ;
61     w. write("<a HREF=\"javascript:submitOperation('" + UIOperation.EXECUTE_ACTION + "')\">" + res.getString("UIOperation.button.execute") + "</a>") ;
62     w. write("<a HREF=\"javascript:submitOperation('" + CANCEL_ACTION + "')\">" + res.getString("UIOperation.button.cancel") + "</a>") ;
63     w. write("</td>") ;
64     w.write("</tr>");
65     w. write("<tr>") ;
66     w. write("<td colspan='2'>");
67     w. write("<pre>"); w.write(returnData); w.write("</pre>");
68     w. write("</td>") ;
69     w. write("</tr>");
70     w. write(getScript()) ;
71     w.write("</table>") ;
72     w.write("</form>") ;
73     }
74   
75    private String JavaDoc getScript() {
76     String JavaDoc script =
77      "<script type=\"text/javascript\">\n" +
78      " function submitOperation(action) {\n" +
79      " document.operation.elements['"+ ACTION + "'].value = action ;\n" +
80      " document.operation.submit();\n" +
81      " }\n" +
82      "</script>\n" ;
83      return script ;
84   }
85 }
Popular Tags