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 org.apache.commons.beanutils.PropertyUtils;
16  
17  import com.eviware.soapui.model.testsuite.TestStep;
18  
19  /***
20   * TestStepProperty implementation that maps to a standard javabean property
21   * 
22   * @author Ole.Matzura
23   */
24  
25  public class TestStepBeanProperty extends DefaultTestStepProperty
26  {
27  	public TestStepBeanProperty(String name, boolean isReadOnly, Object targetObject, String targetName, TestStep testStep )
28  	{
29  		super(name, isReadOnly, new BeanPropertyHandler( targetObject, targetName ), testStep );
30  	}
31  	
32  	/***
33  	 * PropertyHandler for setting/getting bean properties
34  	 * 
35  	 * @author Ole.Matzura
36  	 */
37  	
38  	public static class BeanPropertyHandler implements PropertyHandler
39  	{
40  		private final Object target;
41  		private final String targetName;
42  		
43  		public BeanPropertyHandler(Object targetObject, String targetName)
44  		{
45  			this.target = targetObject;
46  			this.targetName = targetName;
47  		}
48  
49  		public String getValue()
50  		{
51  			try
52  			{
53  				Object property = PropertyUtils.getProperty(target, targetName );
54  				return property == null ? null : property.toString();
55  			}
56  			catch (Exception e)
57  			{
58  				e.printStackTrace();
59  				return null;
60  			}			
61  		}
62  
63  		public void setValue(String value)
64  		{
65  			try
66  			{
67  				PropertyUtils.setProperty( target, targetName, value );
68  			}
69  			catch (Exception e)
70  			{
71  				e.printStackTrace();
72  			}
73  		}
74  	}
75  
76  }