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.impl.wsdl;
14  
15  import java.util.List;
16  import java.util.Map;
17  
18  import org.apache.log4j.Logger;
19  
20  import com.eviware.soapui.SoapUI;
21  import com.eviware.soapui.config.ModelItemConfig;
22  import com.eviware.soapui.config.PropertiesTypeConfig;
23  import com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder;
24  import com.eviware.soapui.model.ModelItem;
25  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
26  import com.eviware.soapui.model.testsuite.TestProperty;
27  import com.eviware.soapui.model.testsuite.TestPropertyListener;
28  import com.eviware.soapui.support.StringUtils;
29  
30  public abstract class AbstractTestPropertyHolderWsdlModelItem<T extends ModelItemConfig> extends
31  		AbstractWsdlModelItem<T> implements MutableTestPropertyHolder
32  {
33  	private XmlBeansPropertiesTestPropertyHolder propertyHolderSupport;
34  	private final static Logger log = Logger.getLogger( AbstractTestPropertyHolderWsdlModelItem.class );
35  
36  	protected AbstractTestPropertyHolderWsdlModelItem( T config, ModelItem parent, String icon )
37  	{
38  		super( config, parent, icon );
39  	}
40  
41  	protected void setPropertiesConfig( PropertiesTypeConfig config )
42  	{
43  		if( propertyHolderSupport == null )
44  			propertyHolderSupport = new XmlBeansPropertiesTestPropertyHolder( this, config );
45  		else
46  			propertyHolderSupport.resetPropertiesConfig( config );
47  
48  		String propertyName = createPropertyName( getName() );
49  		if( StringUtils.hasContent( propertyName ) )
50  		{
51  			String propFileName = "soapui.properties." + propertyName;
52  			String propFile = System.getProperty( propFileName );
53  			if( !StringUtils.hasContent( propFile ))
54  				propFile = SoapUI.getGlobalProperties().getPropertyValue( propFileName );
55  			
56  			if( StringUtils.hasContent( propFile ) )
57  			{
58  				int result = propertyHolderSupport.addPropertiesFromFile( propFile );
59  				if( result > 0 )
60  				{
61  					log.info( "Overriding " + result + " properties from [" + propFile + "] in [" + getName() + "]" );
62  				}
63  			}
64  		}
65  	}
66  
67  	private String createPropertyName( String str )
68  	{
69  		if( str == null )
70  			return null;
71  
72  		StringBuffer result = new StringBuffer();
73  		for( char ch : str.toCharArray() )
74  		{
75  			if( Character.isLetterOrDigit( ch ) )
76  				result.append( ch );
77  		}
78  
79  		return result.toString();
80  	}
81  
82  	public int addPropertiesFromFile( String propFile )
83  	{
84  		return propertyHolderSupport.addPropertiesFromFile( propFile );
85  	}
86  
87  	public TestProperty addProperty( String name )
88  	{
89  		return propertyHolderSupport.addProperty( name );
90  	}
91  
92  	public void addTestPropertyListener( TestPropertyListener listener )
93  	{
94  		propertyHolderSupport.addTestPropertyListener( listener );
95  	}
96  
97  	public TestProperty getProperty( String name )
98  	{
99  		return propertyHolderSupport.getProperty( name );
100 	}
101 
102 	public String[] getPropertyNames()
103 	{
104 		return propertyHolderSupport.getPropertyNames();
105 	}
106 
107 	public List<TestProperty> getPropertyList()
108 	{
109 		return propertyHolderSupport.getPropertyList();
110 	}
111 
112 	public String getPropertyValue( String name )
113 	{
114 		return propertyHolderSupport.getPropertyValue( name );
115 	}
116 
117 	public TestProperty removeProperty( String propertyName )
118 	{
119 		return propertyHolderSupport.removeProperty( propertyName );
120 	}
121 
122 	public void removeTestPropertyListener( TestPropertyListener listener )
123 	{
124 		propertyHolderSupport.removeTestPropertyListener( listener );
125 	}
126 
127 	public void setPropertyValue( String name, String value )
128 	{
129 		propertyHolderSupport.setPropertyValue( name, value );
130 	}
131 
132 	public boolean renameProperty( String name, String newName )
133 	{
134 		return PropertyExpansionUtils.renameProperty( propertyHolderSupport.getProperty( name ), newName, this ) != null;
135 	}
136 
137 	public Map<String, TestProperty> getProperties()
138 	{
139 		return propertyHolderSupport.getProperties();
140 	}
141 
142 	public boolean hasProperty( String name )
143 	{
144 		return propertyHolderSupport.hasProperty( name );
145 	}
146 
147 	public TestProperty getPropertyAt( int index )
148 	{
149 		return propertyHolderSupport.getPropertyAt( index );
150 	}
151 
152 	public int getPropertyCount()
153 	{
154 		return propertyHolderSupport.getPropertyCount();
155 	}
156 
157 	public void moveProperty( String propertyName, int targetIndex )
158 	{
159 		propertyHolderSupport.moveProperty( propertyName, targetIndex );
160 	}
161 
162 	public ModelItem getModelItem()
163 	{
164 		return this;
165 	}
166 
167 	public String getPropertiesLabel()
168 	{
169 		return "Test Properties";
170 	}
171 }