1 5 package org.exoplatform.portlets.jmx.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.ResourceBundle ; 9 10 import javax.faces.component.UIComponent; 11 import javax.faces.context.FacesContext; 12 import javax.faces.context.ResponseWriter; 13 import javax.management.MBeanOperationInfo ; 14 import javax.management.MBeanParameterInfo ; 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 25 public class OperationRenderer extends HtmlBasicRenderer{ 26 public void encodeChildren( FacesContext context, UIComponent component ) throws IOException { 27 UIOperation uiOperation = (UIOperation) component ; 28 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ; 29 MBeanOperationInfo operationInfo = uiOperation.getMBeanOperationInfo() ; 30 Object result = uiOperation.getResult() ; 31 String returnData = "" ; 32 if(result != null) returnData = ObjectDebuger.asString(result) ; 33 ResponseWriter w = context.getResponseWriter() ; 34 String 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 [] params = operationInfo.getSignature() ; 52 for(int i = 0 ; i < params.length; i++) { 53 String 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 getScript() { 76 String 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 |