KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > panoptes > component > jmx > jelly > MBeanAliasTag


1 /*
2  * Created on Aug 25, 2003
3  *
4  */

5 package net.sf.panoptes.component.jmx.jelly;
6
7 import javax.management.MalformedObjectNameException JavaDoc;
8 import javax.management.ObjectName JavaDoc;
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 /**
18  *
19  *
20  * @author Dag Liodden
21  * @version 0.1
22  */

23 public class MBeanAliasTag extends TagSupport {
24
25     private String JavaDoc name = null;
26     private String JavaDoc 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 JavaDoc linkName;
41         try {
42             linkName = new ObjectName JavaDoc(objectName);
43             MBeanLinkNode node = new MBeanLinkNode(parentNode, linkName);
44             parentNode.getContext().put(name, node);
45             getContext().setVariable(name, node);
46         } catch (MalformedObjectNameException JavaDoc e) {
47             throw new JellyTagException("Invalid objectname " + objectName, e);
48         }
49     }
50     
51     public void setName(String JavaDoc name) {
52         this.name = name;
53     }
54     
55     public void setObjectName(String JavaDoc objectName) {
56         this.objectName = objectName;
57     }
58
59 }
60
Popular Tags