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.impl.wsdl;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import com.eviware.soapui.config.InterfaceConfig;
19  import com.eviware.soapui.impl.InterfaceFactory;
20  import com.eviware.soapui.impl.WsdlInterfaceFactory;
21  import com.eviware.soapui.impl.rest.RestServiceFactory;
22  import com.eviware.soapui.impl.support.AbstractInterface;
23  import com.eviware.soapui.support.StringUtils;
24  
25  public class InterfaceFactoryRegistry
26  {
27  	private static Map<String,InterfaceFactory<?>> factories = new HashMap<String, InterfaceFactory<?>>();
28  	
29  	static
30  	{
31  		factories.put( WsdlInterfaceFactory.WSDL_TYPE, new WsdlInterfaceFactory() );
32  		factories.put( RestServiceFactory.REST_TYPE, new RestServiceFactory() );
33  	}
34  	
35  	public static AbstractInterface<?> createNew(WsdlProject project,String type, String name)
36  	{
37  		if( !factories.containsKey(type))
38  			throw new RuntimeException( "Unknown interface type [" + type + "]" );
39  		
40  		return factories.get( type ).createNew( project, name );
41  	}
42  
43  	public static AbstractInterface<?> build(WsdlProject project, InterfaceConfig config)
44  	{
45  		String type = config.getType();
46  		if( StringUtils.isNullOrEmpty(type))
47  			type = WsdlInterfaceFactory.WSDL_TYPE;
48  		
49  		return factories.get( type ).build( project, config );
50  	}
51  }