View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.List;
17  
18  /***
19   * Registry of registered XmlInspectorFactories
20   * 
21   * @author ole.matzura
22   */
23  
24  public class InspectorRegistry
25  {
26  	private static InspectorRegistry instance;
27  	private List<InspectorFactory> factories = new ArrayList<InspectorFactory>();
28  	
29  	public InspectorRegistry()
30  	{
31  	}
32  	
33  	public void addFactory( InspectorFactory factory )
34  	{
35  		for( int c = 0; c < factories.size(); c++  )
36  		{
37  			InspectorFactory f = factories.get( c );
38  			if( f.getInspectorId().equals( factory.getInspectorId() ))
39  			{
40  				factories.set( c, factory );
41  				return;
42  			}
43  		}
44  		
45  		factories.add( factory );
46  	}
47  
48  	public static final InspectorRegistry getInstance()
49  	{
50  		if( instance == null )
51  			instance = new InspectorRegistry();
52  		
53  		return instance;
54  	}
55  	
56  	public void removeFactory( InspectorFactory factory )
57  	{
58  		factories.remove( factory );
59  	}
60  	
61  	public InspectorFactory [] getFactories()
62  	{
63  		return factories.toArray( new InspectorFactory[factories.size()] );
64  	}
65  	
66  	public InspectorFactory [] getFactoriesOfType( Class<?> type )
67  	{
68  		List<InspectorFactory> result = new ArrayList<InspectorFactory>();
69  		for( InspectorFactory factory : factories )
70  		{
71  			if( type.isAssignableFrom( factory.getClass())) 
72  				result.add( factory );
73  		}
74  		
75  		return result.toArray( new InspectorFactory[result.size()] );
76  	}
77  }