1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes; 21 22 import java.io.ByteArrayInputStream ; 23 import java.io.IOException ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.util.Set ; 26 import javax.enterprise.deploy.shared.ModuleType ; 27 import javax.management.AttributeNotFoundException ; 28 import javax.management.InstanceNotFoundException ; 29 import javax.management.MBeanException ; 30 import javax.management.MBeanServerConnection ; 31 import javax.management.MalformedObjectNameException ; 32 import javax.management.ObjectName ; 33 import javax.management.QueryExp ; 34 import javax.management.ReflectionException ; 35 import javax.xml.parsers.DocumentBuilderFactory ; 36 import javax.xml.parsers.ParserConfigurationException ; 37 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; 38 import org.openide.ErrorManager; 39 import org.openide.nodes.AbstractNode; 40 import org.openide.nodes.Children; 41 import org.openide.nodes.Node; 42 import org.openide.util.Lookup; 43 import org.openide.util.NbBundle; 44 import org.w3c.dom.Document ; 45 import org.xml.sax.SAXException ; 46 47 51 public class Util { 52 public static final String WAIT_NODE = "wait_node"; public static final String INFO_NODE = "info_node"; 55 58 public static MBeanServerConnection getRMIServer(Lookup lookup) { 59 return getRMIServer((JBDeploymentManager)lookup.lookup(JBDeploymentManager.class)); 60 } 61 62 65 public static MBeanServerConnection getRMIServer(JBDeploymentManager manager) { 66 return manager.getRMIServer(); 67 } 68 69 74 public static Node createWaitNode() { 75 AbstractNode n = new AbstractNode(Children.LEAF); 76 n.setName(NbBundle.getMessage(JBItemNode.class, "LBL_WaitNode_DisplayName")); n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); return n; 79 } 80 81 86 public static Node createInfoNode() { 87 AbstractNode n = new AbstractNode(Children.LEAF); 88 n.setName(NbBundle.getMessage(JBItemNode.class, "LBL_InfoNode_DisplayName")); n.setShortDescription(NbBundle.getMessage(JBItemNode.class, "LBL_InfoNode_ToolTip")); n.setIconBaseWithExtension("org/netbeans/core/resources/exception.gif"); return n; 92 } 93 94 99 public static boolean isRemoteManagementSupported(Lookup lookup) { 100 101 try { 102 Object server = Util.getRMIServer(lookup); 103 ObjectName searchPattern; 104 searchPattern = new ObjectName ("jboss.management.local:*"); 105 Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 106 107 if(managedObj.size() == 0) 108 return false; 109 } catch (SecurityException ex) { 110 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 111 } catch (IllegalArgumentException ex) { 112 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 113 } catch (IllegalAccessException ex) { 114 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 115 } catch (InvocationTargetException ex) { 116 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 117 } catch (NoSuchMethodException ex) { 118 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 119 } catch (MalformedObjectNameException ex) { 120 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 121 } catch (NullPointerException ex) { 122 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 123 } 124 125 return true; 126 } 127 128 133 public static boolean isObjectDeployed(Object server, ObjectName searchPattern) { 134 try { 135 Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 136 137 if(managedObj.size() > 0) 138 return true; 139 } catch (IllegalArgumentException ex) { 140 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 141 } catch (SecurityException ex) { 142 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 143 } catch (InvocationTargetException ex) { 144 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 145 } catch (IllegalAccessException ex) { 146 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 147 } catch (NoSuchMethodException ex) { 148 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 149 } 150 151 return false; 152 } 153 154 159 public static String getModuleTypeString(ModuleType mt) { 160 if(mt.equals(ModuleType.EAR)) 161 return "J2EEApplication"; 162 else if(mt.equals(ModuleType.WAR)) 163 return "WebModule"; 164 else if(mt.equals(ModuleType.EJB)) 165 return "EJBModule"; 166 167 return "undefined"; 168 } 169 170 175 public static Object getMBeanParameter(JBDeploymentManager dm, String name, String targetObject) { 176 MBeanServerConnection server = dm.refreshRMIServer(); 177 try { 178 return server.getAttribute(new ObjectName (targetObject), name); 179 } catch (InstanceNotFoundException ex) { 180 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 181 } catch (AttributeNotFoundException ex) { 182 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 183 } catch (MalformedObjectNameException ex) { 184 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 185 } catch (NullPointerException ex) { 186 } catch (IllegalArgumentException ex) { 188 } catch (ReflectionException ex) { 190 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 191 } catch (MBeanException ex) { 192 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 193 } catch (IOException ex) { 194 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 195 } 196 197 return null; 198 } 199 200 205 public static String getWebContextRoot(String dd) { 206 207 if (dd == null) { 208 return null; 209 } 210 211 Document doc = null; 212 213 try { 214 doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream (dd.getBytes())); 215 } catch (SAXException ex) { 216 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 217 return null; 218 } catch (IOException ex) { 219 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 220 return null; 221 } catch (ParserConfigurationException ex) { 222 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 223 return null; 224 } 225 226 org.w3c.dom.Node node = doc.getElementsByTagName("context-root").item(0); 227 228 return node.getTextContent(); 229 } 230 } 231 | Popular Tags |