View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.xml;
14  
15  import org.apache.xmlbeans.XmlCursor;
16  import org.apache.xmlbeans.XmlObject;
17  
18  /***
19   * Support class for building XmlObject based configurations
20   * 
21   * @author Ole.Matzura
22   */
23  
24  public class XmlObjectConfigurationBuilder
25  {
26  	private XmlObject config;
27  	private XmlCursor cursor;
28  
29  	public XmlObjectConfigurationBuilder()
30  	{
31  		config = XmlObject.Factory.newInstance();
32  		cursor = config.newCursor();
33  		cursor.toNextToken();
34  	}
35  	
36  	public XmlObjectConfigurationBuilder add( String name, String value )
37  	{
38  		cursor.insertElementWithText( name, value );
39  		return this;
40  	}
41  
42  	public XmlObjectConfigurationBuilder add( String name, int value )
43  	{
44  		cursor.insertElementWithText( name, String.valueOf( value ));
45  		return this;
46  	}
47  	
48  	public XmlObjectConfigurationBuilder add( String name, long value )
49  	{
50  		cursor.insertElementWithText( name, String.valueOf( value ));
51  		return this;
52  	}
53  
54  	public XmlObjectConfigurationBuilder add( String name, float value )
55  	{
56  		cursor.insertElementWithText( name, String.valueOf( value ));
57  		return this;
58  	}
59  	
60  	public XmlObject finish() 
61  	{
62  		cursor.dispose();
63        return config;
64  	}
65  
66  	public XmlObjectConfigurationBuilder add(String name, boolean value)
67  	{
68  		cursor.insertElementWithText( name, String.valueOf( value ));
69  		return this;
70  	}
71  
72  	public void add( String name, String[] values )
73  	{
74  		for( String value : values )
75  			add( name, value );
76  	}
77  }