View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.Map;
16  
17  import org.apache.log4j.Logger;
18  
19  import com.eviware.soapui.SoapUI;
20  import com.eviware.soapui.config.PropertiesTypeConfig;
21  import com.eviware.soapui.impl.wsdl.MutableTestPropertyHolder;
22  import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder;
23  import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder.PropertiesStepProperty;
24  import com.eviware.soapui.model.ModelItem;
25  import com.eviware.soapui.model.settings.Settings;
26  import com.eviware.soapui.model.testsuite.TestProperty;
27  import com.eviware.soapui.model.testsuite.TestPropertyListener;
28  import com.eviware.soapui.settings.GlobalPropertySettings;
29  import com.eviware.soapui.support.StringUtils;
30  
31  public class SettingsTestPropertyHolder implements MutableTestPropertyHolder
32  {
33  	public final static Logger log = Logger.getLogger(SettingsTestPropertyHolder.class);
34  	private XmlBeansPropertiesTestPropertyHolder propertyHolderSupport;
35  	private PropertiesTypeConfig config;
36  	private final ModelItem modelItem;
37  	
38  	public SettingsTestPropertyHolder( Settings settings, ModelItem modelItem )
39  	{
40  		this.modelItem = modelItem;
41  		config = PropertiesTypeConfig.Factory.newInstance();
42  		try
43  		{
44  			String str = settings.getString( GlobalPropertySettings.PROPERTIES, null );
45  			if( StringUtils.hasContent( str ))
46  				config = PropertiesTypeConfig.Factory.parse( str );
47  		}
48  		catch( Exception e )
49  		{
50  			SoapUI.logError( e );
51  		}
52  		
53  		propertyHolderSupport = new XmlBeansPropertiesTestPropertyHolder( null, config );
54  	}
55  
56  	public TestProperty addProperty( String name )
57  	{
58  		return propertyHolderSupport.addProperty( name );
59  	}
60  
61  	public void addTestPropertyListener( TestPropertyListener listener )
62  	{
63  		propertyHolderSupport.addTestPropertyListener( listener );
64  	}
65  
66  	public Map<String, TestProperty> getProperties()
67  	{
68  		return propertyHolderSupport.getProperties();
69  	}
70  
71  	public PropertiesStepProperty getProperty( String name )
72  	{
73  		return propertyHolderSupport.getProperty( name );
74  	}
75  
76  	public String[] getPropertyNames()
77  	{
78  		return propertyHolderSupport.getPropertyNames();
79  	}
80  
81  	public String getPropertyValue( String name )
82  	{
83  		return propertyHolderSupport.getPropertyValue( name );
84  	}
85  
86  	public boolean hasProperty( String name )
87  	{
88  		return propertyHolderSupport.hasProperty( name );
89  	}
90  
91  	public void removeProperty( String propertyName )
92  	{
93  		propertyHolderSupport.removeProperty( propertyName );
94  	}
95  
96  	public void removeTestPropertyListener( TestPropertyListener listener )
97  	{
98  		propertyHolderSupport.removeTestPropertyListener( listener );
99  	}
100 
101 	public boolean renameProperty( String name, String newName )
102 	{
103 		return propertyHolderSupport.renameProperty( name, newName );
104 	}
105 
106 	public void saveTo( Settings settings )
107 	{
108 		settings.setString( GlobalPropertySettings.PROPERTIES, config.toString() );
109 	}
110 
111 	public void setPropertyValue( String name, String value )
112 	{
113 		propertyHolderSupport.setPropertyValue( name, value );
114 	}
115 
116 	public int addPropertiesFromFile( String propFile )
117 	{
118 		return propertyHolderSupport.addPropertiesFromFile( propFile );
119 	}
120 
121 	public ModelItem getModelItem()
122 	{
123 		return modelItem;
124 	}
125 }