source: proiecte/ptvs/src/vnsim/applications/vitp/utils/VITPRequest.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 2.5 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.applications.vitp.utils;
7
8
9import java.util.*;
10
11import vnsim.map.object.*;
12
13
14public class VITPRequest extends VITPMessage {
15       
16        /** <code>serialVersionUID</code> */
17        private static final long serialVersionUID = -5883719321862303634L;
18       
19        private String method; //can be GET or POST
20        private String uri;     //the URI, as described in the VITP specification
21
22        public VITPRequest(
23                                                        short road1IdxDst, short fromDst, short toDst,
24                                                        short road1IdxSrc, short fromSrc, short toSrc,
25
26                                                Date initialTime, Date expirationTime, String cacheControl,
27                                                int msgId, String msgBody, String method, String uri){
28
29                super(road1IdxDst,  fromDst, toDst,  road1IdxSrc, fromSrc, toSrc,
30                                initialTime, expirationTime, cacheControl, msgId, msgBody);
31
32                this.uri=uri;
33                this.method=method;
34                this.type=VITP_REQ;
35        }
36
37        public boolean isPost(){
38                if(method!=null && method.equals("POST"))
39                        return true;
40                return false;
41        }
42
43        public boolean isGet(){
44                if(method!=null && method.equals("GET"))
45                        return true;
46                return false;
47        }
48
49        public String getMethod(){
50                return method;
51        }
52
53        public String getURI(){
54                return uri;
55        }
56
57        public void setURI(String uri){
58                this.uri=uri;
59        }
60       
61        public String toString(){
62                String ret=super.toString();
63                ret=ret+";URI="+uri+";METHOD="+method+"--";
64                return ret;
65        }
66
67        public String getUserFriendlyText() {
68                String ret="";
69                if(this.isPost()) {
70                        ret+="ATTENTION!\n";
71                }
72                ret+="Message came from:\n";
73                Road r=(Road)Globals.map.roads.get(this.source.roadIndex);
74                ret+="Road : "+r.getName();
75                Point ptmid=(Point)r.points.get((this.source.pt1+this.source.pt2)/2);
76                Point pt1=(Point)r.points.get(this.source.pt1);
77                Point pt2=(Point)r.points.get(this.source.pt2);
78                ret+="\nSegment length: "+Math.abs(pt1.getDistance()-pt2.getDistance());
79                for(int i=0;i<r.crosses.size();i++) {
80                        Cross c=(Cross)r.crosses.get(i);
81                        if(c.getPointIndex()==0) {
82                                ret+="\n From "+pt1.getDistance()+"meters away from "+(((Road)(Globals.map.roads.get(c.getCrossRoadIndex()))).getName());
83                        }
84                }
85                ret+="\n Message content:\n"+this.msgBody;
86                ret+="\n***";
87                return ret;
88        }
89}
Note: See TracBrowser for help on using the repository browser.