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