View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.propertyexpansion;
14  
15  import com.eviware.soapui.model.ModelItem;
16  import com.eviware.soapui.model.mock.MockResponse;
17  import com.eviware.soapui.model.mock.MockService;
18  import com.eviware.soapui.model.project.Project;
19  import com.eviware.soapui.model.testsuite.TestCase;
20  import com.eviware.soapui.model.testsuite.TestProperty;
21  import com.eviware.soapui.model.testsuite.TestStep;
22  import com.eviware.soapui.model.testsuite.TestSuite;
23  import com.eviware.soapui.support.StringUtils;
24  
25  public class PropertyExpansionImpl implements PropertyExpansion
26  {
27  	private String xpath;
28  	private TestProperty property;
29  	private String containerInfo;
30  
31  	public PropertyExpansionImpl( TestProperty property, String xpath )
32     {
33  		this.property = property;
34  		this.xpath = xpath;
35  		
36  		containerInfo = property.getName();
37  		if( property.getModelItem() != null )
38  			containerInfo += " in " + property.getModelItem().getName();
39  	}
40  	
41  	public TestProperty getProperty()
42  	{
43  		return property;
44  	}
45  	
46  	public String toString()
47  	{
48  		StringBuffer result = new StringBuffer();
49  		result.append( "${" );
50  		
51  		ModelItem modelItem = property.getModelItem();
52  		
53  		if( modelItem instanceof Project )
54  			result.append( PropertyExpansionImpl.PROJECT_REFERENCE );
55  		else if( modelItem instanceof TestSuite )
56  			result.append( PropertyExpansionImpl.TESTSUITE_REFERENCE );
57  		else if( modelItem instanceof TestCase )
58  			result.append( PropertyExpansionImpl.TESTCASE_REFERENCE );
59  		else if( modelItem instanceof MockService )
60  			result.append( PropertyExpansionImpl.MOCKSERVICE_REFERENCE );
61  		else if( modelItem instanceof MockResponse )
62  			result.append( PropertyExpansionImpl.MOCKRESPONSE_REFERENCE );
63  		else if( modelItem instanceof TestStep )
64  			result.append( modelItem.getName() ).append( PROPERTY_SEPARATOR );
65  		
66  		result.append( property.getName() );
67  		if( StringUtils.hasContent( xpath ))
68  			result.append( PROPERTY_SEPARATOR  ).append( xpath );
69  		
70  		result.append( '}' );
71  		
72  		return result.toString();
73  	}
74  
75  	public String getXPath()
76  	{
77  		return xpath;
78  	}
79  
80  	public String getContainerInfo()
81  	{
82  		return containerInfo;
83  	}
84  
85  	public void setContainerInfo( String containerInfo )
86  	{
87  		this.containerInfo = containerInfo;
88  	}
89  
90  	protected void setProperty( TestProperty property )
91  	{
92  		this.property = property;
93  	}
94  
95  	protected void setXPath( String xpath )
96  	{
97  		this.xpath = xpath;
98  	}
99  }