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.impl.wsdl;
14  
15  import java.io.ByteArrayOutputStream;
16  import java.io.File;
17  import java.io.FileOutputStream;
18  import java.io.IOException;
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  import java.util.ArrayList;
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  import javax.swing.ImageIcon;
27  import javax.xml.namespace.QName;
28  
29  import org.apache.log4j.Logger;
30  import org.apache.xmlbeans.XmlException;
31  import org.apache.xmlbeans.XmlOptions;
32  
33  import com.eviware.soapui.SoapUI;
34  import com.eviware.soapui.config.InterfaceConfig;
35  import com.eviware.soapui.config.MockServiceConfig;
36  import com.eviware.soapui.config.ProjectConfig;
37  import com.eviware.soapui.config.SoapuiProjectDocumentConfig;
38  import com.eviware.soapui.config.TestSuiteConfig;
39  import com.eviware.soapui.impl.WorkspaceImpl;
40  import com.eviware.soapui.impl.wsdl.endpoint.DefaultEndpointStrategy;
41  import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
42  import com.eviware.soapui.impl.wsdl.support.wsdl.UrlWsdlLoader;
43  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
44  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader;
45  import com.eviware.soapui.model.iface.Interface;
46  import com.eviware.soapui.model.mock.MockService;
47  import com.eviware.soapui.model.project.EndpointStrategy;
48  import com.eviware.soapui.model.project.Project;
49  import com.eviware.soapui.model.project.ProjectListener;
50  import com.eviware.soapui.model.settings.Settings;
51  import com.eviware.soapui.model.testsuite.TestSuite;
52  import com.eviware.soapui.settings.ProjectSettings;
53  import com.eviware.soapui.settings.UISettings;
54  import com.eviware.soapui.settings.WsdlSettings;
55  import com.eviware.soapui.support.SoapUIException;
56  import com.eviware.soapui.support.StringUtils;
57  import com.eviware.soapui.support.Tools;
58  import com.eviware.soapui.support.UISupport;
59  
60  /***
61   * WSDL project implementation
62   * 
63   * @author Ole.Matzura
64   */
65  
66  public class WsdlProject extends AbstractWsdlModelItem<ProjectConfig> implements Project
67  {
68     private WorkspaceImpl workspace;
69     private String path;
70     private List<WsdlInterface> interfaces = new ArrayList<WsdlInterface>();
71     private List<WsdlTestSuite> testSuites = new ArrayList<WsdlTestSuite>();
72     private List<WsdlMockService> mockServices = new ArrayList<WsdlMockService>();
73     private Set<ProjectListener> projectListeners = new HashSet<ProjectListener>();
74     private SoapuiProjectDocumentConfig projectDocument;
75  	private ImageIcon disabledIcon;
76  	private ImageIcon closedIcon;
77  	private ImageIcon remoteIcon;
78  	private EndpointStrategy endpointStrategy = new DefaultEndpointStrategy();
79  	private long lastModified;
80  	private boolean remote;
81  	private boolean open = true;
82  	private boolean disabled;
83     
84     private final static Logger log = Logger.getLogger( WsdlProject.class );
85  
86     public WsdlProject() throws XmlException, IOException, SoapUIException
87     {
88     	this( (WorkspaceImpl)null );
89     }
90  
91     public WsdlProject( String path ) throws XmlException, IOException, SoapUIException
92     {
93     	this( path, null );
94     }
95     
96     public WsdlProject( WorkspaceImpl workspace ) 
97     {
98     	this( null, workspace, true );
99     }
100    
101    public WsdlProject(String path, WorkspaceImpl workspace ) 
102    {
103    	this( path, workspace, true );
104    }
105    
106    public WsdlProject(String path, WorkspaceImpl workspace, boolean create ) 
107    {
108    	this( path, workspace, create, true, null );
109    }
110    
111    public WsdlProject(String path, WorkspaceImpl workspace, boolean create, boolean open, String tempName ) 
112    {
113    	super( null, workspace, "/project.gif" );
114    	
115       this.workspace = workspace;
116    	this.path = path;
117       
118    	try
119    	{
120 	   	if( path != null && open )
121 	   	{
122 		   	if( path.toLowerCase().startsWith( "http" ))
123 		   	{
124 		   		try
125 		 			{
126 		   			remote = true;
127 		 				loadProject( new URL( path ));
128 		 			}
129 		 			catch( MalformedURLException e )
130 		 			{
131 		 				SoapUI.logError( e );
132 		 			}
133 		   	}
134 				else
135 				{
136 					File file = new File( path );
137 					if( file.exists())
138 					{
139 					   try
140 						{
141 							loadProject( file.toURI().toURL());
142 							lastModified = file.lastModified();
143 						}
144 						catch( MalformedURLException e )
145 						{
146 			 				SoapUI.logError( e );
147 						}
148 					}
149 					else if( !create )
150 					{
151 						disabled = true;
152 					}
153 				}
154 		   }
155    	}
156    	catch( SoapUIException e )
157 		{
158    		SoapUI.logError( e );
159 			disabled = true;
160 		}
161    	finally
162    	{
163       	closedIcon = UISupport.createImageIcon( "/closedProject.gif" );
164       	remoteIcon = UISupport.createImageIcon( "/remoteProject.gif" );
165       	disabledIcon = UISupport.createImageIcon( "/disabledProject.gif" );
166       	
167       	this.open = open && !disabled;
168       	
169       	if( projectDocument == null )
170 	   	{
171 	   		projectDocument = SoapuiProjectDocumentConfig.Factory.newInstance();
172 			   setConfig( projectDocument.addNewSoapuiProject() );
173 			   if( tempName != null || path != null )
174 			   	getConfig().setName( StringUtils.isNullOrEmpty( tempName ) ? getNameFromPath() : tempName );
175 	   	}
176       	
177       	endpointStrategy.init( this );
178       	setProjectRoot(path);
179       	
180       	for( ProjectListener listener : SoapUI.getListenerRegistry().getListeners( ProjectListener.class ) )
181    		{
182    			addProjectListener( listener );
183    		}
184    	}
185    }
186    
187 	public boolean isRemote()
188 	{
189 		return remote;
190 	}
191 
192 	private void loadProject( URL file ) throws SoapUIException
193 	{
194 		try
195 		{
196 			UISupport.setHourglassCursor();
197 			
198 			UrlWsdlLoader loader = new UrlWsdlLoader( file.toString() );
199 			loader.setUseWorker( false );
200 			projectDocument = SoapuiProjectDocumentConfig.Factory.parse( loader.load() );
201 
202 			setConfig( projectDocument.getSoapuiProject() );
203 			
204 			// removed cached definitions if caching is disabled
205 			if( !getSettings().getBoolean( WsdlSettings.CACHE_WSDLS ))
206 			{
207 				removeDefinitionCaches( projectDocument );
208 			}
209 			
210 			log.info( "Loaded project from [" + file.toString() + "]" );
211 			 
212 			List<InterfaceConfig> interfaceConfigs = getConfig().getInterfaceList();
213 			for (InterfaceConfig config : interfaceConfigs)
214 			{
215 			   interfaces.add( new WsdlInterface( this, config ));
216 			}
217 
218 			List<TestSuiteConfig> testSuiteConfigs = getConfig().getTestSuiteList();
219 			for( TestSuiteConfig config : testSuiteConfigs )
220 			{
221 			   testSuites.add( new WsdlTestSuite( this, config ));
222 			}
223 			
224 			List<MockServiceConfig> mockServiceConfigs = getConfig().getMockServiceList();
225 			for( MockServiceConfig config : mockServiceConfigs )
226 			{
227 			   mockServices.add( new WsdlMockService( this, config ));
228 			}
229 			
230 			endpointStrategy.init( this );
231 		}
232 		catch (Exception e)
233 		{
234 			throw new SoapUIException( "Failed to create project from file [" + file.toString() + "]", e );
235 		}
236 		finally
237 		{
238 			UISupport.resetCursor();
239 		}
240 	}
241 
242 	private void setProjectRoot(String path)
243 	{
244 		if( path != null && projectDocument != null )
245       {
246       	int ix = path.lastIndexOf( File.separatorChar );
247       	if( ix > 0 )
248       		getSettings().setString( ProjectSettings.PROJECT_ROOT, path.substring( 0, ix ) );
249       }
250 	}
251 	
252 	@Override
253 	public ImageIcon getIcon()
254 	{
255 		if( isDisabled())
256 			return disabledIcon;
257 		else if( !isOpen() )
258 			return closedIcon;
259 		else if( isRemote() )
260 			return remoteIcon;
261 		else
262 			return super.getIcon();
263 	}
264 	
265 	private String getNameFromPath()
266 	{
267 		int ix = path.lastIndexOf( isRemote() ? '/' : File.separatorChar );
268 		String name = ix == -1 ? path : path.substring( ix+1 );
269 		return name;
270 	}
271 	
272 	@Override
273 	public String getDescription()
274 	{
275 		if( isOpen() )
276 			return super.getDescription();
277 		
278 		String name = getName();
279 		
280 		if( isDisabled() )
281 			name += " - disabled";
282 		else
283 			name += " - closed";
284 		
285 		return name;
286 	}
287 
288    public WorkspaceImpl getWorkspace()
289    {
290       return workspace;
291    }
292 
293 	public WsdlInterface getInterfaceAt(int index)
294    {
295       return interfaces.get( index );
296    }
297 
298    public WsdlInterface getInterfaceByName(String interfaceName)
299 	{
300 		return (WsdlInterface) getWsdlModelItemByName( interfaces, interfaceName );
301 	}
302 
303    public WsdlInterface getInterfaceByBindingName( QName bindingName )
304    {
305    	for( int c = 0; c < getInterfaceCount(); c++ )
306    	{
307    		if( getInterfaceAt( c ).getBindingName().equals( bindingName ))
308    			return getInterfaceAt( c );
309    	}
310    	
311    	return null;
312    }
313    
314 	public int getInterfaceCount()
315    {
316       return interfaces.size();
317    }
318 
319    public String getPath()
320 	{
321 		return path;
322 	}
323 
324 	public boolean save() throws IOException 
325    {
326 		if( !isOpen() || isDisabled() || isRemote() )
327 			return true;
328 		
329       if( path == null || isRemote())
330       {
331       	path = getName() + "-soapui-project.xml";
332       	File file = null;
333          
334          while( file == null || (file.exists() && !UISupport.confirm( "File [" + file.getName() + "] exists, overwrite?", "Overwrite File?" )))
335          {
336          	file = UISupport.getFileDialogs().saveAs(this, "Save project " + getName(), ".xml",
337       					"XML Files (*.xml)", new File( path ));
338             if( file == null ) return false;
339          }
340 
341          path = file.getAbsolutePath();
342       }
343       
344       File projectFile = new File( path );
345       
346       while( projectFile.exists() && !projectFile.canWrite() )
347       {
348       	if( UISupport.confirm( "Project file [" + path + "] can not be written to, save to new file?", "Save Project" ))
349       	{
350       		projectFile = UISupport.getFileDialogs().saveAs(this, "Save project " + getName(),".xml",
351       					"XML Files (*.xml)", projectFile );
352       		
353             if( projectFile == null ) return false;
354 
355             path = projectFile.getAbsolutePath();
356       	}
357       	else return false;
358       }
359       
360       // check modified 
361 		if( projectFile.exists() && lastModified != 0 && lastModified < projectFile.lastModified() )
362 		{
363 			if( !UISupport.confirm( 
364 						"Project file for [" + getName() + "] has been modified externally, overwrite?", 
365 						"Save Project" ))
366 				return false;
367 		}
368       
369    	long size = 0;
370    	
371    	if( projectFile.exists() && getSettings().getBoolean( UISettings.CREATE_BACKUP ))
372    	{
373    		createBackup( projectFile );
374    	}
375    	
376    	onSave();
377    	
378    	XmlOptions options = new XmlOptions();
379    	if( SoapUI.getSettings().getBoolean( WsdlSettings.PRETTY_PRINT_PROJECT_FILES ))
380    		options.setSavePrettyPrint();
381    	
382    	// check for caching
383    	if( !getSettings().getBoolean( WsdlSettings.CACHE_WSDLS ))
384    	{
385    		// no caching -> create copy and remove definition cachings
386    		SoapuiProjectDocumentConfig config = (SoapuiProjectDocumentConfig) projectDocument.copy();
387    		removeDefinitionCaches(config);
388    		
389    		config.getSoapuiProject().setSoapuiVersion( SoapUI.SOAPUI_VERSION );
390    		config.save( projectFile, options );
391    	}
392    	else
393    	{
394       	try
395 			{
396       		// save to temporary buffer to avoid corruption of file
397 				projectDocument.getSoapuiProject().setSoapuiVersion( SoapUI.SOAPUI_VERSION );
398 				ByteArrayOutputStream writer = new ByteArrayOutputStream( 8192 );
399 				projectDocument.save( writer, options );
400 				FileOutputStream out = new FileOutputStream( projectFile );
401 				writer.writeTo( out );
402 				out.close();
403 				size = writer.size();
404 			}
405 			catch (Throwable t)
406 			{
407 				SoapUI.logError( t );
408 				UISupport.showErrorMessage( "Failed to save project [" + getName() + "]: " + t.toString() );
409 				return false;
410 			}
411    	}
412    	
413    	lastModified = projectFile.lastModified();
414 		log.info( "Saved project [" + getName() + "] to [" + projectFile.getAbsolutePath() + " - " +
415 				size + " bytes" );
416 		setProjectRoot(path);
417 		return true;
418 }
419 
420 	public void onSave()
421 	{
422 		// notify
423    	for( WsdlInterface iface : interfaces )
424    		iface.onSave();
425    	
426    	for( WsdlTestSuite testSuite : testSuites )
427    		testSuite.onSave();
428    	
429    	for( WsdlMockService mockService : mockServices )
430    		mockService.onSave();
431    	
432   		endpointStrategy.onSave();
433 	}
434 
435 	private void createBackup(File projectFile) throws IOException
436 	{
437 		String backupFolderName = getSettings().getString( UISettings.BACKUP_FOLDER, "" );
438 		
439 		File backupFolder = new File( backupFolderName );
440 		if( !backupFolder.isAbsolute() )
441 		{
442 			backupFolder = new File( projectFile.getParentFile(), backupFolderName );
443 		}
444 		
445 		if( !backupFolder.exists() )
446 			backupFolder.mkdirs();
447 		
448 		File backupFile = new File( backupFolder, projectFile.getName() + ".backup" );
449 		log.info( "Backing up [" + projectFile + "] to [" + backupFile + "]" );
450 		
451 		Tools.copyFile( projectFile, backupFile, true );
452 	}
453 
454 	private void removeDefinitionCaches(SoapuiProjectDocumentConfig config)
455 	{
456 		for( InterfaceConfig ifaceConfig : config.getSoapuiProject().getInterfaceList() )
457 		{
458 			if( ifaceConfig.isSetDefinitionCache() )
459 			{
460 				log.info( "Removing definition cache from interface [" + ifaceConfig.getName() + "]" );
461 				ifaceConfig.unsetDefinitionCache();
462 			}
463 		}
464 	}
465 	
466 	public WsdlInterface [] importWsdl( String url, boolean createRequests ) throws SoapUIException
467 	{
468 		return importWsdl( url, createRequests, null, null );
469 	}
470    
471 	public WsdlInterface [] importWsdl( String url, boolean createRequests, WsdlLoader wsdlLoader ) throws SoapUIException
472 	{
473 		return importWsdl( url, createRequests, null, wsdlLoader );
474 	}
475 	
476    public WsdlInterface [] importWsdl( String url, boolean createRequests, QName bindingName, WsdlLoader wsdlLoader ) throws SoapUIException
477    {
478    	if( projectDocument == null )
479    		return null;
480    	
481    	WsdlInterface[] result;
482    	
483       try
484       {
485          result = WsdlImporter.getInstance().importWsdl( this, url, bindingName, wsdlLoader );
486       }
487       catch (Exception e)
488       {
489          log.error( "Error importing wsdl: " + e );
490          SoapUI.logError( e );
491          throw new SoapUIException( "Error importing wsdl", e );
492       }
493       
494       try
495       {      
496 			if( createRequests && result != null )
497          {
498          	for (WsdlInterface iface : result)
499 				{
500          		for( int c = 0; c < iface.getOperationCount(); c++ )
501          		{
502          			WsdlOperation operation = (WsdlOperation) iface.getOperationAt( c );
503          			WsdlRequest request = operation.addNewRequest( "Request 1");
504                   try
505                   {
506                      String requestContent = operation.createRequest( true );
507 							request.setRequestContent( requestContent);
508                   }
509                   catch (Exception e)
510                   {
511                      SoapUI.logError( e );
512                   }
513          		}
514 				}
515          }
516       }
517       catch (Exception e)
518       {
519       	log.error( "Error creating requests: " + e.getMessage() );
520          throw new SoapUIException( "Error creating requests", e );
521       }
522       
523       return result;
524    }
525    
526    public WsdlInterface addNewInterface( String name )
527    {
528       WsdlInterface iface = new WsdlInterface( this, getConfig().addNewInterface());
529       iface.setName( name );
530       interfaces.add( iface );
531       fireInterfaceAdded( iface );
532 
533       return iface;
534    }
535    
536    public void addProjectListener(ProjectListener listener)
537    {
538       projectListeners.add( listener );
539    }
540    
541    public void removeProjectListener(ProjectListener listener)
542    {
543       projectListeners.remove( listener );
544    }
545    
546    public void fireInterfaceAdded( WsdlInterface iface )
547    {
548       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
549       
550       for (int c = 0; c < a.length; c++ )
551       {
552          a[c].interfaceAdded( iface );
553       }
554    }
555    
556    public void fireInterfaceRemoved( WsdlInterface iface )
557    {
558       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
559       
560       for (int c = 0; c < a.length; c++ )
561       {
562          a[c].interfaceRemoved( iface );
563       }
564    }
565    
566    public void fireInterfaceUpdated( WsdlInterface iface )
567    {
568       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
569       
570       for (int c = 0; c < a.length; c++ )
571       {
572          a[c].interfaceUpdated( iface );
573       }
574    }
575    
576    public void fireTestSuiteAdded( WsdlTestSuite testSuite )
577    {
578       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
579       
580       for (int c = 0; c < a.length; c++ )
581       {
582          a[c].testSuiteAdded( testSuite );
583       }
584    }
585    
586    public void fireTestSuiteRemoved( WsdlTestSuite testSuite )
587    {
588       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
589       
590       for (int c = 0; c < a.length; c++ )
591       {
592          a[c].testSuiteRemoved( testSuite );
593       }
594    } 
595    
596    public void fireMockServiceAdded( WsdlMockService mockService )
597    {
598       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
599       
600       for (int c = 0; c < a.length; c++ )
601       {
602          a[c].mockServiceAdded( mockService );
603       }
604    }
605    
606    public void fireMockServiceRemoved( WsdlMockService mockService )
607    {
608       ProjectListener[] a = projectListeners.toArray( new ProjectListener[projectListeners.size()] );
609       
610       for (int c = 0; c < a.length; c++ )
611       {
612          a[c].mockServiceRemoved( mockService );
613       }
614    }
615    
616    public void removeInterface(WsdlInterface iface )
617    {
618       int ix = interfaces.indexOf( iface );
619       interfaces.remove( ix );
620       try
621       {
622       	fireInterfaceRemoved( iface );
623       }
624       finally
625       {
626       	iface.release();
627       	getConfig().removeInterface( ix );
628       }
629    }
630    
631    public void removeTestSuite(WsdlTestSuite testSuite )
632    {
633       int ix = testSuites.indexOf( testSuite );
634       testSuites.remove( ix );
635       
636       try
637       {
638       	fireTestSuiteRemoved( testSuite );
639       }
640       finally
641       {
642       	testSuite.release();
643       	getConfig().removeTestSuite( ix );
644       }
645    }
646 
647    public boolean isDisabled()
648    {
649    	return disabled;
650    }
651    
652    public int getTestSuiteCount()
653    {
654       return testSuites.size();
655    }
656 
657    public WsdlTestSuite getTestSuiteAt(int index)
658    {
659       return testSuites.get( index );
660    }
661 
662    public WsdlTestSuite getTestSuiteByName(String testSuiteName)
663 	{
664 		return  ( WsdlTestSuite ) getWsdlModelItemByName( testSuites, testSuiteName );
665 	}
666 
667    public WsdlTestSuite addNewTestSuite(String name)
668    {
669       WsdlTestSuite testSuite = new WsdlTestSuite( this, getConfig().addNewTestSuite());
670       testSuite.setName( name );
671       testSuites.add( testSuite );
672       fireTestSuiteAdded( testSuite );
673 
674       return testSuite;
675    }
676 
677 	public WsdlTestSuite cloneTestSuite(WsdlTestSuite testSuite, String name)
678 	{
679 		testSuite.onSave();
680 		TestSuiteConfig testSuiteConfig = getConfig().addNewTestSuite();
681 		testSuiteConfig.set( testSuite.getConfig() );
682 		WsdlTestSuite newTestSuite = new WsdlTestSuite( this, testSuiteConfig );
683 		newTestSuite.setName( name );
684       testSuites.add( newTestSuite );
685       fireTestSuiteAdded( newTestSuite );
686 
687       return newTestSuite;
688 	}
689 	
690 	public boolean isCacheDefinitions()
691 	{
692 		return getSettings().getBoolean( WsdlSettings.CACHE_WSDLS );
693 	}
694 	
695 	public void setCacheDefinitions( boolean cacheDefinitions )
696 	{
697 		getSettings().setBoolean( WsdlSettings.CACHE_WSDLS, cacheDefinitions );
698 	}
699 
700 	public boolean saveTo(String fileName) throws IOException
701 	{
702 		if( !isOpen() || isDisabled() )
703 			return false;
704 		
705 		String oldPath = path;
706 		path = fileName;
707 		boolean result = save();
708 		if( !result )
709 			path = oldPath;
710 		else
711 			remote = false;
712 		
713 		setProjectRoot(path);
714 		
715 		return result;
716 	}
717 
718 	public void release()
719 	{
720 		super.release();
721 		
722 		if( isOpen() )
723 		{
724 			endpointStrategy.release();
725 			
726 			for( WsdlTestSuite testSuite : testSuites )
727 				testSuite.release();
728 	
729 			for( WsdlInterface iface : interfaces )
730 				iface.release();
731 			
732 			for( WsdlMockService mockService : mockServices )
733 				mockService.release();
734 		}
735 		
736 		projectListeners.clear();
737 	}
738 
739 	public WsdlMockService cloneMockService( WsdlMockService mockService, String name )
740 	{
741 		mockService.onSave();
742 		MockServiceConfig testSuiteConfig = getConfig().addNewMockService();
743 		testSuiteConfig.set( mockService.getConfig() );
744 		WsdlMockService newMockService = new WsdlMockService( this, testSuiteConfig );
745 		newMockService.setName( name );
746       mockServices.add( newMockService );
747       fireMockServiceAdded( newMockService );
748 
749       return newMockService;
750 	}
751 	
752 	public WsdlMockService addNewMockService( String name )
753 	{
754 		WsdlMockService mockService = new WsdlMockService( this, getConfig().addNewMockService());
755       mockService.setName( name );
756       mockServices.add( mockService );
757       fireMockServiceAdded( mockService );
758 
759       return mockService;
760 	}
761 
762 	public WsdlMockService getMockServiceAt( int index )
763 	{
764 		return mockServices.get( index );
765 	}
766 
767 	public WsdlMockService getMockServiceByName( String mockServiceName )
768 	{
769 		return (WsdlMockService) getWsdlModelItemByName( mockServices, mockServiceName );
770 	}
771 
772 	public int getMockServiceCount()
773 	{
774 		return mockServices.size();
775 	}
776 
777 	public void removeMockService(WsdlMockService mockService )
778    {
779       int ix = mockServices.indexOf( mockService );
780       mockServices.remove( ix );
781       
782       try
783       {
784       	fireMockServiceRemoved( mockService );
785       }
786       finally
787       {
788       	mockService.release();
789       	getConfig().removeMockService( ix );
790       }
791    }
792 
793 	public List<TestSuite> getTestSuites()
794 	{
795 		return new ArrayList<TestSuite>( testSuites );
796 	}
797 
798 	public List<MockService> getMockServices()
799 	{
800 		return new ArrayList<MockService>( mockServices );
801 	}
802 
803 	public List<Interface> getInterfaces()
804 	{
805 		return new ArrayList<Interface>( interfaces );
806 	}
807 
808 	public void reload() throws SoapUIException
809 	{
810 		reload( path );
811 	}
812 	
813 	public void reload( String path ) throws SoapUIException
814 	{
815 		this.path = path;
816 		getWorkspace().reloadProject( this );
817 	}
818 
819    public boolean hasNature(String natureId)
820    {
821       Settings projectSettings = getSettings();
822       String projectNature = projectSettings.getString( ProjectSettings.PROJECT_NATURE, null );
823       return natureId.equals(projectNature);
824    }
825 
826 	public WsdlInterface importInterface( WsdlInterface iface, boolean importEndpoints )
827 	{
828 		iface.onSave();
829 		InterfaceConfig ifaceConfig = ( InterfaceConfig ) getConfig().addNewInterface().set( iface.getConfig().copy());
830 		WsdlInterface imported = new WsdlInterface( this, ifaceConfig );
831       interfaces.add( imported );
832       
833       if( iface.getProject() != this && importEndpoints )
834       {
835       	endpointStrategy.importEndpoints( iface );
836       }
837       
838       fireInterfaceAdded( imported );
839 
840       return imported;
841 	}
842 
843 	public WsdlTestSuite importTestSuite( WsdlTestSuite testSuite, String name )
844 	{
845 		testSuite.onSave();
846 		TestSuiteConfig testSuiteConfig = ( TestSuiteConfig ) getConfig().addNewTestSuite().set( testSuite.getConfig().copy() );
847 		testSuiteConfig.setName( name );
848 		testSuite = new WsdlTestSuite( this, testSuiteConfig );
849       testSuites.add( testSuite );
850       fireTestSuiteAdded( testSuite );
851 
852 		return testSuite;
853 	}
854 
855 	public WsdlMockService importMockService( WsdlMockService mockService, String name )
856 	{
857 		mockService.onSave();
858 		MockServiceConfig mockServiceConfig = ( MockServiceConfig ) getConfig().addNewMockService().set( mockService.getConfig().copy() );
859 		mockServiceConfig.setName( name );
860 		mockService = new WsdlMockService( this, mockServiceConfig);
861       mockServices.add( mockService );
862       fireMockServiceAdded( mockService );
863 
864       return mockService;
865 	}
866 
867 	public EndpointStrategy getEndpointStrategy()
868 	{
869 		return endpointStrategy;
870 	}
871 
872 	public boolean isOpen()
873 	{
874 		return open;
875 	}
876 }