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 java.beans.PropertyChangeEvent;
16  import java.beans.PropertyChangeListener;
17  
18  import org.apache.xmlbeans.SchemaTypeSystem;
19  import org.apache.xmlbeans.XmlBeans;
20  
21  import com.eviware.soapui.impl.wsdl.WsdlInterface;
22  import com.eviware.soapui.impl.wsdl.WsdlOperation;
23  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
24  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.AbstractXmlDocument;
25  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
26  
27  public class MockResponseXmlDocument extends AbstractXmlDocument implements PropertyChangeListener
28  {
29  	private final WsdlMockResponse mockResponse;
30  
31  	public MockResponseXmlDocument( WsdlMockResponse response )
32  	{
33  		this.mockResponse = response;
34  		
35  		mockResponse.addPropertyChangeListener( WsdlMockResponse.RESPONSECONTENT_PROPERTY, this );
36  	}
37  
38  	public SchemaTypeSystem getTypeSystem()
39  	{
40  		try
41  		{
42  			WsdlOperation operation = mockResponse.getMockOperation().getOperation();
43  			if( operation != null )
44  			{
45  				WsdlInterface iface = operation.getInterface();
46  				WsdlContext wsdlContext = iface.getWsdlContext();
47  				return wsdlContext.getSchemaTypeSystem();
48  			}
49  		}
50  		catch (Exception e1)
51  		{
52  			e1.printStackTrace();
53  		}
54  		
55  		return XmlBeans.getBuiltinTypeSystem();
56  	}
57  
58  	public String getXml()
59  	{
60  		return mockResponse.getResponseContent();
61  	}
62  
63  	public void setXml( String xml )
64  	{
65  		mockResponse.setResponseContent( xml );
66  	}
67  
68  	public void propertyChange( PropertyChangeEvent arg0 )
69  	{
70  		fireXmlChanged( (String)arg0.getOldValue(), (String)arg0.getNewValue() );
71  	}
72  }