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;
13 import java.io.BufferedReader;
14 import java.io.ByteArrayInputStream;
15 import java.io.InputStreamReader;
16 import java.util.List;
18 import net.sourceforge.phpdt.monitor.core.internal.MonitorManager;
19 import net.sourceforge.phpdt.monitor.core.internal.MonitorPlugin;
20 import net.sourceforge.phpdt.monitor.core.internal.Trace;
24 public class MonitorCore {
25 public static String TCPIP_PROTOCOL_ID = "TCPIP";
26 public static String HTTP_PROTOCOL_ID = "HTTP";
28 private static MonitorManager manager = MonitorManager.getInstance();
30 private static final String lineSeparator = System.getProperty("line.separator");
33 * Return a list of all the existing monitors.
35 * @return java.util.List
37 public static List getMonitors() {
38 return manager.getMonitors();
42 * Create a new monitor.
44 * @return working copy
46 public static IMonitorWorkingCopy createMonitor() {
47 return manager.createMonitor();
51 * Start the given monitor.
56 public static void startMonitor(IMonitor monitor) throws Exception {
57 manager.startMonitor(monitor);
61 * Stop the given monitor.
65 public static void stopMonitor(IMonitor monitor) {
66 manager.stopMonitor(monitor);
70 * Return the protocol adapters.
72 * @return array of protocol adapters
74 public static IProtocolAdapter[] getProtocolAdapters() {
75 return MonitorPlugin.getInstance().getProtocolAdapters();
79 * Return the protocol adapter with the given id.
81 * @return protocol adapter
83 public static IProtocolAdapter getProtocolAdapter(String id) {
84 return MonitorPlugin.getInstance().getProtocolAdapter(id);
88 * Return the content filters.
90 * @return array of content filters
92 public static IContentFilter[] getContentFilters() {
93 return MonitorPlugin.getInstance().getContentFilters();
97 * Return the content filter with the given id.
99 * @return content filter
101 public static IContentFilter getContentFilter(String id) {
102 return MonitorPlugin.getInstance().getContentFilter(id);
106 * Add monitor listener.
110 public static void addMonitorListener(IMonitorListener listener) {
111 manager.addMonitorListener(listener);
115 * Remove monitor listener.
119 public static void removeMonitorListener(IMonitorListener listener) {
120 manager.removeMonitorListener(listener);
124 * Return all requests.
128 public static List getRequests() {
129 return manager.getRequests();
133 * Remove all requests.
135 public static void removeAllRequests() {
136 manager.removeAllRequests();
140 * Add request listener.
144 public static void addRequestListener(IRequestListener listener) {
145 manager.addRequestListener(listener);
149 * Remove request listener.
153 public static void removeRequestListener(IRequestListener listener) {
154 manager.removeRequestListener(listener);
158 * Parse the given bytes into String form.
163 public static String parse(byte[] b) {
167 ByteArrayInputStream bin = new ByteArrayInputStream(b);
168 BufferedReader br = new BufferedReader(new InputStreamReader(bin));
169 StringBuffer sb = new StringBuffer();
171 String s = br.readLine();
177 sb.append(lineSeparator);
179 sb.append(lineSeparator);
180 } catch (Exception e) {
181 Trace.trace(Trace.SEVERE, "Error parsing input", e);
184 return sb.toString();