1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.propertyexpansion;
14
15 import org.apache.commons.beanutils.PropertyUtils;
16
17 import com.eviware.soapui.model.testsuite.TestProperty;
18
19 public class MutablePropertyExpansionImpl extends PropertyExpansionImpl implements MutablePropertyExpansion
20 {
21 private final Object container;
22 private final String propertyName;
23 private String stringRep;
24
25 public MutablePropertyExpansionImpl( TestProperty tp, String xpath, Object container, String propertyName )
26 {
27 super( tp, xpath );
28 this.container = container;
29 this.propertyName = propertyName;
30
31 stringRep = toString();
32 }
33
34 public void setProperty( TestProperty property )
35 {
36 super.setProperty( property );
37 }
38
39 public void setXPath( String xpath )
40 {
41 super.setXPath( xpath );
42 }
43
44 public void update() throws Exception
45 {
46 String rep = toString();
47
48
49 if( stringRep.equals( rep ) )
50 return;
51
52 Object obj = PropertyUtils.getProperty( container, propertyName );
53 if( obj == null )
54 throw new Exception( "property value is null" );
55
56 String str = obj.toString();
57 int ix = str.indexOf( stringRep );
58 if( ix == -1 )
59 throw new Exception( "property expansion [" + stringRep + "] not found for update" );
60
61 while( ix != -1 )
62 {
63 str = str.substring( 0, ix ) + rep + str.substring( ix + stringRep.length() );
64 ix = str.indexOf( stringRep, ix + rep.length() );
65 }
66
67 PropertyUtils.setProperty( container, propertyName, str );
68
69 stringRep = rep;
70 }
71 }