View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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( int initialCapacity )
32  	{
33  		super( initialCapacity );
34  	}
35  
36  	public StringList( String[] strings )
37  	{
38  		super( Arrays.asList( strings ) );
39  	}
40  
41  	public StringList( Object[] objects )
42  	{
43  		super();
44  
45  		for( Object object : objects )
46  			add( object == null ? null : object.toString() );
47  	}
48  
49  	public StringList( Collection<?> objects )
50  	{
51  		super();
52  
53  		for( Object object : objects )
54  			add( object == null ? null : object.toString() );
55  	}
56  
57  	public void addAll( String[] strings )
58  	{
59  		addAll( Arrays.asList( strings ) );
60  	}
61  
62  	public String[] toStringArray()
63  	{
64  		return toArray( new String[size()] );
65  	}
66  
67  	public static StringList fromXml( String value ) throws XmlException
68  	{
69  		return StringUtils.isNullOrEmpty( value ) ? new StringList() : new StringList( StringListConfig.Factory.parse(
70  				value ).getEntryList() );
71  	}
72  
73  	public String toXml()
74  	{
75  		StringListConfig config = StringListConfig.Factory.newInstance();
76  		config.setEntryArray( toStringArray() );
77  		return config.xmlText();
78  	}
79  }