01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: public TestStepBeanProperty(String name, boolean isReadOnly,
28: Object targetObject, String targetName, TestStep testStep) {
29: super (name, isReadOnly, new BeanPropertyHandler(targetObject,
30: 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: private final Object target;
41: private final String targetName;
42:
43: public BeanPropertyHandler(Object targetObject,
44: String targetName) {
45: this .target = targetObject;
46: this .targetName = targetName;
47: }
48:
49: public String getValue() {
50: try {
51: Object property = PropertyUtils.getProperty(target,
52: targetName);
53: return property == null ? null : property.toString();
54: } catch (Exception e) {
55: SoapUI.logError(e);
56: return null;
57: }
58: }
59:
60: public void setValue(String value) {
61: try {
62: PropertyUtils.setProperty(target, targetName, value);
63: } catch (Exception e) {
64: SoapUI.logError(e);
65: }
66: }
67: }
68:
69: }
|