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