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  /***
20   * Default XmlDocument that works on a standard xml string
21   * 
22   * @author ole.matzura
23   */
24  
25  public class DefaultXmlDocument extends AbstractXmlDocument
26  {
27  	private String xml;
28  	private SchemaTypeSystem typeSystem;
29  
30  	public DefaultXmlDocument( String xml )
31  	{
32  		this.xml = xml;
33  	}
34  	
35  	public DefaultXmlDocument()
36  	{
37  	}
38  
39  	public void setTypeSystem( SchemaTypeSystem typeSystem )
40  	{
41  		this.typeSystem = typeSystem;
42  	}
43  
44  	public SchemaTypeSystem getTypeSystem()
45  	{
46  		if( typeSystem != null )
47  			return typeSystem;
48  		
49  		try
50  		{
51  			typeSystem = XmlObject.Factory.parse( xml ).schemaType().getTypeSystem();
52  			return typeSystem;
53  		}
54  		catch (Exception e)
55  		{
56  			return XmlBeans.getBuiltinTypeSystem();
57  		}
58  	}
59  
60  	public String getXml()
61  	{
62  		return xml;
63  	}
64  
65  	public void setXml(String xml)
66  	{
67  		String oldXml = this.xml;
68  		this.xml = xml;
69  		
70  		fireXmlChanged( oldXml, xml );
71  	}
72  
73  	public void release()
74  	{
75  		typeSystem = null;
76  	}
77  }