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  /***
22   * Registry of availabel XmlViews
23   * 
24   * @author ole.matzura
25   */
26  
27  public class XmlEditorViewRegistry
28  {
29  	private static XmlEditorViewRegistry instance;
30  	private List<XmlEditorViewFactory> factories = new ArrayList<XmlEditorViewFactory>();
31  	
32  	public XmlEditorViewRegistry()
33  	{
34  		addFactory( new XmlSourceEditorFactory() );
35  	}
36  	
37  	public void addFactory( XmlEditorViewFactory factory )
38  	{
39  		factories.add( factory );
40  	}
41  
42  	public void setFactory( String viewId, XmlEditorViewFactory factory )
43  	{
44  		for( int c = 0; c < factories.size(); c++ )
45  		{
46  			if( factories.get( c ).getViewId().equals( viewId ))
47  			{
48  				factories.set( c, factory );
49  			}
50  		}
51  	}
52  	
53  	public static final XmlEditorViewRegistry getInstance()
54  	{
55  		if( instance == null )
56  			instance = new XmlEditorViewRegistry();
57  		
58  		return instance;
59  	}
60  	
61  	public XmlEditorViewFactory [] getFactories()
62  	{
63  		return factories.toArray( new XmlEditorViewFactory[factories.size()] );
64  	}
65  	
66  	public XmlEditorViewFactory [] getFactoriesOfType( Class type )
67  	{
68  		List<XmlEditorViewFactory> result = new ArrayList<XmlEditorViewFactory>();
69  		for( XmlEditorViewFactory factory : factories )
70  		{
71  			if( Arrays.asList( factory.getClass().getInterfaces() ).contains( type )) 
72  				result.add( factory );
73  		}
74  		
75  		return result.toArray( new XmlEditorViewFactory[result.size()] );
76  	}
77  }