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