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