1 5 package net.sf.panoptes.component.jmx.jelly; 6 7 import net.sf.panoptes.model.node.GroupNode; 8 import net.sf.panoptes.model.node.NodeSupport; 9 import net.sf.panoptes.model.node.NodeDescriptor; 10 import net.sf.panoptes.component.jmx.model.MBeanServerNode; 11 12 import org.apache.commons.jelly.JellyTagException; 13 import org.apache.commons.jelly.MissingAttributeException; 14 import org.apache.commons.jelly.TagSupport; 15 import org.apache.commons.jelly.XMLOutput; 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 19 25 public abstract class NodeTag extends TagSupport { 26 27 protected Log log = LogFactory.getLog(getClass()); 28 29 private String name; 30 private String description; 31 private GroupNode parentNode; 32 private GroupNode group; 33 private String iconName; 34 private MBeanServerNode serverNode = null; 35 private NodeSupport node = null; 36 37 private String aliasName = null; 38 39 42 public void doTag(XMLOutput output) throws JellyTagException { 43 44 if (parentNode == null) { 45 GroupTag parent = (GroupTag) findAncestorWithClass(GroupTag.class); 46 if (parent != null) 47 parentNode = (GroupNode) parent.getNode(); 48 else 49 parentNode = (GroupNode) getContext().getVariable("rootNode"); 50 51 if (parentNode == null) { 52 throw new JellyTagException("This tag must be nested within <node> or descendant of <node> or be in a context where 'rootNode' is set"); 53 } 54 } 55 56 if (name == null) { 57 throw new MissingAttributeException("name"); 58 } 59 60 if (description == null) { 61 throw new MissingAttributeException("description"); 62 } 63 } 64 65 public void doDefault(NodeSupport node) { 66 67 NodeDescriptor desc = node.getConfigDescriptor(); 68 node.setConfigDescriptor( 69 new NodeDescriptor( 70 getName(), 71 getDescription(), 72 getIcon() == null ? desc.getIconName() : getIcon())); 73 74 if (serverNode != null) 75 node.getContext().put(MBeanServerNode.MBEANSERVERNODE_KEY, serverNode); 76 77 78 if (aliasName != null) { 79 getParentNode().getContext().put(aliasName, node); 80 node.getContext().put(aliasName, node); 81 getContext().setVariable(aliasName, node); 82 } 83 84 if (iconName != null) 85 desc.setIconName(iconName); 86 87 this.node = node; 88 } 89 90 public NodeSupport getNode() { 91 return node; 92 } 93 94 97 public String getDescription() { 98 return description; 99 } 100 101 104 public void setDescription(String description) { 105 this.description = description; 106 } 107 108 111 public String getName() { 112 return name; 113 } 114 115 118 public void setName(String name) { 119 this.name = name; 120 } 121 122 public void setIcon(String iconName) { 123 this.iconName = iconName; 124 } 125 126 public String getIcon() { 127 return iconName; 128 } 129 130 public void setParentNode(GroupNode parent) { 131 this.parentNode = parent; 132 } 133 134 public GroupNode getParentNode() { 135 return parentNode; 136 137 } 138 139 public GroupNode getGroup() { 140 return group; 141 } 142 143 public void setGroup(GroupNode group) { 144 this.group = group; 145 } 146 147 public void setAliasName(String aliasName) { 148 this.aliasName = aliasName; 149 } 150 151 155 public void setServer(MBeanServerNode serverNode) { 156 this.serverNode = serverNode; 157 } 158 159 private MBeanServerNode getServer() { 160 return serverNode; 161 } 162 163 } 164 | Popular Tags |