View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.request.components;
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.WsdlRequest;
23  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.AbstractXmlDocument;
24  import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
25  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
26  import com.eviware.soapui.model.iface.Response;
27  
28  public class ResponseXmlDocument extends AbstractXmlDocument implements PropertyChangeListener
29  {
30  	private final WsdlRequest request;
31  	private boolean settingResponse;
32  
33  	public ResponseXmlDocument(WsdlRequest request)
34  	{
35  		this.request = request;
36  		request.addPropertyChangeListener( this );
37  	}
38  
39  	public String getXml()
40  	{
41  		Response response = request.getResponse();
42  		return response == null ? null : response.getContentAsString();
43  	}
44  
45  	public void setXml(String xml)
46  	{
47  		WsdlResponse response = (WsdlResponse) request.getResponse();
48  		if( response != null )
49  		{
50  			try
51  			{
52  				settingResponse = true;
53  				response.setResponseContent(xml);
54  			}
55  			finally
56  			{
57  				settingResponse = false;
58  			}			
59  		}
60  	}
61  
62  	public void propertyChange(PropertyChangeEvent evt)
63  	{
64  		if( evt.getPropertyName().equals( WsdlRequest.RESPONSE_PROPERTY ) || 
65  			(evt.getPropertyName().equals( WsdlRequest.RESPONSE_CONTENT_PROPERTY ) && !settingResponse ))
66  		{
67  			Response oldResponse = (Response) evt.getOldValue();
68  			Response newResponse = (Response) evt.getNewValue();
69  			
70  			fireXmlChanged( oldResponse == null ? null : oldResponse.getContentAsString(), 
71  					newResponse == null ? null : newResponse.getContentAsString() );
72  		}
73  	}
74  
75  	public SchemaTypeSystem getTypeSystem()
76  	{
77  		WsdlInterface iface = (WsdlInterface) request.getOperation().getInterface();
78  		WsdlContext wsdlContext = iface.getWsdlContext();
79  		try
80  		{
81  			return wsdlContext.getSchemaTypeSystem();
82  		}
83  		catch (Exception e1)
84  		{
85  			e1.printStackTrace();
86  			return XmlBeans.getBuiltinTypeSystem();
87  		}
88  	}
89  }