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