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.types;
14  
15  import java.util.ArrayList;
16  import java.util.Arrays;
17  import java.util.Collection;
18  
19  import org.apache.xmlbeans.XmlException;
20  
21  import com.eviware.soapui.config.StringListConfig;
22  import com.eviware.soapui.support.StringUtils;
23  
24  public class StringList extends ArrayList<String>
25  {
26  	public StringList()
27  	{
28  		super();
29  	}
30  
31  	public StringList(Collection<? extends String> c)
32  	{
33  		super(c);
34  	}
35  
36  	public StringList(int initialCapacity)
37  	{
38  		super(initialCapacity);
39  	}
40  
41  	public StringList( String[] strings )
42  	{
43  		super( Arrays.asList( strings ));
44  	}
45  
46  	public StringList( Object[] objects )
47  	{
48  		super();
49  		
50  		for( Object object : objects )
51  			add( object == null ? null : object.toString() );
52  	}
53  
54  	public void addAll(String[] strings)
55  	{
56  		addAll( Arrays.asList( strings ));
57  	}
58  
59  	public String[] toStringArray()
60  	{
61  		return toArray( new String[size()]);
62  	}
63  
64  	public static StringList fromXml( String value ) throws XmlException
65  	{
66  		return StringUtils.isNullOrEmpty( value ) ? new StringList() : 
67  			new StringList( StringListConfig.Factory.parse( value ).getEntryList() );
68  	}
69  
70  	public String toXml()
71  	{
72  		StringListConfig config = StringListConfig.Factory.newInstance();
73  		config.setEntryArray( toStringArray() );
74  		return config.xmlText();
75  	}
76  }