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