1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.avk; 26 27 import java.io.File ; 28 import java.net.URL ; 29 import java.awt.Dialog ; 30 import java.util.ResourceBundle ; 31 import org.netbeans.api.project.FileOwnerQuery; 32 import org.netbeans.api.project.Project; 33 import org.netbeans.modules.j2ee.sun.ide.avk.actions.StartInstrumentation; 34 import org.openide.nodes.Node; 35 36 import org.openide.util.HelpCtx; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.NotifyDescriptor; 40 import org.openide.util.Lookup; 41 import org.openide.util.RequestProcessor; 42 import org.openide.filesystems.FileObject; 43 import org.openide.awt.HtmlBrowser.URLDisplayer; 44 45 import org.netbeans.modules.j2ee.dd.api.application.Web; 46 import org.netbeans.modules.j2ee.dd.api.application.Module; 47 import org.netbeans.modules.j2ee.dd.api.application.Application; 48 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 49 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeAppProvider; 50 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 51 52 import javax.enterprise.deploy.spi.DeploymentManager ; 53 54 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 55 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties; 56 57 61 public class AddAVKSupport { 62 static ResourceBundle bundle = ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.avk.Bundle"); boolean instrumentServer = false; 64 boolean verify = false; 65 66 private RequestProcessor processor = new RequestProcessor("instrument"); 68 public static final String APPSERVER_VERSION_UNKNOWN = "unknown"; public static final String APPSERVER_VERSION_9 = "9.0"; public static final String APPSERVER_VERSION_8_x = "8.x"; 72 73 public AddAVKSupport(){ 74 } 75 76 public boolean createAVKSupport(final DeploymentManager dm, final J2eeModuleProvider modProvider) { 77 AddAVKFrame frame = new AddAVKFrame(); 78 DialogDescriptor dd = new DialogDescriptor(frame, bundle.getString("LBL_ChooseVerification"), true, null); 79 Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); 80 dialog.setLocation(320, 325); 81 dialog.pack(); 82 dialog.setVisible(true); 83 if (dd.getValue() == DialogDescriptor.OK_OPTION) { 84 instrumentServer = frame.instrumentServer(); 85 verify = frame.verify(); 86 if(instrumentServer) { 87 instrument(dm, modProvider); 88 return false; 89 } else 90 return verify; 91 }else{ 92 instrumentServer = false; 93 verify = false; 94 return false; 95 } 96 } 97 98 public boolean instrumentServer(){ 99 return instrumentServer; 100 } 101 102 public boolean verify(){ 103 return verify; 104 } 105 106 public boolean instrumentAndVerify(){ 107 return (verify && instrumentServer); 108 } 109 110 static class AddAVKFrame extends javax.swing.JPanel { 111 112 public AddAVKFrame(){ 113 initComponents(); 114 staticRadioButton.setSelected(true); 115 HelpCtx.setHelpIDString(this, "AVKVerifyDialog"); } 117 122 private void initComponents() { 124 java.awt.GridBagConstraints gridBagConstraints; 125 126 jPanel1 = new javax.swing.JPanel (); 127 jTextPane1 = new javax.swing.JTextPane (); 128 jPanel2 = new javax.swing.JPanel (); 129 staticRadioButton = new javax.swing.JRadioButton (); 130 dynamicRadioButton = new javax.swing.JRadioButton (); 131 staticTextArea = new javax.swing.JTextArea (); 132 dynamicTextArea = new javax.swing.JTextArea (); 133 134 setLayout(new java.awt.GridBagLayout ()); 135 136 setEnabled(false); 137 setFocusable(false); 138 setMaximumSize(new java.awt.Dimension (500, 200)); 139 setMinimumSize(new java.awt.Dimension (500, 200)); 140 setPreferredSize(new java.awt.Dimension (500, 200)); 141 setRequestFocusEnabled(false); 142 setVerifyInputWhenFocusTarget(false); 143 getAccessibleContext().setAccessibleName(bundle.getString("LBL_ChooseVerification")); 144 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("LBL_ChooseVerification")); 145 jPanel1.setLayout(new java.awt.GridBagLayout ()); 146 147 jTextPane1.setEditable(false); 148 jTextPane1.setText(bundle.getString("MSG_ChooseVerification")); 149 jTextPane1.setFocusCycleRoot(false); 150 jTextPane1.setFocusable(false); 151 jTextPane1.setOpaque(false); 152 jTextPane1.setRequestFocusEnabled(false); 153 jTextPane1.setVerifyInputWhenFocusTarget(false); 154 gridBagConstraints = new java.awt.GridBagConstraints (); 155 gridBagConstraints.gridx = 0; 156 gridBagConstraints.gridy = 0; 157 gridBagConstraints.gridwidth = 15; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 160 gridBagConstraints.weightx = 1.0; 161 gridBagConstraints.weighty = 1.0; 162 jPanel1.add(jTextPane1, gridBagConstraints); 163 jTextPane1.getAccessibleContext().setAccessibleName(bundle.getString("LBL_ChooseVerification")); 164 jTextPane1.getAccessibleContext().setAccessibleDescription(bundle.getString("MSG_ChooseVerification")); 165 166 gridBagConstraints = new java.awt.GridBagConstraints (); 167 gridBagConstraints.gridx = 0; 168 gridBagConstraints.gridy = 0; 169 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 170 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 171 gridBagConstraints.weightx = 1.0; 172 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 173 add(jPanel1, gridBagConstraints); 174 175 jPanel2.setLayout(new java.awt.GridBagLayout ()); 176 177 staticRadioButton.setText(bundle.getString("LBL_StaticVerification")); 178 staticRadioButton.addItemListener(new java.awt.event.ItemListener () { 179 public void itemStateChanged(java.awt.event.ItemEvent evt) { 180 staticRadioButtonItemStateChanged(evt); 181 } 182 }); 183 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.gridy = 0; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 188 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 189 gridBagConstraints.weightx = 1.0; 190 gridBagConstraints.weighty = 1.0; 191 jPanel2.add(staticRadioButton, gridBagConstraints); 192 staticRadioButton.getAccessibleContext().setAccessibleName(bundle.getString("LBL_StaticVerification")); 193 staticRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("LBL_StaticVerification")); 194 195 dynamicRadioButton.setText(bundle.getString("LBL_DynamicVerification")); 196 dynamicRadioButton.addItemListener(new java.awt.event.ItemListener () { 197 public void itemStateChanged(java.awt.event.ItemEvent evt) { 198 dynamicRadioButtonItemStateChanged(evt); 199 } 200 }); 201 202 gridBagConstraints = new java.awt.GridBagConstraints (); 203 gridBagConstraints.gridx = 0; 204 gridBagConstraints.gridy = 2; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 206 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 207 gridBagConstraints.weightx = 1.0; 208 gridBagConstraints.weighty = 1.0; 209 jPanel2.add(dynamicRadioButton, gridBagConstraints); 210 dynamicRadioButton.getAccessibleContext().setAccessibleName(bundle.getString("LBL_DynamicVerification")); 211 dynamicRadioButton.getAccessibleContext().setAccessibleDescription(bundle.getString("LBL_DynamicVerification")); 212 213 staticTextArea.setFont(new java.awt.Font ("Microsoft Sans Serif", 0, 11)); 214 staticTextArea.setLineWrap(true); 215 staticTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("Msg_InfoVerifier")); 216 staticTextArea.setWrapStyleWord(true); 217 staticTextArea.setOpaque(false); 218 gridBagConstraints = new java.awt.GridBagConstraints (); 219 gridBagConstraints.gridx = 0; 220 gridBagConstraints.gridy = 1; 221 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 222 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 223 gridBagConstraints.weightx = 1.0; 224 gridBagConstraints.weighty = 1.0; 225 gridBagConstraints.insets = new java.awt.Insets (0, 19, 0, 0); 226 jPanel2.add(staticTextArea, gridBagConstraints); 227 staticTextArea.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("LBL_StaticVerification")); 228 staticTextArea.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("Msg_InfoVerifier")); 229 230 dynamicTextArea.setFont(new java.awt.Font ("Microsoft Sans Serif", 0, 11)); 231 dynamicTextArea.setLineWrap(true); 232 dynamicTextArea.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("Msg_InfoAVK")); 233 dynamicTextArea.setWrapStyleWord(true); 234 dynamicTextArea.setOpaque(false); 235 gridBagConstraints = new java.awt.GridBagConstraints (); 236 gridBagConstraints.gridx = 0; 237 gridBagConstraints.gridy = 3; 238 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 239 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 240 gridBagConstraints.weightx = 1.0; 241 gridBagConstraints.weighty = 1.0; 242 gridBagConstraints.insets = new java.awt.Insets (0, 19, 0, 0); 243 jPanel2.add(dynamicTextArea, gridBagConstraints); 244 dynamicTextArea.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("LBL_DynamicVerification")); 245 dynamicTextArea.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/avk/Bundle").getString("Msg_InfoAVK")); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 0; 249 gridBagConstraints.gridy = 1; 250 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 251 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 252 gridBagConstraints.weightx = 1.0; 253 gridBagConstraints.weighty = 1.0; 254 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 12); 255 add(jPanel2, gridBagConstraints); 256 257 } 258 260 private void dynamicRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) { if(dynamicRadioButton.isSelected()){ 262 staticRadioButton.setSelected(false); 263 } 264 } 266 private void staticRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) { if(staticRadioButton.isSelected()){ 268 dynamicRadioButton.setSelected(false); 269 } 270 } 272 public boolean instrumentServer() { 273 return dynamicRadioButton.isSelected(); 274 } 275 276 public boolean verify() { 277 return staticRadioButton.isSelected(); 278 } 279 280 private javax.swing.JRadioButton dynamicRadioButton; 282 private javax.swing.JTextArea dynamicTextArea; 283 private javax.swing.JPanel jPanel1; 284 private javax.swing.JPanel jPanel2; 285 private javax.swing.JTextPane jTextPane1; 286 private javax.swing.JRadioButton staticRadioButton; 287 private javax.swing.JTextArea staticTextArea; 288 } 290 291 private void instrument(final DeploymentManager dm, final J2eeModuleProvider modProvider){ 292 processor.post(new Runnable () { 293 public void run() { 294 SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface)dm; 295 String appServerVersion = getAppServerVersion(sdm.getPlatformRoot()); 296 if(APPSERVER_VERSION_9.equals(appServerVersion)) { 297 StartInstrumentation.getInstance().start(getProject(modProvider)); 298 } else { 299 300 AVKSupport avkSupport = new AVKSupport((SunDeploymentManagerInterface)dm); 301 avkSupport.setAVK(true); 302 launchApp(dm, getContextRoot(modProvider)); 303 } 304 } 305 }); 306 } 307 308 private String getContextRoot(J2eeModuleProvider modProvider){ 309 String url = null; 310 if(modProvider != null){ 311 if(modProvider instanceof J2eeAppProvider){ 312 Application appXml = (Application)modProvider.getJ2eeModule().getDeploymentDescriptor(J2eeModule.APP_XML); 314 Module[] mods = appXml.getModule(); 315 for(int i=0; i<mods.length; i++){ 316 Web webMod = mods[i].getWeb(); 317 if(webMod != null){ 318 url = webMod.getContextRoot(); 319 break; 320 } 321 } 322 }else{ 323 url = modProvider.getConfigSupport().getWebContextRoot(); 324 } 325 } 326 return url; 327 } 328 329 private void launchApp(DeploymentManager dm, String contextRoot){ 330 try{ 331 if(contextRoot != null){ 332 SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface)dm; 333 DeploymentManagerProperties dmProps = new DeploymentManagerProperties(dm); 334 String start = "http://" + sdm.getHost() + ":" + dmProps.getHttpPortNumber(); if (contextRoot.startsWith("/")) contextRoot = start + contextRoot; 337 else 338 contextRoot = start + "/" + contextRoot; 340 URLDisplayer.getDefault().showURL(new URL (contextRoot)); 341 } 342 }catch(Exception ex){} 343 } 344 345 348 public String getAppServerVersion(File asInstallRoot) { 349 String version = APPSERVER_VERSION_UNKNOWN; 351 if(asInstallRoot != null && asInstallRoot.exists()) { 352 File sunDomain11Dtd = new File (asInstallRoot, "lib/dtds/sun-domain_1_1.dtd"); File as9 = new File ((asInstallRoot)+"/lib/dtds/sun-web-app_2_5-0.dtd"); 355 if(as9.exists()){ 356 version = APPSERVER_VERSION_9; 357 358 } else if(sunDomain11Dtd.exists()) { 359 version = APPSERVER_VERSION_8_x; 360 } 361 } 362 return version; 363 } 364 365 private Project getProject(J2eeModuleProvider modProvider) { 366 Project project = null; 367 try { 368 FileObject archive = modProvider.getJ2eeModule().getArchive(); 369 project = FileOwnerQuery.getOwner(archive); 370 } catch(Exception ex) { 371 ex.printStackTrace(); 372 } 373 return project; 374 } 375 376 } 377 | Popular Tags |