View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  SoapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.panels.request.actions;
14  
15  import java.awt.Toolkit;
16  import java.awt.event.ActionEvent;
17  import java.awt.event.KeyEvent;
18  
19  import javax.swing.AbstractAction;
20  import javax.swing.Action;
21  import javax.swing.DefaultListModel;
22  import javax.swing.JComponent;
23  import javax.swing.JOptionPane;
24  import javax.swing.JSplitPane;
25  import javax.swing.KeyStroke;
26  
27  import com.eviware.soapui.SoapUI;
28  import com.eviware.soapui.impl.wsdl.WsdlInterface;
29  import com.eviware.soapui.impl.wsdl.WsdlOperation;
30  import com.eviware.soapui.impl.wsdl.WsdlRequest;
31  import com.eviware.soapui.impl.wsdl.support.WsdlValidator;
32  import com.eviware.soapui.impl.wsdl.teststeps.assertions.AssertionError;
33  import com.eviware.soapui.support.JXmlTextArea;
34  
35  /***
36   * Validates the request XML of a WsdlRequest
37   * 
38   * @author Ole.Matzura
39   */
40  
41  public class ValidateRequestXmlAction extends AbstractAction
42  {
43  	private final JComponent container;
44  	private final DefaultListModel errorListModel;
45  	private final JSplitPane splitPane;
46  	private final JXmlTextArea textArea;
47  	private final WsdlRequest request;
48  
49  	public ValidateRequestXmlAction(WsdlRequest request, JComponent container, DefaultListModel errorListModel, JSplitPane splitPane, JXmlTextArea textArea )
50  	{
51  		super( "Validate" );
52  		putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_V, KeyEvent.ALT_MASK ));
53  		
54  		this.request = request;
55  		this.container = container;
56  		this.errorListModel = errorListModel;
57  		this.splitPane = splitPane;
58  		this.textArea = textArea;
59  	}
60  
61  	public void actionPerformed(ActionEvent e)
62  	{
63  	   WsdlOperation operation = (WsdlOperation) request.getOperation();
64  		WsdlValidator validator = new WsdlValidator( ((WsdlInterface)operation.getInterface()).getWsdlContext() );
65  	   
66  		AssertionError[] errors = validator.assertRequest( textArea.getText(), operation.getBindingOperationName() );
67  		
68  		errorListModel.clear();
69  	   if( errors == null || errors.length == 0 )
70  	   {
71  	   	splitPane.setDividerLocation( 1.0 );
72  	   	JOptionPane.showMessageDialog( SoapUI.getInstance().getFrame(), "XML is valid", "Validation",
73  	   			JOptionPane.INFORMATION_MESSAGE );
74  		   container.setVisible( false );
75  	   }
76  	   else
77  	   {
78  	   	Toolkit.getDefaultToolkit().beep();
79  		   for( int c = 0; c < errors.length; c++ )
80  		   {
81  		   	errorListModel.addElement( errors[c] );
82  		   }
83  		   container.setVisible( true );
84  		   splitPane.setDividerLocation( 0.8 );
85  	   }
86  	}
87  }