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.model.support;
14  
15  import java.util.Collection;
16  import java.util.Map;
17  import java.util.Set;
18  
19  import org.apache.log4j.Logger;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.config.PropertiesTypeConfig;
23  import com.eviware.soapui.impl.wsdl.MutableTestPropertyHolder;
24  import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder;
25  import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder.PropertiesStepProperty;
26  import com.eviware.soapui.model.ModelItem;
27  import com.eviware.soapui.model.settings.Settings;
28  import com.eviware.soapui.model.testsuite.TestProperty;
29  import com.eviware.soapui.model.testsuite.TestPropertyListener;
30  import com.eviware.soapui.settings.GlobalPropertySettings;
31  import com.eviware.soapui.support.StringUtils;
32  
33  public class SettingsTestPropertyHolder implements MutableTestPropertyHolder, Map<String,TestProperty>
34  {
35  	public final static Logger log = Logger.getLogger(SettingsTestPropertyHolder.class);
36  	private XmlBeansPropertiesTestPropertyHolder propertyHolderSupport;
37  	private PropertiesTypeConfig config;
38  	private final ModelItem modelItem;
39  	private String propertiesLabel = "Test Properties";
40  	
41  	public SettingsTestPropertyHolder( Settings settings, ModelItem modelItem )
42  	{
43  		this.modelItem = modelItem;
44  		config = PropertiesTypeConfig.Factory.newInstance();
45  		try
46  		{
47  			String str = settings.getString( GlobalPropertySettings.PROPERTIES, null );
48  			if( StringUtils.hasContent( str ))
49  				config = PropertiesTypeConfig.Factory.parse( str );
50  		}
51  		catch( Exception e )
52  		{
53  			SoapUI.logError( e );
54  		}
55  		
56  		propertyHolderSupport = new XmlBeansPropertiesTestPropertyHolder( null, config );
57  	}
58  
59  	public TestProperty addProperty( String name )
60  	{
61  		return propertyHolderSupport.addProperty( name );
62  	}
63  
64  	public void addTestPropertyListener( TestPropertyListener listener )
65  	{
66  		propertyHolderSupport.addTestPropertyListener( listener );
67  	}
68  
69  	public Map<String, TestProperty> getProperties()
70  	{
71  		return propertyHolderSupport.getProperties();
72  	}
73  
74  	public PropertiesStepProperty getProperty( String name )
75  	{
76  		return propertyHolderSupport.getProperty( name );
77  	}
78  
79  	public String[] getPropertyNames()
80  	{
81  		return propertyHolderSupport.getPropertyNames();
82  	}
83  
84  	public String getPropertyValue( String name )
85  	{
86  		return propertyHolderSupport.getPropertyValue( name );
87  	}
88  
89  	public boolean hasProperty( String name )
90  	{
91  		return propertyHolderSupport.hasProperty( name );
92  	}
93  
94  	public TestProperty removeProperty( String propertyName )
95  	{
96  		return propertyHolderSupport.removeProperty( propertyName );
97  	}
98  
99  	public void removeTestPropertyListener( TestPropertyListener listener )
100 	{
101 		propertyHolderSupport.removeTestPropertyListener( listener );
102 	}
103 
104 	public boolean renameProperty( String name, String newName )
105 	{
106 		return propertyHolderSupport.renameProperty( name, newName );
107 	}
108 
109 	public void saveTo( Settings settings )
110 	{
111 		settings.setString( GlobalPropertySettings.PROPERTIES, config.toString() );
112 	}
113 
114 	public void setPropertyValue( String name, String value )
115 	{
116 		propertyHolderSupport.setPropertyValue( name, value );
117 	}
118 
119 	public int addPropertiesFromFile( String propFile )
120 	{
121 		return propertyHolderSupport.addPropertiesFromFile( propFile );
122 	}
123 
124 	public ModelItem getModelItem()
125 	{
126 		return modelItem;
127 	}
128 
129 	public void moveProperty(String propertyName, int targetIndex)
130 	{
131 		propertyHolderSupport.moveProperty(propertyName, targetIndex);
132 	}
133 
134 	public TestProperty getPropertyAt(int index)
135 	{
136 		return propertyHolderSupport.getPropertyAt(index);
137 	}
138 
139 	public int getPropertyCount()
140 	{
141 		return propertyHolderSupport.getPropertyCount();
142 	}
143 
144 	public void clear()
145 	{
146 		propertyHolderSupport.clear();
147 	}
148 
149 	public boolean containsKey(Object key)
150 	{
151 		return propertyHolderSupport.containsKey(key);
152 	}
153 
154 	public boolean containsValue(Object value)
155 	{
156 		return propertyHolderSupport.containsValue(value);
157 	}
158 
159 	public Set<java.util.Map.Entry<String, TestProperty>> entrySet()
160 	{
161 		return propertyHolderSupport.entrySet();
162 	}
163 
164 	public TestProperty get(Object key)
165 	{
166 		return propertyHolderSupport.get(key);
167 	}
168 
169 	public boolean isEmpty()
170 	{
171 		return propertyHolderSupport.isEmpty();
172 	}
173 
174 	public Set<String> keySet()
175 	{
176 		return propertyHolderSupport.keySet();
177 	}
178 
179 	public TestProperty put(String key, TestProperty value)
180 	{
181 		return propertyHolderSupport.put(key, value);
182 	}
183 
184 	public void putAll(Map<? extends String, ? extends TestProperty> m)
185 	{
186 		propertyHolderSupport.putAll(m);
187 	}
188 
189 	public TestProperty remove(Object key)
190 	{
191 		return propertyHolderSupport.remove(key);
192 	}
193 
194 	public int size()
195 	{
196 		return propertyHolderSupport.size();
197 	}
198 
199 	public Collection<TestProperty> values()
200 	{
201 		return propertyHolderSupport.values();
202 	}
203 
204 	public String getPropertiesLabel()
205 	{
206 		return propertiesLabel ;
207 	}
208 
209 	public void setPropertiesLabel(String propertiesLabel)
210 	{
211 		this.propertiesLabel = propertiesLabel;
212 	}
213 }