View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.monitor;
14  
15  import java.beans.PropertyDescriptor;
16  import java.util.Properties;
17  
18  import org.apache.commons.beanutils.BeanUtils;
19  import org.apache.commons.beanutils.PropertyUtils;
20  
21  import com.eviware.soapui.SoapUI;
22  import com.eviware.soapui.model.ModelItem;
23  import com.eviware.soapui.model.propertyexpansion.DefaultPropertyExpansionContext;
24  
25  public class PropertySupport
26  {
27  	public static void applySystemProperties( Object target, String scope, ModelItem modelItem )
28  	{
29  		PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors( target );
30  		DefaultPropertyExpansionContext context = new DefaultPropertyExpansionContext( modelItem );
31  		Properties properties = System.getProperties();
32  
33  		for( PropertyDescriptor descriptor : descriptors )
34  		{
35  			String name = descriptor.getName();
36  			String key = scope + "." + name;
37  			if( PropertyUtils.isWriteable( target, name ) && properties.containsKey( key ) )
38  			{
39  				try
40  				{
41  					String value = context.expand( String.valueOf( properties.get( key ) ) );
42  					BeanUtils.setProperty( target, name, value );
43  					SoapUI.log.info( "Set property [" + name + "] to [" + value + "] in scope [" + scope + "]" );
44  				}
45  				catch( Throwable e )
46  				{
47  					SoapUI.logError( e );
48  				}
49  			}
50  		}
51  	}
52  
53  }