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.support.editor.xml.support;
14  
15  import org.apache.xmlbeans.SchemaTypeSystem;
16  import org.apache.xmlbeans.XmlBeans;
17  import org.apache.xmlbeans.XmlObject;
18  
19  import com.eviware.soapui.SoapUI;
20  
21  /***
22   * Default XmlDocument that works on an existing XmlObject
23   * 
24   * @author ole.matzura
25   */
26  
27  public class XmlObjectXmlDocument extends AbstractXmlDocument
28  {
29  	private XmlObject xmlObject;
30  
31  	public XmlObjectXmlDocument( XmlObject xmlObject )
32  	{
33  		this.xmlObject = xmlObject;
34  	}
35  
36  	public SchemaTypeSystem getTypeSystem()
37  	{
38  		return xmlObject == null ? XmlBeans.getBuiltinTypeSystem() : xmlObject.schemaType().getTypeSystem();
39  	}
40  
41  	public String getXml()
42  	{
43  		return xmlObject.toString();
44  	}
45  
46  	public void setXml( String xml )
47  	{
48  		try
49  		{
50  			String old = getXml();
51  			xmlObject = XmlObject.Factory.parse( xml );
52  			fireXmlChanged( old, getXml() );
53  		}
54  		catch( Exception e )
55  		{
56  			SoapUI.logError( e );
57  		}
58  	}
59  
60  	public void release()
61  	{
62  		xmlObject = null;
63  	}
64  }