01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private XmlObject config;
26: private XmlCursor cursor;
27:
28: public XmlObjectConfigurationBuilder(XmlObject config) {
29: this .config = config;
30: cursor = config.newCursor();
31: cursor.toNextToken();
32: }
33:
34: public XmlObjectConfigurationBuilder() {
35: this (XmlObject.Factory.newInstance());
36: cursor = config.newCursor();
37: cursor.toNextToken();
38: }
39:
40: public XmlObjectConfigurationBuilder add(String name, String value) {
41: cursor.insertElementWithText(name, value);
42: return this ;
43: }
44:
45: public XmlObjectConfigurationBuilder add(String name, int value) {
46: cursor.insertElementWithText(name, String.valueOf(value));
47: return this ;
48: }
49:
50: public XmlObjectConfigurationBuilder add(String name, long value) {
51: cursor.insertElementWithText(name, String.valueOf(value));
52: return this ;
53: }
54:
55: public XmlObjectConfigurationBuilder add(String name, float value) {
56: cursor.insertElementWithText(name, String.valueOf(value));
57: return this ;
58: }
59:
60: public XmlObject finish() {
61: cursor.dispose();
62: return config;
63: }
64:
65: public XmlObjectConfigurationBuilder add(String name, boolean value) {
66: cursor.insertElementWithText(name, String.valueOf(value));
67: return this ;
68: }
69:
70: public void add(String name, String[] values) {
71: for (String value : values)
72: add(name, value);
73: }
74: }
|