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