1 | |
---|
2 | package de.ugoe.cs.quest.plugin.php.eventcore; |
---|
3 | |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import de.ugoe.cs.quest.eventcore.IEventType; |
---|
7 | |
---|
8 | /** |
---|
9 | * <p> |
---|
10 | * Event type for PHP web requests. |
---|
11 | * </p> |
---|
12 | * |
---|
13 | * @version $Revision: $ $Date: Aug 16, 2012$ |
---|
14 | * @author 2012, last modified by $Author: sherbold$ |
---|
15 | */ |
---|
16 | public class PHPEventType implements IEventType { |
---|
17 | |
---|
18 | /** |
---|
19 | * <p> |
---|
20 | * Id for object serialization. |
---|
21 | * </p> |
---|
22 | */ |
---|
23 | private static final long serialVersionUID = 1L; |
---|
24 | |
---|
25 | /** |
---|
26 | * <p> |
---|
27 | * Path of the web request. |
---|
28 | * </p> |
---|
29 | */ |
---|
30 | private final String path; |
---|
31 | |
---|
32 | /** |
---|
33 | * <p> |
---|
34 | * List of post variable names posted with the request. |
---|
35 | * </p> |
---|
36 | */ |
---|
37 | private final List<String> postVars; |
---|
38 | |
---|
39 | /** |
---|
40 | * <p> |
---|
41 | * List of get variable names posted with the request. |
---|
42 | * </p> |
---|
43 | */ |
---|
44 | private final List<String> getVars; |
---|
45 | |
---|
46 | /** |
---|
47 | * <p> |
---|
48 | * Constructor. Creates a new PHPEventType from a given path, a list of post variables, and a |
---|
49 | * list of get variables. |
---|
50 | * </p> |
---|
51 | * |
---|
52 | * @param path |
---|
53 | * path of the URI of the event |
---|
54 | * @param postVars |
---|
55 | * POST variables send with the event |
---|
56 | * @param getVars |
---|
57 | * GET variables send with the event |
---|
58 | */ |
---|
59 | public PHPEventType(String path, List<String> postVars, List<String> getVars) { |
---|
60 | this.path = path; |
---|
61 | this.postVars = postVars; |
---|
62 | this.getVars = getVars; |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * (non-Javadoc) |
---|
67 | * |
---|
68 | * @see de.ugoe.cs.quest.eventcore.IEventType#getName() |
---|
69 | */ |
---|
70 | @Override |
---|
71 | public String getName() { |
---|
72 | return "PHPEventType"; |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * (non-Javadoc) |
---|
77 | * |
---|
78 | * @see java.lang.Object#toString() |
---|
79 | */ |
---|
80 | @Override |
---|
81 | public String toString() { |
---|
82 | String str = path; |
---|
83 | if (getVars != null && !getVars.isEmpty()) { |
---|
84 | str += "+GET" + getVars.toString().replace(" ", ""); |
---|
85 | } |
---|
86 | if (postVars != null && !postVars.isEmpty()) { |
---|
87 | str += "+POST" + postVars.toString().replace(" ", ""); |
---|
88 | } |
---|
89 | return str; |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * (non-Javadoc) |
---|
94 | * |
---|
95 | * @see java.lang.Object#equals(java.lang.Object) |
---|
96 | */ |
---|
97 | @Override |
---|
98 | public boolean equals(Object obj) { |
---|
99 | if (obj instanceof PHPEventType) { |
---|
100 | PHPEventType other = (PHPEventType) obj; |
---|
101 | return ((path == other.path) || (path != null && path.equals(other.path))) && |
---|
102 | ((postVars == other.postVars) || (postVars!=null && postVars.equals(other.postVars))) && |
---|
103 | ((getVars == other.getVars) || (getVars!=null && getVars.equals(other.getVars))); |
---|
104 | } |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | /* |
---|
109 | * (non-Javadoc) |
---|
110 | * |
---|
111 | * @see java.lang.Object#hashCode() |
---|
112 | */ |
---|
113 | @Override |
---|
114 | public int hashCode() { |
---|
115 | int hash = 17; |
---|
116 | int multiplier = 7; |
---|
117 | if (path != null) { |
---|
118 | hash = hash * multiplier + path.hashCode(); |
---|
119 | } |
---|
120 | if (postVars != null) { |
---|
121 | hash = hash * multiplier + postVars.hashCode(); |
---|
122 | } |
---|
123 | if (getVars != null) { |
---|
124 | hash = hash * multiplier + getVars.hashCode(); |
---|
125 | } |
---|
126 | return hash; |
---|
127 | } |
---|
128 | |
---|
129 | } |
---|