1 19 20 package org.netbeans.modules.websvc.registry.ui; 21 22 import org.netbeans.modules.websvc.registry.model.WebServiceData; 23 import org.netbeans.modules.websvc.registry.util.Util; 24 import com.sun.xml.rpc.processor.model.java.*; 25 import java.awt.Cursor ; 26 import java.awt.Dialog ; 27 import java.awt.EventQueue ; 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.awt.event.WindowAdapter ; 31 import java.awt.event.WindowEvent ; 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.lang.reflect.Array ; 35 import java.math.BigDecimal ; 36 import java.math.BigInteger ; 37 import java.net.*; 38 import java.util.*; 39 import javax.swing.JButton ; 40 import javax.swing.JPanel ; 41 import javax.swing.SwingUtilities ; 42 import javax.swing.tree.DefaultMutableTreeNode ; 43 import javax.swing.tree.DefaultTreeModel ; 44 import javax.xml.parsers.DocumentBuilder ; 45 import javax.xml.parsers.DocumentBuilderFactory ; 46 import javax.xml.parsers.ParserConfigurationException ; 47 import org.netbeans.swing.outline.DefaultOutlineModel; 48 import org.netbeans.swing.outline.Outline; 49 import org.netbeans.swing.outline.OutlineModel; 50 import org.openide.DialogDescriptor; 51 import org.openide.DialogDisplayer; 52 import org.openide.ErrorManager; 53 import org.openide.NotifyDescriptor; 54 import org.openide.awt.StatusDisplayer; 55 import org.openide.util.HelpCtx; 56 import org.openide.util.NbBundle; 57 import org.openide.util.RequestProcessor; 58 import org.w3c.dom.*; 59 import org.xml.sax.SAXException ; 60 61 import org.openide.modules.InstalledFileLocator; 62 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 63 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 64 65 66 70 public class TestWebServiceMethodDlg extends JPanel { 71 private Dialog dialog; 72 private DialogDescriptor dlg = null; 73 private JavaMethod method; 74 81 private URLClassLoader runtimeClassLoader; 82 83 private String packageName; 84 private DefaultMutableTreeNode parameterRootNode = new DefaultMutableTreeNode (); 85 private DefaultMutableTreeNode resultRootNode = new DefaultMutableTreeNode (); 86 private WebServiceData wsData; 87 public String portName; 88 public String modifiedMethodName; 89 90 91 public TestWebServiceMethodDlg(WebServiceData inWSData, JavaMethod inMethod, String inPortName) { 92 this.setJavaMethod(inMethod); 93 wsData = inWSData; 94 packageName = inWSData.getPackageName(); 95 portName = inPortName; 96 modifiedMethodName = Util.getProperPortName(inPortName).toLowerCase() + Util.upperCaseFirstChar(inMethod.getName()); 97 98 initComponents(); 99 myInitComponents(); 100 101 this.lblTitle.setText(NbBundle.getMessage(this.getClass(), "TEST_WEBSVC_LABEL") + " " + modifiedMethodName); 102 } 103 104 105 112 private URLClassLoader getRuntimeClassLoader() { 113 if(null == runtimeClassLoader) { 114 117 118 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 119 DocumentBuilder builder = null; 120 121 try { 122 builder = factory.newDocumentBuilder(); 123 124 } catch(ParserConfigurationException pe) { 125 ErrorManager.getDefault().notify(pe); 126 ErrorManager.getDefault().log("ParserConfigurationException=" + pe); 127 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS")); 128 return null; 129 } 130 131 Document document = null; 132 try { 133 File runtimeJarsFile = InstalledFileLocator.getDefault().locate( 134 "config" + File.separator + "WebServices" + File.separator + 135 "websvc_runtimejars.xml", null, false); 136 document = builder.parse(runtimeJarsFile); 137 } catch(SAXException se) { 138 ErrorManager.getDefault().notify(se); 139 ErrorManager.getDefault().log("SAXException=" + se); 140 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS")); 141 return null; 142 } catch(IOException ioe) { 143 ErrorManager.getDefault().notify(ioe); 144 ErrorManager.getDefault().log("IOException=" + ioe); 145 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS")); 146 return null; 147 } 148 149 NodeList list = document.getElementsByTagName("Jar"); 150 151 ArrayList urlList = new ArrayList(); 152 155 try { 156 161 urlList.add(new URL("file:" + this.getWebServiceData().getProxyJarFileName())); 162 } catch(MalformedURLException mfu) { 163 ErrorManager.getDefault().notify(mfu); 164 ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + mfu); 165 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS")); 167 return null; 168 } 169 170 String serverInstanceIDs[] = Deployment.getDefault().getServerInstanceIDs (); 172 J2eePlatform platform = null; 173 for (int i = 0; i < serverInstanceIDs.length; i++) { 174 J2eePlatform p = Deployment.getDefault().getJ2eePlatform (serverInstanceIDs [i]); 175 if (p != null && p.isToolSupported ("wscompile")) { 176 platform = p; 177 break; 178 } 179 } 180 File appserverRoot = platform == null ? null : platform.getPlatformRoots () [0]; 181 String asRootPath = (appserverRoot != null) ? appserverRoot.getAbsolutePath() : ""; 182 asRootPath = asRootPath.replace('\\', '/'); 183 184 Node currentNode = null; 185 for (int ii=0; ii < list.getLength(); ii++) { 186 currentNode = list.item(ii); 187 String name =currentNode.getNodeName(); 188 String localName =currentNode.getLocalName(); 189 String value = currentNode.getNodeValue(); 190 NamedNodeMap nodeMap = currentNode.getAttributes(); 191 Node fileNode = nodeMap.getNamedItem("file"); 192 String jarString = ""; 193 try { 194 jarString = fileNode.getNodeValue(); 195 } catch(DOMException de) { 196 ErrorManager.getDefault().notify(de); 197 ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + de); 198 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS")); 200 return null; 201 } 202 203 if (jarString.indexOf("\\{appserv\\.home\\}") > -1) { 204 jarString = jarString.replaceAll("\\{appserv\\.home\\}", asRootPath); 205 } else { 206 File f = InstalledFileLocator.getDefault().locate(jarString, null, false); 207 if (f != null) { 208 jarString = f.getPath(); 209 } 210 } 211 212 217 if(!jarString.startsWith("file:")) { 218 if(jarString.substring(1,1).equals("/")) { 219 jarString = "file:/" + jarString; 220 } else { 221 jarString = "file:///" + jarString; 222 } 223 } 224 225 URL newURL = null; 226 try { 227 newURL = new URL(jarString); 228 } catch(MalformedURLException mfu) { 229 ErrorManager.getDefault().notify(mfu); 230 ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + mfu); 231 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS")); 233 return null; 234 235 } 236 urlList.add(newURL); 237 238 } 239 240 URL [] urls = (URL [])urlList.toArray(new URL[0]); 241 245 246 250 runtimeClassLoader = new URLClassLoader(urls, null); 251 252 } 253 254 return runtimeClassLoader; 255 } 256 262 public String getPackageName() { 263 return packageName; 264 } 265 266 public WebServiceData getWebServiceData() { 267 return this.wsData; 268 } 269 270 public void displayDialog(){ 271 272 dlg = new DialogDescriptor(this, NbBundle.getMessage(this.getClass(), "TEST_WEB_SERVICE_METHOD"), 273 false, new Object []{NotifyDescriptor.CLOSED_OPTION}, DialogDescriptor.CLOSED_OPTION, 274 DialogDescriptor.DEFAULT_ALIGN, this.getHelpCtx(), null); 275 dialog = DialogDisplayer.getDefault().createDialog(dlg); 276 279 280 final JPanel thisPanel = this; 281 final Dialog thisDialog = dialog; 282 dialog.addWindowListener( new WindowAdapter (){ 283 public void windowOpened( WindowEvent e ){ 284 SwingUtilities.invokeLater( 285 new Runnable () { 286 public void run() { 287 btnSubmit.requestFocus(); 288 thisPanel.getRootPane().setDefaultButton(btnSubmit); 289 } 290 }); 291 } 292 293 public void windowClosing(WindowEvent e) { 294 thisDialog.dispose(); 295 } 296 }); 297 298 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_TEST_WEB_SERVICE_DLG")); 299 dialog.show(); 300 } 301 public HelpCtx getHelpCtx() { 302 return new HelpCtx(TestWebServiceMethodDlg.class); 303 } 304 305 310 private void initComponents() { 311 jSplitPane1 = new javax.swing.JSplitPane (); 312 pnlParameter = new javax.swing.JPanel (); 313 btnPanel = new javax.swing.JPanel (); 314 btnSubmit = new javax.swing.JButton (); 315 scrollPaneParameter = new javax.swing.JScrollPane (); 316 pnlLabel = new javax.swing.JPanel (); 317 lblTitle = new javax.swing.JLabel (); 318 jLabel1 = new javax.swing.JLabel (); 319 pnlResults = new javax.swing.JPanel (); 320 jPanel4 = new javax.swing.JPanel (); 321 jLabel2 = new javax.swing.JLabel (); 322 scrollPaneResults = new javax.swing.JScrollPane (); 323 324 setLayout(new java.awt.BorderLayout ()); 325 326 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5))); 327 jSplitPane1.setDividerLocation(400); 328 jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); 329 jSplitPane1.setResizeWeight(1.0); 330 pnlParameter.setLayout(new java.awt.BorderLayout ()); 331 332 org.openide.awt.Mnemonics.setLocalizedText(btnSubmit, NbBundle.getMessage(TestWebServiceMethodDlg.class, "BUTTON_SUBMIT")); 333 btnSubmit.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_BUTTON_SUBMIT")); 334 btnSubmit.addActionListener(new java.awt.event.ActionListener () { 335 public void actionPerformed(java.awt.event.ActionEvent evt) { 336 btnSubmitActionPerformed(evt); 337 } 338 }); 339 340 btnPanel.add(btnSubmit); 341 342 pnlParameter.add(btnPanel, java.awt.BorderLayout.SOUTH); 343 344 pnlParameter.add(scrollPaneParameter, java.awt.BorderLayout.CENTER); 345 346 pnlLabel.setLayout(new java.awt.GridLayout (2, 0, 10, 10)); 347 348 pnlLabel.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5))); 349 lblTitle.setFont(new java.awt.Font (getFont().getName(), getFont().getStyle(), getFont().getSize()+2)); 350 lblTitle.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/registry/ui/Bundle").getString("TEST_WEBSVC_LABEL")); 351 lblTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 352 pnlLabel.add(lblTitle); 353 354 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(TestWebServiceMethodDlg.class, "PARAMETERS")); 355 jLabel1.setToolTipText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "TEST_WEBSVC_INSTRUCTIONS")); 356 jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 357 pnlLabel.add(jLabel1); 358 359 pnlParameter.add(pnlLabel, java.awt.BorderLayout.NORTH); 360 361 jSplitPane1.setTopComponent(pnlParameter); 362 363 pnlResults.setLayout(new java.awt.BorderLayout ()); 364 365 jPanel4.setLayout(new java.awt.BorderLayout ()); 366 367 jPanel4.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5))); 368 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,NbBundle.getMessage(TestWebServiceMethodDlg.class,"RESULTS")); 369 jLabel2.setToolTipText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_RESULT_TABLE")); 370 jPanel4.add(jLabel2, java.awt.BorderLayout.NORTH); 371 372 jPanel4.add(scrollPaneResults, java.awt.BorderLayout.CENTER); 373 374 pnlResults.add(jPanel4, java.awt.BorderLayout.CENTER); 375 376 jSplitPane1.setBottomComponent(pnlResults); 377 378 add(jSplitPane1, java.awt.BorderLayout.CENTER); 379 380 } 381 382 private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) { 383 RequestProcessor.getDefault().post(new Runnable () { 384 public void run(){ 385 Cursor normalCursor = dialog.getCursor(); 386 dialog.setCursor(new Cursor (Cursor.WAIT_CURSOR)); 387 invokeMethod(); 388 dialog.setCursor(normalCursor); 389 } 390 }); 391 392 } 393 394 395 private void invokeMethod() { 396 404 405 409 410 413 LinkedList paramList = new LinkedList(); 414 for(int ii=0; null != this.getParamterRootNode() && ii < this.getParamterRootNode().getChildCount(); ii++) { 415 DefaultMutableTreeNode childNode = (DefaultMutableTreeNode ) this.getParamterRootNode().getChildAt(ii); 416 TypeNodeData nodeData = (TypeNodeData)childNode.getUserObject(); 417 Object parameterValue = nodeData.getParameterValue(); 418 if(parameterValue instanceof ArrayList) { 419 try { 420 parameterValue = ReflectionHelper.getTypedParameterArray((ArrayList)parameterValue, nodeData.getParameterType(), 421 this.getRuntimeClassLoader(), getPackageName()); 422 } catch(WebServiceReflectionException wsre) { 423 Throwable cause = wsre.getCause(); 424 ErrorManager.getDefault().notify(cause); 425 ErrorManager.getDefault().log(this.getClass().getName() + 426 ": Error trying to create a typed parameter array for type:" + nodeData.getParameterType() + 427 "WebServiceReflectionException=" + cause); 428 return; 429 } 430 } 431 paramList.add(parameterValue); 432 } 433 434 437 String clientClassName = wsData.getPackageName() + "." + wsData.getDisplayName() + "Client"; 438 439 442 Object returnObject=null; 443 try { 444 returnObject = ReflectionHelper.callMethodWithParams(clientClassName, paramList, this.getJavaMethod(), 445 this.getRuntimeClassLoader(),modifiedMethodName); 446 } catch(WebServiceReflectionException wsre) { 447 MethodExceptionDialog errorDialog = new MethodExceptionDialog(wsre); 448 errorDialog.show(); 449 return; 450 } 451 452 showResults(returnObject); 453 454 } 455 456 private void showResults(Object inResultObject) { 457 460 461 outline = loadResultTreeTable(this.getJavaMethod(), inResultObject); 462 scrollPaneResults.setViewportView(outline); 463 jLabel2.setLabelFor(outline); 464 } 465 466 467 private void myInitComponents() { 468 469 472 if(null == this.getJavaMethod()) { 473 return; 474 } 475 476 outline = loadParameterTreeTable(this.getJavaMethod()); 477 478 479 480 483 484 scrollPaneParameter.setViewportView(outline); 485 jLabel1.setLabelFor(outline); 486 487 } 488 private DefaultMutableTreeNode getParamterRootNode() { 489 return parameterRootNode; 490 } 491 492 private void setParameterRootNode(DefaultMutableTreeNode inNode) { 493 parameterRootNode = inNode; 494 } 495 private DefaultMutableTreeNode getResultRootNode() { 496 return resultRootNode; 497 } 498 499 private void setResultRootNode(DefaultMutableTreeNode inNode) { 500 resultRootNode = inNode; 501 } 502 503 private JavaMethod getJavaMethod() { 504 return method; 505 } 506 507 private void setJavaMethod(JavaMethod inMethod) { 508 method = inMethod; 509 } 510 511 private Outline loadResultTreeTable(JavaMethod inMethod, Object inResultObject) { 512 if(null == inMethod) { 513 return null; 514 } 515 JavaType currentType = inMethod.getReturnType(); 516 517 518 ResultNodeData data = new ResultNodeData(currentType,inResultObject); 519 DefaultMutableTreeNode node = new DefaultMutableTreeNode (data); 520 521 if(currentType instanceof JavaArrayType) { 522 525 526 addResultArrayInstances(node); 527 } else if(currentType instanceof JavaStructureType) { 528 529 533 traverseResultType(node); 534 } 535 539 this.setResultRootNode(new DefaultMutableTreeNode ()); 540 543 this.getResultRootNode().add(node); 544 545 546 DefaultTreeModel treeModel = new DefaultTreeModel (this.getResultRootNode()); 547 ResultRowModel rowModel = new ResultRowModel(); 548 OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(treeModel,rowModel, false); 549 outlineModel.setNodeColumnName(NbBundle.getMessage(this.getClass(), "TYPE_COLUMN_NAME")); 550 Outline returnOutline = new Outline(outlineModel); 551 ResultCellEditor cellEditor = new ResultCellEditor(); 552 returnOutline.setDefaultEditor(Object .class,cellEditor); 553 returnOutline.setRootVisible(false); 554 555 returnOutline.setRenderDataProvider(new TypeDataProvider()); 556 557 returnOutline.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSN_RESULT_TABLE")); 558 560 return returnOutline; 561 } 562 563 private Outline loadParameterTreeTable(JavaMethod inMethod) { 564 if(null == inMethod) { 565 return null; 566 } 567 Iterator paramIterator = inMethod.getParameters(); 568 JavaParameter currentParameter = null; 569 570 while(paramIterator.hasNext()) { 571 574 currentParameter = (JavaParameter)paramIterator.next(); 575 JavaType currentType = currentParameter.getType(); 576 Object value = null; 577 value = getParameterDefaultValue(currentType); 578 579 TypeNodeData data = new TypeNodeData(currentType,currentParameter.getName(),value); 580 DefaultMutableTreeNode node = null; 581 582 if(currentType instanceof JavaArrayType) { 583 node = new ArrayTypeTreeNode(data); 584 587 588 JavaType elementType = ((JavaArrayType)currentType).getElementType(); 589 addParameterArrayInstances(elementType,node); 590 } else if(currentType instanceof JavaStructureType) { 591 node = new StructureTypeTreeNode(data,this.getRuntimeClassLoader(),this.getPackageName()); 592 593 597 traverseType(node); 598 } else { 599 node = new DefaultMutableTreeNode (data); 600 } 601 604 this.getParamterRootNode().add(node); 605 606 } 607 608 DefaultTreeModel treeModel = new DefaultTreeModel (this.getParamterRootNode()); 609 TypeRowModel rowModel = new TypeRowModel(this.getRuntimeClassLoader(),this.getPackageName()); 610 OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(treeModel,rowModel, false); 611 outlineModel.setNodeColumnName(NbBundle.getMessage(this.getClass(), "TYPE_COLUMN_NAME")); 612 Outline returnOutline = new Outline(outlineModel); 613 TypeCellEditor cellEditor = new TypeCellEditor(); 614 returnOutline.setDefaultEditor(Object .class,cellEditor); 615 returnOutline.setRootVisible(false); 616 returnOutline.setRenderDataProvider(new TypeDataProvider()); 617 622 returnOutline.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 624 returnOutline.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSN_PARAMETER_TABLE")); 625 returnOutline.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_PARAMETER_TABLE")); 626 627 return returnOutline; 628 } 629 630 private void traverseType(DefaultMutableTreeNode inNode) { 631 632 if(null == inNode) { 633 return; 634 } 635 636 JavaType inType = ((NodeData)inNode.getUserObject()).getNodeType(); 637 640 if(!(inType instanceof JavaStructureType)) { 641 return; 642 } 643 JavaStructureType type = (JavaStructureType)inType; 644 Iterator typeIterator = type.getMembers(); 645 while(null != typeIterator && typeIterator.hasNext()) { 646 JavaStructureMember entry = (JavaStructureMember)typeIterator.next(); 647 JavaType entryType = entry.getType(); 648 if(entryType instanceof JavaEnumerationType || entryType instanceof JavaSimpleType) { 649 653 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType)); 654 DefaultMutableTreeNode node = new DefaultMutableTreeNode (data); 655 inNode.add(node); 656 } else if(entryType instanceof JavaArrayType) { 657 661 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType)); 662 ArrayTypeTreeNode node = new ArrayTypeTreeNode(data); 663 inNode.add(node); 664 JavaType elementType = ((JavaArrayType)entryType).getElementType(); 665 addParameterArrayInstances(elementType,node); 666 } else if(entryType instanceof JavaStructureType) { 667 671 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType)); 672 StructureTypeTreeNode node = new StructureTypeTreeNode(data,this.getRuntimeClassLoader(),this.getPackageName()); 673 inNode.add(node); 674 677 traverseType(node); 678 } 679 } 680 681 } 682 683 private void traverseResultType(DefaultMutableTreeNode inParentNode) { 684 685 if(null == inParentNode) { 686 return; 687 } 688 689 ResultNodeData parentData = (ResultNodeData)inParentNode.getUserObject(); 690 JavaType parentType = parentData.getResultType(); 691 Object parentValue = parentData.getResultValue(); 692 695 if(!(parentType instanceof JavaStructureType)) { 696 return; 697 } 698 JavaStructureType type = (JavaStructureType)parentType; 699 Iterator typeIterator = type.getMembers(); 700 while(null != typeIterator && typeIterator.hasNext()) { 701 JavaStructureMember member = (JavaStructureMember)typeIterator.next(); 702 JavaType memberType = member.getType(); 703 String memberName = member.getName(); 704 Object subTypeValue = null; 705 710 if(null != parentValue) { 711 712 try { 713 subTypeValue = ReflectionHelper.getStructureValue(parentData,member,this.getRuntimeClassLoader(), 714 this.getPackageName()); 715 } catch(WebServiceReflectionException wsfe) { 716 717 } 718 } 719 ResultNodeData data = new ResultNodeData(memberType,subTypeValue); 720 DefaultMutableTreeNode node = new DefaultMutableTreeNode (data); 721 inParentNode.add(node); 722 if(memberType instanceof JavaArrayType) { 723 addResultArrayInstances(node); 724 } else if(memberType instanceof JavaStructureType) { 725 728 traverseResultType(node); 729 } 730 } 731 732 } 733 private void addParameterArrayInstances(JavaType inType, DefaultMutableTreeNode parentNode) { 734 738 DefaultMutableTreeNode childNode = null; 739 TypeNodeData data = null; 740 for(int ii=0; ii < 9; ii++) { 741 data = new TypeNodeData(inType,"[" + ii + "]",getParameterDefaultValue(inType)); 742 childNode = new DefaultMutableTreeNode (data); 743 parentNode.add(childNode); 744 745 748 if(inType instanceof JavaStructureType) { 749 this.traverseType(childNode); 750 } 751 752 } 753 754 } 755 private void addResultArrayInstances(DefaultMutableTreeNode parentNode) { 756 762 DefaultMutableTreeNode childNode = null; 763 764 ResultNodeData parentData = (ResultNodeData)parentNode.getUserObject(); 765 JavaType parentType = parentData.getResultType(); 766 if(!(parentType instanceof JavaArrayType)) { 767 return; 768 } 769 772 JavaType valueType = ((JavaArrayType)parentType).getElementType(); 773 Object resultValue = parentData.getResultValue(); 774 if(null == resultValue) return; 775 ResultNodeData childData = null; 779 int length = Array.getLength(resultValue); 780 for(int i = 0; i < length; i++) { 781 childData = new ResultNodeData(valueType, Array.get(resultValue, i)); 782 childNode = new DefaultMutableTreeNode (childData); 783 parentNode.add(childNode); 784 788 if(valueType instanceof JavaStructureType) { 789 this.traverseResultType(childNode); 790 } 791 } 792 } 793 794 798 private Object getParameterDefaultValue(JavaType type) { 799 800 Object value = null; 801 802 if(null == type) return null; 803 804 808 if(type instanceof JavaStructureType) { 809 Object returnValue = null; 810 try { 811 returnValue = ReflectionHelper.makeStructureType((JavaStructureType)type, 812 this.getRuntimeClassLoader(),this.getPackageName()); 813 } catch(WebServiceReflectionException wsre) { 814 Throwable cause = wsre.getCause(); 815 ErrorManager.getDefault().notify(cause); 816 ErrorManager.getDefault().log(this.getClass().getName() + 817 ": Error trying to do Class.forName on: " + packageName + "." + type.getFormalName() + "WebServiceReflectionException=" + cause); 818 return null; 819 } 820 821 return returnValue; 822 } 823 826 else if(type instanceof JavaEnumerationType) { 827 Object returnValue = null; 828 try { 829 returnValue = ReflectionHelper.makeEnumerationType((JavaEnumerationType)type, 830 this.getRuntimeClassLoader(),this.getPackageName()); 831 } catch(WebServiceReflectionException wsre) { 832 Throwable cause = wsre.getCause(); 833 ErrorManager.getDefault().notify(cause); 834 ErrorManager.getDefault().log(this.getClass().getName() + 835 ": Error trying to create an Enumeration Type: " + packageName + "." + type.getFormalName() + "ClassNWebServiceReflectionExceptionotFoundException=" + cause); 836 return null; 837 } 838 839 return returnValue; 840 841 842 } 843 846 else if(type instanceof JavaArrayType) { 847 return new ArrayList(); 848 } 849 852 else { 853 854 855 String currentType = type.getRealName(); 856 857 858 if(currentType.equals(int.class.getName()) || 859 currentType.equals(Integer .class.getName())) { 860 value = new Integer (0); 861 } else if(currentType.equals(byte.class.getName()) || 862 currentType.equals(Byte .class.getName())) { 863 value = new Byte ("0"); 864 } else if("byte[]".equals(currentType)) { 865 value = new Byte []{}; 866 } else if(currentType.equals(boolean.class.getName()) || 867 currentType.equals(Boolean .class.getName())) { 868 value = new Boolean (false); 869 } else if(currentType.equals(float.class.getName()) || 870 currentType.equals(Float .class.getName())) { 871 value = new Float (0); 872 } else if(currentType.equals(double.class.getName()) || 873 currentType.equals(Double .class.getName())) { 874 value = new Double (0); 875 } else if(currentType.equals(long.class.getName()) || 876 currentType.equals(Long .class.getName())) { 877 value = new Long (0L); 878 } else if(currentType.equals(short.class.getName()) || 879 currentType.equals(Short .class.getName())) { 880 value = new Short ("0"); 881 } else if(currentType.equals(String .class.getName())) { 882 value = ""; 883 } else if(currentType.equals(BigDecimal .class.getName())) { 884 value = new BigDecimal ("0"); 885 } else if(currentType.equals(BigInteger .class.getName())) { 886 value = new BigInteger ("0"); 887 } else if(currentType.equals(URI.class.getName())) { 888 try { 889 value = new URI("http://java.sun.com"); 890 } catch(URISyntaxException uri) { 891 892 } 893 } else if(currentType.equals(Calendar.class.getName())) { 894 value = Calendar.getInstance(); 895 } else if(currentType.equalsIgnoreCase(Date.class.getName())) { 896 value = new Date(); 897 } 898 899 return value; 900 } 901 } 902 903 private javax.swing.JPanel btnPanel; 905 private javax.swing.JButton btnSubmit; 906 private javax.swing.JLabel jLabel1; 907 private javax.swing.JLabel jLabel2; 908 private javax.swing.JPanel jPanel4; 909 private javax.swing.JSplitPane jSplitPane1; 910 private javax.swing.JLabel lblTitle; 911 private javax.swing.JPanel pnlLabel; 912 private javax.swing.JPanel pnlParameter; 913 private javax.swing.JPanel pnlResults; 914 private javax.swing.JScrollPane scrollPaneParameter; 915 private javax.swing.JScrollPane scrollPaneResults; 916 private Outline outline; 919 } 920 | Popular Tags |