View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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.mockoperation;
14  
15  import org.apache.xmlbeans.SchemaTypeSystem;
16  import org.apache.xmlbeans.XmlBeans;
17  
18  import com.eviware.soapui.SoapUI;
19  import com.eviware.soapui.impl.wsdl.WsdlInterface;
20  import com.eviware.soapui.impl.wsdl.WsdlOperation;
21  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
22  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
23  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
24  import com.eviware.soapui.support.editor.xml.XmlDocument;
25  import com.eviware.soapui.support.editor.xml.support.AbstractXmlDocument;
26  
27  /***
28   * XmlDocument for the last request to a WsdlMockResponse
29   * 
30   * @author ole.matzura
31   */
32  
33  public class MockRequestXmlDocument extends AbstractXmlDocument implements XmlDocument
34  {
35  	private final WsdlMockResponse mockResponse;
36  
37  	public MockRequestXmlDocument( WsdlMockResponse response )
38  	{
39  		this.mockResponse = response;
40  	}
41  
42  	public SchemaTypeSystem getTypeSystem()
43  	{
44  		try
45  		{
46  			WsdlOperation operation = mockResponse.getMockOperation().getOperation();
47  			if( operation != null )
48  			{
49  				WsdlInterface iface = operation.getInterface();
50  				WsdlContext wsdlContext = iface.getWsdlContext();
51  				return wsdlContext.getSchemaTypeSystem();
52  			}
53  		}
54  		catch( Exception e1 )
55  		{
56  			SoapUI.logError( e1 );
57  		}
58  
59  		return XmlBeans.getBuiltinTypeSystem();
60  	}
61  
62  	public String getXml()
63  	{
64  		WsdlMockResult mockResult = mockResponse.getMockResult();
65  		return mockResult == null ? null : mockResult.getMockRequest().getRequestContent();
66  	}
67  
68  	public void setXml( String xml )
69  	{
70  		WsdlMockResult mockResult = mockResponse.getMockResult();
71  		if( mockResult != null )
72  		{
73  			String oldXml = getXml();
74  			mockResult.getMockRequest().setRequestContent( xml );
75  			oldXml = "";
76  			fireXmlChanged( oldXml, xml );
77  		}
78  	}
79  }