View Javadoc

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