1 package com.lc.jmxconsole.model.node; 2 3 import java.io.StringWriter ; 4 import java.io.Writer ; 5 6 import net.sf.panoptes.component.jmx.model.ServerRegistry; 7 import net.sf.panoptes.controller.MainController; 8 import net.sf.panoptes.model.node.GroupNode; 9 import net.sf.panoptes.model.node.NodeSupport; 10 import net.sf.panoptes.registry.Template; 11 12 import org.apache.commons.jelly.JellyContext; 13 import org.apache.commons.jelly.XMLOutput; 14 15 public class TemplateNode extends GroupNode { 16 17 private Template template; 18 19 22 public TemplateNode(NodeSupport parent, String name, String description, Template template) { 23 super(parent, name, description); 24 this.template = template; 25 } 26 27 public void init() { 28 29 } 30 31 34 public boolean acceptsChildren() { 35 return false; 36 } 37 38 39 public void refresh() { 40 clear(); 41 JellyContext context = new JellyContext(); 42 43 context.setVariables(getContext()); 44 context.setVariable("rootNode", this); 45 context.setVariable("serverRegistry", ServerRegistry.getInstance()); 46 Writer output = new StringWriter (0); 47 XMLOutput xmlOutput = XMLOutput.createXMLOutput(output); long startTime = System.currentTimeMillis(); 49 try { 50 context.runScript(template.getScript(), xmlOutput); 51 } catch (Exception e) { 52 MainController.getInstance().displayError("Unable to construct template", e.getMessage(), e); 53 } 54 55 56 } 57 58 59 60 } 61 | Popular Tags |