View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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 java.util.HashMap;
16  import java.util.Map;
17  
18  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
19  import com.eviware.soapui.model.propertyexpansion.resolvers.providers.ProjectDirProvider;
20  
21  public class DynamicPropertyResolver implements PropertyResolver
22  {
23  	private static Map<String,ValueProvider> providers = new HashMap<String, ValueProvider>();
24  	
25  	static
26  	{
27  		addProvider( "projectDir", new ProjectDirProvider() );
28  	}
29  	
30  	public DynamicPropertyResolver()
31  	{
32  	}
33  	
34  	public String resolveProperty( PropertyExpansionContext context, String name, boolean globalOverride )
35  	{
36  		ValueProvider provider = providers.get( name );
37  		if( provider != null )
38  			return provider.getValue( context );
39  		
40  		return null;
41  	}
42  
43  	public static void addProvider( String propertyName, ValueProvider provider )
44  	{
45  		providers.put( propertyName, provider );
46  	}
47  	
48  	public interface ValueProvider
49  	{
50  		String getValue( PropertyExpansionContext context );
51  	}
52  }