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.panels.request.components.editor.views.registry;
14  
15  import java.util.ArrayList;
16  import java.util.Arrays;
17  import java.util.List;
18  
19  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.views.source.XmlSourceEditorFactory;
20  
21  public class XmlEditorViewRegistry
22  {
23  	private static XmlEditorViewRegistry instance;
24  	private List<XmlEditorViewFactory> factories = new ArrayList<XmlEditorViewFactory>();
25  	
26  	public XmlEditorViewRegistry()
27  	{
28  		addFactory( new XmlSourceEditorFactory() );
29  	}
30  	
31  	public void addFactory( XmlEditorViewFactory factory )
32  	{
33  		factories.add( factory );
34  	}
35  
36  	public void setFactory( String viewId, XmlEditorViewFactory factory )
37  	{
38  		for( int c = 0; c < factories.size(); c++ )
39  		{
40  			if( factories.get( c ).getViewId().equals( viewId ))
41  			{
42  				factories.set( c, factory );
43  			}
44  		}
45  	}
46  	
47  	public static final XmlEditorViewRegistry getInstance()
48  	{
49  		if( instance == null )
50  			instance = new XmlEditorViewRegistry();
51  		
52  		return instance;
53  	}
54  	
55  	public XmlEditorViewFactory [] getFactories()
56  	{
57  		return factories.toArray( new XmlEditorViewFactory[factories.size()] );
58  	}
59  	
60  	public XmlEditorViewFactory [] getFactoriesOfType( Class type )
61  	{
62  		List<XmlEditorViewFactory> result = new ArrayList<XmlEditorViewFactory>();
63  		for( XmlEditorViewFactory factory : factories )
64  		{
65  			if( Arrays.asList( factory.getClass().getInterfaces() ).contains( type )) 
66  				result.add( factory );
67  		}
68  		
69  		return result.toArray( new XmlEditorViewFactory[result.size()] );
70  	}
71  }