01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private static XmlEditorViewRegistry instance;
29: private List<XmlEditorViewFactory> factories = new ArrayList<XmlEditorViewFactory>();
30:
31: public XmlEditorViewRegistry() {
32: addFactory(new XmlSourceEditorFactory());
33: }
34:
35: public void addFactory(XmlEditorViewFactory factory) {
36: factories.add(factory);
37: }
38:
39: public void setFactory(String viewId, XmlEditorViewFactory factory) {
40: for (int c = 0; c < factories.size(); c++) {
41: if (factories.get(c).getViewId().equals(viewId)) {
42: factories.set(c, factory);
43: }
44: }
45: }
46:
47: public static final XmlEditorViewRegistry getInstance() {
48: if (instance == null)
49: instance = new XmlEditorViewRegistry();
50:
51: return instance;
52: }
53:
54: public XmlEditorViewFactory[] getFactories() {
55: return factories.toArray(new XmlEditorViewFactory[factories
56: .size()]);
57: }
58:
59: public XmlEditorViewFactory[] getFactoriesOfType(Class type) {
60: List<XmlEditorViewFactory> result = new ArrayList<XmlEditorViewFactory>();
61: for (XmlEditorViewFactory factory : factories) {
62: if (Arrays.asList(factory.getClass().getInterfaces())
63: .contains(type))
64: result.add(factory);
65: }
66:
67: return result.toArray(new XmlEditorViewFactory[result.size()]);
68: }
69: }
|