View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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 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.SoapUI;
22  import com.eviware.soapui.impl.wsdl.WsdlInterface;
23  import com.eviware.soapui.impl.wsdl.WsdlOperation;
24  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
25  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
26  import com.eviware.soapui.support.editor.xml.support.AbstractXmlDocument;
27  
28  /***
29   * XmlDocument for a WsdlMockResponse
30   * 
31   * @author ole.matzura
32   */
33  
34  public class MockResponseXmlDocument extends AbstractXmlDocument implements PropertyChangeListener
35  {
36  	private final WsdlMockResponse mockResponse;
37  
38  	public MockResponseXmlDocument( WsdlMockResponse response )
39  	{
40  		this.mockResponse = response;
41  		
42  		mockResponse.addPropertyChangeListener( WsdlMockResponse.RESPONSE_CONTENT_PROPERTY, this );
43  	}
44  
45  	public SchemaTypeSystem getTypeSystem()
46  	{
47  		try
48  		{
49  			WsdlOperation operation = mockResponse.getMockOperation().getOperation();
50  			if( operation != null )
51  			{
52  				WsdlInterface iface = operation.getInterface();
53  				WsdlContext wsdlContext = iface.getWsdlContext();
54  				return wsdlContext.getSchemaTypeSystem();
55  			}
56  		}
57  		catch (Exception e1)
58  		{
59  			SoapUI.logError( e1 );
60  		}
61  		
62  		return XmlBeans.getBuiltinTypeSystem();
63  	}
64  
65  	public String getXml()
66  	{
67  		return mockResponse.getResponseContent();
68  	}
69  
70  	public void setXml( String xml )
71  	{
72  		mockResponse.setResponseContent( xml );
73  	}
74  
75  	public void propertyChange( PropertyChangeEvent arg0 )
76  	{
77  		fireXmlChanged( (String)arg0.getOldValue(), (String)arg0.getNewValue() );
78  	}
79  
80  	@Override
81  	public void release()
82  	{
83  		mockResponse.removePropertyChangeListener( WsdlMockResponse.RESPONSE_CONTENT_PROPERTY, this );
84  	}
85  }