inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.core / src / net / sourceforge / phpdt / monitor / core / internal / Monitor.java
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
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.core.internal;
12
13 import net.sourceforge.phpdt.monitor.core.*;
14 /**
15  * 
16  */
17 public class Monitor implements IMonitor {
18         private static final String MEMENTO_ID = "id";
19         private static final String MEMENTO_LOCAL_PORT = "local-port";
20         private static final String MEMENTO_REMOTE_HOST = "remote-host";
21         private static final String MEMENTO_REMOTE_PORT = "remote-port";
22         private static final String MEMENTO_TYPE_ID = "type-id";
23
24         protected String id;
25         protected String remoteHost;
26         protected int remotePort = 80;
27         protected int localPort = 80;
28         protected IProtocolAdapter type;
29         
30         public Monitor() {
31                 type = MonitorPlugin.getInstance().getDefaultType();
32         }
33         
34         /* (non-Javadoc)
35          * @see org.eclipse.monitor.internal.IMonitor#getId()
36          */
37         public String getId() {
38                 return id;
39         }
40
41         /* (non-Javadoc)
42          * @see org.eclipse.monitor.internal.IMonitor#getRemoteHost()
43          */
44         public String getRemoteHost() {
45                 return remoteHost;
46         }
47
48         /* (non-Javadoc)
49          * @see org.eclipse.monitor.internal.IMonitor#getRemotePort()
50          */
51         public int getRemotePort() {
52                 return remotePort;
53         }
54
55         /* (non-Javadoc)
56          * @see org.eclipse.monitor.internal.IMonitor#getLocalPort()
57          */
58         public int getLocalPort() {
59                 return localPort;
60         }
61
62         /* (non-Javadoc)
63          * @see org.eclipse.monitor.internal.IMonitor#isHTTPEnabled()
64          */
65         public IProtocolAdapter getProtocolAdapter() {
66                 return type;
67         }
68
69         /* (non-Javadoc)
70          * @see org.eclipse.monitor.internal.IMonitor#isRunning()
71          */
72         public boolean isRunning() {
73                 return MonitorManager.getInstance().isRunning(this);
74         }
75         
76         public void delete() {
77                 MonitorManager.getInstance().removeMonitor(this);
78         }
79
80         public boolean isWorkingCopy() {
81                 return false;
82         }
83         
84         public IMonitorWorkingCopy getWorkingCopy() {
85                 return new MonitorWorkingCopy(this);
86         }
87         
88         protected void setInternal(IMonitor monitor) {
89                 id = monitor.getId();
90                 remoteHost = monitor.getRemoteHost();
91                 remotePort = monitor.getRemotePort();
92                 localPort = monitor.getLocalPort();
93                 type = monitor.getProtocolAdapter();
94         }
95         
96         protected void save(IMemento memento) {
97                 memento.putString(MEMENTO_ID, id);
98                 memento.putString(MEMENTO_TYPE_ID, type.getId());
99                 memento.putInteger(MEMENTO_LOCAL_PORT, localPort);
100                 memento.putString(MEMENTO_REMOTE_HOST, remoteHost);
101                 memento.putInteger(MEMENTO_REMOTE_PORT, remotePort);
102         }
103
104         protected void load(IMemento memento) {
105                 id = memento.getString(MEMENTO_ID);
106                 type = MonitorPlugin.getInstance().getProtocolAdapter(memento.getString(MEMENTO_TYPE_ID));
107                 Integer temp = memento.getInteger(MEMENTO_LOCAL_PORT);
108                 if (temp != null)
109                         localPort = temp.intValue();
110                 remoteHost = memento.getString(MEMENTO_REMOTE_HOST);
111                 temp = memento.getInteger(MEMENTO_REMOTE_PORT);
112                 if (temp != null)
113                         remotePort = temp.intValue();
114         }
115 }