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.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  	public SchemaTypeSystem getTypeSystem()
36  	{
37  		return xmlObject == null ? XmlBeans.getBuiltinTypeSystem() : xmlObject.schemaType().getTypeSystem();
38  	}
39  
40  	public String getXml()
41  	{
42  		return xmlObject.toString();
43  	}
44  
45  	public void setXml(String xml)
46  	{
47  		try
48  		{
49  			String old = getXml();
50  			xmlObject = XmlObject.Factory.parse( xml );
51  			fireXmlChanged( old, getXml() );
52  		}
53  		catch (Exception e)
54  		{
55  			SoapUI.logError( e );
56  		}
57  	}
58  
59  	public void release()
60  	{
61  		xmlObject = null;
62  	}
63  }