1 5 package net.sf.panoptes.component.jmx.jelly; 6 7 import javax.management.MalformedObjectNameException ; 8 import javax.management.ObjectName ; 9 10 import net.sf.panoptes.model.node.NodeSupport; 11 import net.sf.panoptes.component.jmx.model.MBeanLinkNode; 12 13 import org.apache.commons.jelly.JellyTagException; 14 import org.apache.commons.jelly.TagSupport; 15 import org.apache.commons.jelly.XMLOutput; 16 17 23 public class MBeanAliasTag extends TagSupport { 24 25 private String name = null; 26 private String objectName = null; 27 28 public void doTag(XMLOutput output) throws JellyTagException { 29 30 NodeSupport parentNode; 31 NodeTag parent = (NodeTag) findAncestorWithClass(NodeTag.class); 32 if (parent != null) parentNode = parent.getNode(); 33 else parentNode = (NodeSupport) getContext().getVariable("rootNode"); 34 35 if (parentNode == null) 36 throw new JellyTagException("This tag must be nested within <node> or descendant of <node> or be in a context where 'rootNode' is set"); 37 38 if (name == null) throw new JellyTagException("Name is not set"); 39 if (objectName == null) throw new JellyTagException("ObjectName is not set"); 40 ObjectName linkName; 41 try { 42 linkName = new ObjectName (objectName); 43 MBeanLinkNode node = new MBeanLinkNode(parentNode, linkName); 44 parentNode.getContext().put(name, node); 45 getContext().setVariable(name, node); 46 } catch (MalformedObjectNameException e) { 47 throw new JellyTagException("Invalid objectname " + objectName, e); 48 } 49 } 50 51 public void setName(String name) { 52 this.name = name; 53 } 54 55 public void setObjectName(String objectName) { 56 this.objectName = objectName; 57 } 58 59 } 60 | Popular Tags |