1 22 package org.jboss.console.plugins.helpers; 23 24 import org.jboss.console.manager.interfaces.ManageableResource; 25 import org.jboss.console.manager.interfaces.ResourceTreeNode; 26 import org.jboss.console.manager.interfaces.TreeAction; 27 import org.jboss.console.manager.interfaces.TreeNode; 28 import org.jboss.console.manager.interfaces.TreeNodeMenuEntry; 29 import org.jboss.console.manager.interfaces.impl.HttpLinkTreeAction; 30 import org.jboss.console.manager.interfaces.impl.MBeanResource; 31 import org.jboss.console.manager.interfaces.impl.SeparatorTreeNodeMenuEntry; 32 import org.jboss.console.manager.interfaces.impl.SimpleResourceTreeNode; 33 import org.jboss.console.manager.interfaces.impl.SimpleTreeNode; 34 import org.jboss.console.manager.interfaces.impl.SimpleTreeNodeMenuEntryImpl; 35 36 import javax.management.ObjectName ; 37 38 53 public class TreeNodeFactory 54 { 55 56 public final static int NAME = 0; 57 public final static int DESCRIPTION = 1; 58 public final static int ICON_URL = 2; 59 public final static int DEFAULT_URL = 3; 60 public final static int MENU_ENTRIES = 4; 61 public final static int SUB_NODES = 5; 62 public final static int SUB_RESOURCES = 6; 63 public final static int MANAGEABLE_RESOURCES = 7; 64 65 public static TreeNode createTreeNode (Object [] content) throws Exception 66 { 67 if (content.length != 7 && content.length != 8) 68 throw new Exception ("Bad number of parameters"); 69 70 71 String name = (String )content[NAME]; 72 String description = (String )content[DESCRIPTION]; 73 String iconUrl = (String )content[ICON_URL]; 74 String defaultUrl = (String )content[DEFAULT_URL]; 75 76 TreeAction action = new HttpLinkTreeAction (defaultUrl); 77 78 TreeNodeMenuEntry[] menuEntries = createTreeMenus ((Object [])content[MENU_ENTRIES]); 81 82 TreeNode[] subNodes = null; 85 Object [] genericSubNodes = (Object [])content[SUB_NODES]; 86 if (genericSubNodes != null && genericSubNodes.length > 0) 87 { 88 subNodes = new TreeNode[genericSubNodes.length]; 89 for (int i=0; i< genericSubNodes.length; i++) 90 { 91 subNodes[i] = createTreeNode ( (Object [])genericSubNodes[i] ); 92 } 93 } 94 else 95 { 96 subNodes = new TreeNode[0]; 97 } 98 99 ResourceTreeNode[] subResNodes = null; 102 Object [] genericSubResNodes = (Object [])content[SUB_RESOURCES]; 103 if (genericSubResNodes != null && genericSubResNodes.length > 0) 104 { 105 subResNodes = new ResourceTreeNode[genericSubResNodes.length]; 106 for (int i=0; i< genericSubResNodes.length; i++) 107 { 108 subResNodes[i] = (ResourceTreeNode)createTreeNode ( (Object [])genericSubResNodes[i] ); 109 } 110 } 111 else 112 { 113 subResNodes = new ResourceTreeNode[0]; 114 } 115 116 if ((content.length-1) == MANAGEABLE_RESOURCES) 117 { 118 ManageableResource res = createManageableResource (content[MANAGEABLE_RESOURCES]); 121 return new SimpleResourceTreeNode (name, description, iconUrl, action, menuEntries, subNodes, subResNodes, res); 122 123 } 124 else 125 { 126 return new SimpleTreeNode (name, description, iconUrl, action, menuEntries, subNodes, subResNodes); 129 } 130 131 } 132 133 public static ManageableResource createManageableResource (Object content) throws Exception 134 { 135 Object [] realContent = (Object [])content; 136 return new MBeanResource (new ObjectName ((String )realContent[0]), (String )realContent[1]); 137 } 138 139 protected static TreeNodeMenuEntry[] createTreeMenus (Object [] content) throws Exception 140 { 141 142 TreeNodeMenuEntry[] menuEntries = null; 143 144 if (content != null && content.length > 0) 145 { 146 menuEntries = new TreeNodeMenuEntry[content.length]; 147 int i=0; 148 while (i< content.length) 149 { 150 if (content[i] == null) 151 { 152 menuEntries[i] = new SeparatorTreeNodeMenuEntry(); 153 i++; 154 } 155 else 156 { 157 String text = (String )content[i]; 158 TreeAction action = new HttpLinkTreeAction((String )content[i+1]); 159 menuEntries[i] = new SimpleTreeNodeMenuEntryImpl ( text, action ); 160 i+=2; 161 } 162 } 163 } 164 else 165 { 166 menuEntries = new TreeNodeMenuEntry[0]; 167 } 168 return menuEntries; 169 } 170 } 171 | Popular Tags |