View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 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.mockoperation;
14  
15  import org.apache.xmlbeans.SchemaTypeSystem;
16  import org.apache.xmlbeans.XmlBeans;
17  
18  import com.eviware.soapui.impl.wsdl.WsdlInterface;
19  import com.eviware.soapui.impl.wsdl.WsdlOperation;
20  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
21  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
22  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlDocument;
23  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.AbstractXmlDocument;
24  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
25  
26  public class MockRequestXmlDocument extends AbstractXmlDocument implements XmlDocument
27  {
28  	private final WsdlMockResponse mockResponse;
29  
30  	public MockRequestXmlDocument( WsdlMockResponse response )
31  	{
32  		this.mockResponse = response;
33  	}
34  
35  	public SchemaTypeSystem getTypeSystem()
36  	{
37  		try
38  		{
39  			WsdlOperation operation = mockResponse.getMockOperation().getOperation();
40  			if( operation != null )
41  			{
42  				WsdlInterface iface = operation.getInterface();
43  				WsdlContext wsdlContext = iface.getWsdlContext();
44  				return wsdlContext.getSchemaTypeSystem();
45  			}
46  		}
47  		catch (Exception e1)
48  		{
49  			e1.printStackTrace();
50  		}
51  
52  		return XmlBeans.getBuiltinTypeSystem();
53  	}
54  
55  	public String getXml()
56  	{
57  		WsdlMockResult mockResult = mockResponse.getMockResult();
58  		return mockResult == null ? null : mockResult.getMockRequest().getRequestContent();
59  	}
60  
61  	public void setXml( String xml )
62  	{
63  		WsdlMockResult mockResult = mockResponse.getMockResult();
64  		if( mockResult != null ) 
65  		{
66  			String oldXml = getXml();
67  			mockResult.getMockRequest().setRequestContent( xml );
68  			oldXml = "";
69  			fireXmlChanged( oldXml, xml );
70  		}
71  	}
72  }