View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.resolvers;
14  
15  import com.eviware.soapui.model.propertyexpansion.PropertyExpander;
16  import com.eviware.soapui.model.propertyexpansion.PropertyExpansion;
17  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
18  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
19  
20  public class ContextPropertyResolver implements PropertyResolver
21  {
22  	public String resolveProperty( PropertyExpansionContext context, String propertyName, boolean globalOverride )
23  	{
24  		Object property = null;
25  		String xpath = null;
26  
27  		int sepIx = propertyName.indexOf( PropertyExpansion.PROPERTY_SEPARATOR );
28  		if( sepIx == 0 )
29  		{
30  			propertyName = propertyName.substring( 1 );
31  			sepIx = propertyName.indexOf( PropertyExpansion.PROPERTY_SEPARATOR );
32  		}
33  
34  		if( sepIx > 0 )
35  		{
36  			xpath = propertyName.substring( sepIx + 1 );
37  			propertyName = propertyName.substring( 0, sepIx );
38  		}
39  
40  		if( globalOverride )
41  			property = PropertyExpansionUtils.getGlobalProperty( propertyName );
42  
43  		if( property == null )
44  			property = context.getProperty( propertyName );
45  
46  		if( property != null && xpath != null )
47  		{
48  			property = ResolverUtils.extractXPathPropertyValue( property, PropertyExpander.expandProperties( context,
49  					xpath ) );
50  		}
51  
52  		return property == null ? null : property.toString();
53  	}
54  
55  }