View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.support.propertyexpansion;
14  
15  import com.eviware.soapui.impl.wsdl.teststeps.HttpTestRequestInterface;
16  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
17  import com.eviware.soapui.model.ModelItem;
18  import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
19  import com.eviware.soapui.support.scripting.SoapUIScriptEngineRegistry;
20  import com.eviware.soapui.support.scripting.SoapUIScriptGenerator;
21  
22  public abstract class AbstractPropertyExpansionTarget implements PropertyExpansionTarget
23  {
24  	private ModelItem modelItem;
25  
26  	public AbstractPropertyExpansionTarget( ModelItem modelItem )
27  	{
28  		this.modelItem = modelItem;
29  	}
30  
31  	public ModelItem getContextModelItem()
32  	{
33  		if( modelItem instanceof WsdlTestRequest )
34  		{
35  			modelItem = ( ( WsdlTestRequest )modelItem ).getTestStep();
36  		}
37  		else if( modelItem instanceof HttpTestRequestInterface<?> )
38  		{
39  			modelItem = ( ( HttpTestRequestInterface<?> )modelItem ).getTestStep();
40  		}
41  
42  		return modelItem;
43  	}
44  
45  	public ModelItem getModelItem()
46  	{
47  		return modelItem;
48  	}
49  
50  	protected String createContextExpansion( String name, PropertyExpansion expansion )
51  	{
52  		SoapUIScriptGenerator scriptGenerator = SoapUIScriptEngineRegistry.createScriptGenerator( getModelItem() );
53  		return scriptGenerator.createContextExpansion( name, expansion );
54  	}
55  }