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.support.components;
14  
15  import com.eviware.soapui.SoapUI;
16  import com.eviware.soapui.impl.wsdl.WsdlInterface;
17  import com.eviware.soapui.impl.wsdl.WsdlRequest;
18  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
19  import com.eviware.soapui.support.editor.xml.support.AbstractXmlDocument;
20  import org.apache.xmlbeans.SchemaTypeSystem;
21  import org.apache.xmlbeans.XmlBeans;
22  
23  import java.beans.PropertyChangeEvent;
24  import java.beans.PropertyChangeListener;
25  
26  /***
27   * XmlDocument for a WsdlRequest
28   * 
29   * @author ole.matzura
30   */
31  
32  public class RequestXmlDocument extends AbstractXmlDocument implements PropertyChangeListener
33  {
34  	private final WsdlRequest request;
35  	private boolean updating;
36  
37  	public RequestXmlDocument(WsdlRequest request)
38  	{
39  		this.request = request;
40  		request.addPropertyChangeListener( WsdlRequest.REQUEST_PROPERTY, this );
41  	}
42  
43  	public String getXml()
44  	{
45  		return request.getRequestContent();
46  	}
47  
48  	public void setXml(String xml)
49  	{
50        if( !updating )
51        {
52           updating = true;
53           String old = request.getRequestContent();
54           request.setRequestContent( xml );
55           fireXmlChanged( old, xml );
56           updating = false;
57        }
58     }
59  
60  	public void propertyChange(PropertyChangeEvent evt)
61  	{
62  		if( !updating )
63        {
64           updating = true;
65           fireXmlChanged( (String)evt.getOldValue(), (String)evt.getNewValue() );
66           updating = false;
67        }
68     }
69  
70  	public SchemaTypeSystem getTypeSystem()
71  	{
72  		WsdlInterface iface = (WsdlInterface) request.getOperation().getInterface();
73  		WsdlContext wsdlContext = iface.getWsdlContext();
74  		try
75  		{
76  			return wsdlContext.getSchemaTypeSystem();
77  		}
78  		catch (Exception e1)
79  		{
80  			SoapUI.logError( e1 );
81  			return XmlBeans.getBuiltinTypeSystem();
82  		}
83  	}
84  	
85  	public void release()
86  	{
87  		request.removePropertyChangeListener( WsdlRequest.REQUEST_PROPERTY, this );
88  	}
89  }