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.inspectors.registry;
14  
15  import java.util.ArrayList;
16  import java.util.Arrays;
17  import java.util.List;
18  
19  /***
20   * Registry of registered XmlInspectorFactories
21   * 
22   * @author ole.matzura
23   */
24  
25  public class XmlInspectorRegistry
26  {
27  	private static XmlInspectorRegistry instance;
28  	private List<XmlInspectorFactory> factories = new ArrayList<XmlInspectorFactory>();
29  	
30  	public XmlInspectorRegistry()
31  	{
32  	}
33  	
34  	public void addFactory( XmlInspectorFactory factory )
35  	{
36  		for( XmlInspectorFactory f : factories )
37  			if( f.getInspectorId().equals( factory.getInspectorId() ))
38  				return;
39  		
40  		factories.add( factory );
41  	}
42  
43  	public static final XmlInspectorRegistry getInstance()
44  	{
45  		if( instance == null )
46  			instance = new XmlInspectorRegistry();
47  		
48  		return instance;
49  	}
50  	
51  	public void removeFactory( XmlInspectorFactory factory )
52  	{
53  		factories.remove( factory );
54  	}
55  	
56  	public XmlInspectorFactory [] getFactories()
57  	{
58  		return factories.toArray( new XmlInspectorFactory[factories.size()] );
59  	}
60  	
61  	public XmlInspectorFactory [] getFactoriesOfType( Class type )
62  	{
63  		List<XmlInspectorFactory> result = new ArrayList<XmlInspectorFactory>();
64  		for( XmlInspectorFactory factory : factories )
65  		{
66  			if( Arrays.asList( factory.getClass().getInterfaces() ).contains( type )) 
67  				result.add( factory );
68  		}
69  		
70  		return result.toArray( new XmlInspectorFactory[result.size()] );
71  	}
72  }