Organized imports
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.core / src / net / sourceforge / phpdt / monitor / core / internal / http / HTTPConnection.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.http;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import net.sourceforge.phpdt.monitor.core.IMonitor;
17 import net.sourceforge.phpdt.monitor.core.IRequest;
18 import net.sourceforge.phpdt.monitor.core.internal.Request;
19 import net.sourceforge.phpdt.monitor.core.internal.Trace;
20 /**
21  * Manages a monitor server connection between two hosts. This
22  * connection may spawn one or more TCP/IP pairs to be displayed
23  * in the monitor server view.
24  */
25 public class HTTPConnection {
26         protected IMonitor monitor;
27
28         protected int req = -1;
29         protected int resp = -1;
30
31         protected List calls = new ArrayList();
32
33         /**
34          * MonitorHTTPConnection constructor comment.
35          */
36         public HTTPConnection(IMonitor monitor) {
37                 super();
38                 this.monitor = monitor;
39                 Trace.trace(Trace.PARSING, "TCP/IP monitor connection opened " + monitor);
40         }
41
42         /**
43          * Add a request.
44          * @param req byte[]
45          * @param isNew boolean
46          */
47         public void addRequest(byte[] request, boolean isNew) {
48                 if (isNew)
49                         req ++;
50                 Request pair = (Request) getRequestResponse(req);
51                 pair.addToRequest(request);
52         }
53
54         /**
55          * Add a response.
56          * @param req byte[]
57          * @param isNew boolean
58          */
59         public void addResponse(byte[] response, boolean isNew) {
60                 if (isNew)
61                         resp ++;
62                 Request pair = (Request) getRequestResponse(resp);
63                 pair.addToResponse(response);
64         }
65
66         /**
67          * 
68          */
69         public void addProperty(String key, Object value) {
70                 IRequest pair = getRequestResponse(req);
71                 pair.addProperty(key, value);
72         }
73
74         /**
75          * 
76          */
77         public IRequest getRequestResponse(boolean isRequest) {
78                 if (isRequest)
79                         return getRequestResponse(req);
80                 else
81                         return getRequestResponse(resp);
82         }
83
84         /**
85          * 
86          */
87         protected IRequest getRequestResponse(int i) {
88                 synchronized (this) {
89                         while (i >= calls.size()) {
90                                 Request rr = new HTTPRequest(monitor.getLocalPort(), monitor.getRemoteHost(), monitor.getRemotePort());
91                                 calls.add(rr);
92                                 return rr;
93                         }
94                         return (Request) calls.get(i);
95                 }
96         }
97
98         /**
99          * Set the title
100          * @param req byte[]
101          * @param isNew boolean
102          */
103         public void setLabel(String title, boolean isNew) {
104                 if (isNew)
105                         req ++;
106                 Request pair = (Request) getRequestResponse(req);
107                 pair.setLabel(title);
108         }
109 }