1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.monitor.core.internal;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.List;
19 import net.sourceforge.phpdt.monitor.core.IContentFilter;
20 import net.sourceforge.phpdt.monitor.core.IProtocolAdapter;
21 import net.sourceforge.phpdt.monitor.core.IRequestListener;
23 import org.eclipse.core.runtime.IConfigurationElement;
24 import org.eclipse.core.runtime.IExtensionRegistry;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.core.runtime.Plugin;
28 * The monitor core plugin.
30 public class MonitorPlugin extends Plugin {
31 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.core";
33 private static MonitorPlugin singleton;
35 protected Map protocolAdapters;
36 protected Map contentFilters;
37 protected IRequestListener[] requestListeners;
40 * MonitorPlugin constructor comment.
42 public MonitorPlugin() {
45 loadProtocolAdapters();
50 * Returns the singleton instance of this plugin.
52 * @return net.sourceforge.phpdt.monitor.core.MonitorPlugin
54 public static MonitorPlugin getInstance() {
59 * Returns the translated String found with the given key.
61 * @return java.lang.String
62 * @param key java.lang.String
64 public static String getString(String key) {
66 return Platform.getResourceString(getInstance().getBundle(), key);
67 } catch (Exception e) {
72 public IProtocolAdapter getDefaultType() {
73 return (ProtocolAdapter) protocolAdapters.get("HTTP");
76 public IProtocolAdapter getProtocolAdapter(String id) {
77 return (ProtocolAdapter) protocolAdapters.get(id);
80 public IProtocolAdapter[] getProtocolAdapters() {
81 List list = new ArrayList();
82 Iterator iterator = protocolAdapters.values().iterator();
83 while (iterator.hasNext()) {
84 list.add(iterator.next());
86 IProtocolAdapter[] types = new IProtocolAdapter[list.size()];
91 public IContentFilter[] getContentFilters() {
92 List list = new ArrayList();
93 Iterator iterator = contentFilters.values().iterator();
94 while (iterator.hasNext()) {
95 list.add(iterator.next());
97 IContentFilter[] cf = new IContentFilter[list.size()];
102 public IContentFilter getContentFilter(String id) {
103 return (IContentFilter) contentFilters.get(id);
106 public IRequestListener[] getRequestListeners() {
107 if (requestListeners == null)
108 loadRequestListeners();
109 return requestListeners;
112 public void loadProtocolAdapters() {
113 Trace.trace(Trace.CONFIG, "Loading protocol adapters");
114 IExtensionRegistry registry = Platform.getExtensionRegistry();
115 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "protocolAdapters");
117 int size = cf.length;
118 protocolAdapters = new HashMap(size);
119 for (int i = 0; i < size; i++) {
120 String id = cf[i].getAttribute("id");
121 Trace.trace(Trace.CONFIG, "Loading adapter: " + id);
122 protocolAdapters.put(id, new ProtocolAdapter(cf[i]));
126 public void loadContentFilters() {
127 Trace.trace(Trace.CONFIG, "Loading content filters");
128 IExtensionRegistry registry = Platform.getExtensionRegistry();
129 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "contentFilters");
131 int size = cf.length;
132 contentFilters = new HashMap(size);
133 for (int i = 0; i < size; i++) {
134 String id = cf[i].getAttribute("id");
135 Trace.trace(Trace.CONFIG, "Loading filter: " + id);
136 contentFilters.put(id, new ContentFilter(cf[i]));
140 public void loadRequestListeners() {
141 Trace.trace(Trace.CONFIG, "Loading request listeners");
142 IExtensionRegistry registry = Platform.getExtensionRegistry();
143 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "requestListeners");
145 int size = cf.length;
146 List list = new ArrayList();
147 for (int i = 0; i < size; i++) {
148 String id = cf[i].getAttribute("id");
149 Trace.trace(Trace.CONFIG, "Loading request listener: " + id);
151 IRequestListener rl = (IRequestListener) cf[i].createExecutableExtension("class");
153 } catch (Exception e) {
154 Trace.trace(Trace.SEVERE, "Could not create request listener: " + id, e);
160 requestListeners = new IRequestListener[size];
161 list.toArray(requestListeners);