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;
15 import net.sourceforge.phpdt.monitor.core.IContentFilter;
16 import net.sourceforge.phpdt.monitor.core.IProtocolAdapter;
17 import net.sourceforge.phpdt.monitor.core.IRequestListener;
19 import org.eclipse.core.runtime.*;
21 * The monitor core plugin.
23 public class MonitorPlugin extends Plugin {
24 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.monitor.core";
26 private static MonitorPlugin singleton;
28 protected Map protocolAdapters;
29 protected Map contentFilters;
30 protected IRequestListener[] requestListeners;
33 * MonitorPlugin constructor comment.
35 public MonitorPlugin() {
38 loadProtocolAdapters();
43 * Returns the singleton instance of this plugin.
45 * @return net.sourceforge.phpdt.monitor.core.MonitorPlugin
47 public static MonitorPlugin getInstance() {
52 * Returns the translated String found with the given key.
54 * @return java.lang.String
55 * @param key java.lang.String
57 public static String getString(String key) {
59 return Platform.getResourceString(getInstance().getBundle(), key);
60 } catch (Exception e) {
65 public IProtocolAdapter getDefaultType() {
66 return (ProtocolAdapter) protocolAdapters.get("HTTP");
69 public IProtocolAdapter getProtocolAdapter(String id) {
70 return (ProtocolAdapter) protocolAdapters.get(id);
73 public IProtocolAdapter[] getProtocolAdapters() {
74 List list = new ArrayList();
75 Iterator iterator = protocolAdapters.values().iterator();
76 while (iterator.hasNext()) {
77 list.add(iterator.next());
79 IProtocolAdapter[] types = new IProtocolAdapter[list.size()];
84 public IContentFilter[] getContentFilters() {
85 List list = new ArrayList();
86 Iterator iterator = contentFilters.values().iterator();
87 while (iterator.hasNext()) {
88 list.add(iterator.next());
90 IContentFilter[] cf = new IContentFilter[list.size()];
95 public IContentFilter getContentFilter(String id) {
96 return (IContentFilter) contentFilters.get(id);
99 public IRequestListener[] getRequestListeners() {
100 if (requestListeners == null)
101 loadRequestListeners();
102 return requestListeners;
105 public void loadProtocolAdapters() {
106 Trace.trace(Trace.CONFIG, "Loading protocol adapters");
107 IExtensionRegistry registry = Platform.getExtensionRegistry();
108 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "protocolAdapters");
110 int size = cf.length;
111 protocolAdapters = new HashMap(size);
112 for (int i = 0; i < size; i++) {
113 String id = cf[i].getAttribute("id");
114 Trace.trace(Trace.CONFIG, "Loading adapter: " + id);
115 protocolAdapters.put(id, new ProtocolAdapter(cf[i]));
119 public void loadContentFilters() {
120 Trace.trace(Trace.CONFIG, "Loading content filters");
121 IExtensionRegistry registry = Platform.getExtensionRegistry();
122 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "contentFilters");
124 int size = cf.length;
125 contentFilters = new HashMap(size);
126 for (int i = 0; i < size; i++) {
127 String id = cf[i].getAttribute("id");
128 Trace.trace(Trace.CONFIG, "Loading filter: " + id);
129 contentFilters.put(id, new ContentFilter(cf[i]));
133 public void loadRequestListeners() {
134 Trace.trace(Trace.CONFIG, "Loading request listeners");
135 IExtensionRegistry registry = Platform.getExtensionRegistry();
136 IConfigurationElement[] cf = registry.getConfigurationElementsFor(MonitorPlugin.PLUGIN_ID, "requestListeners");
138 int size = cf.length;
139 List list = new ArrayList();
140 for (int i = 0; i < size; i++) {
141 String id = cf[i].getAttribute("id");
142 Trace.trace(Trace.CONFIG, "Loading request listener: " + id);
144 IRequestListener rl = (IRequestListener) cf[i].createExecutableExtension("class");
146 } catch (Exception e) {
147 Trace.trace(Trace.SEVERE, "Could not create request listener: " + id, e);
153 requestListeners = new IRequestListener[size];
154 list.toArray(requestListeners);