View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.support.editor.registry;
14  
15  import java.util.ArrayList;
16  import java.util.Arrays;
17  import java.util.List;
18  
19  import com.eviware.soapui.impl.rest.panels.request.views.html.HttpHtmlResponseViewFactory;
20  import com.eviware.soapui.impl.rest.panels.request.views.json.JsonResponseViewFactory;
21  import com.eviware.soapui.impl.support.http.HttpRequestContentViewFactory;
22  import com.eviware.soapui.support.editor.views.xml.raw.RawXmlEditorFactory;
23  import com.eviware.soapui.support.editor.views.xml.source.XmlSourceEditorViewFactory;
24  
25  /***
26   * Registry of availabel XmlViews
27   * 
28   * @author ole.matzura
29   */
30  
31  public class EditorViewFactoryRegistry
32  {
33  	private static EditorViewFactoryRegistry instance;
34  	private List<EditorViewFactory> factories = new ArrayList<EditorViewFactory>();
35  
36  	public EditorViewFactoryRegistry()
37  	{
38  		// this should obviously come from a configuration file..
39  		addFactory( new XmlSourceEditorViewFactory() );
40  		// addFactory( new RestRequestParamsViewFactory() );
41  		addFactory( new HttpRequestContentViewFactory() );
42  		addFactory( new JsonResponseViewFactory() );
43  		addFactory( new HttpHtmlResponseViewFactory() );
44  		addFactory( new RawXmlEditorFactory() );
45  	}
46  
47  	public void addFactory( EditorViewFactory factory )
48  	{
49  		factories.add( factory );
50  	}
51  
52  	public void setFactory( String viewId, EditorViewFactory factory )
53  	{
54  		for( int c = 0; c < factories.size(); c++ )
55  		{
56  			if( factories.get( c ).getViewId().equals( viewId ) )
57  			{
58  				factories.set( c, factory );
59  			}
60  		}
61  	}
62  
63  	public static final EditorViewFactoryRegistry getInstance()
64  	{
65  		if( instance == null )
66  			instance = new EditorViewFactoryRegistry();
67  
68  		return instance;
69  	}
70  
71  	public EditorViewFactory[] getFactories()
72  	{
73  		return factories.toArray( new EditorViewFactory[factories.size()] );
74  	}
75  
76  	public EditorViewFactory[] getFactoriesOfType( Class<?> type )
77  	{
78  		List<EditorViewFactory> result = new ArrayList<EditorViewFactory>();
79  		for( EditorViewFactory factory : factories )
80  		{
81  			if( Arrays.asList( factory.getClass().getInterfaces() ).contains( type ) )
82  				result.add( factory );
83  		}
84  
85  		return result.toArray( new EditorViewFactory[result.size()] );
86  	}
87  }