1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.plugin.php.eventcore; |
---|
16 | |
---|
17 | import java.util.List; |
---|
18 | |
---|
19 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
20 | |
---|
21 | /** |
---|
22 | * <p> |
---|
23 | * Event type for PHP web requests. |
---|
24 | * </p> |
---|
25 | * |
---|
26 | * @version $Revision: $ $Date: Aug 16, 2012$ |
---|
27 | * @author 2012, last modified by $Author: sherbold$ |
---|
28 | */ |
---|
29 | public class PHPEventType implements IEventType { |
---|
30 | |
---|
31 | /** |
---|
32 | * <p> |
---|
33 | * Id for object serialization. |
---|
34 | * </p> |
---|
35 | */ |
---|
36 | private static final long serialVersionUID = 1L; |
---|
37 | |
---|
38 | /** |
---|
39 | * <p> |
---|
40 | * Path of the web request. |
---|
41 | * </p> |
---|
42 | */ |
---|
43 | private final String path; |
---|
44 | |
---|
45 | /** |
---|
46 | * <p> |
---|
47 | * List of post variable names posted with the request. |
---|
48 | * </p> |
---|
49 | */ |
---|
50 | private final List<String> postVars; |
---|
51 | |
---|
52 | /** |
---|
53 | * <p> |
---|
54 | * List of get variable names posted with the request. |
---|
55 | * </p> |
---|
56 | */ |
---|
57 | private final List<String> getVars; |
---|
58 | |
---|
59 | /** |
---|
60 | * <p> |
---|
61 | * Constructor. Creates a new PHPEventType from a given path, a list of post variables, and a |
---|
62 | * list of get variables. |
---|
63 | * </p> |
---|
64 | * |
---|
65 | * @param path |
---|
66 | * path of the URI of the event |
---|
67 | * @param postVars |
---|
68 | * POST variables send with the event |
---|
69 | * @param getVars |
---|
70 | * GET variables send with the event |
---|
71 | */ |
---|
72 | public PHPEventType(String path, List<String> postVars, List<String> getVars) { |
---|
73 | this.path = path; |
---|
74 | this.postVars = postVars; |
---|
75 | this.getVars = getVars; |
---|
76 | } |
---|
77 | |
---|
78 | /* |
---|
79 | * (non-Javadoc) |
---|
80 | * |
---|
81 | * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName() |
---|
82 | */ |
---|
83 | @Override |
---|
84 | public String getName() { |
---|
85 | return "PHPEventType"; |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * (non-Javadoc) |
---|
90 | * |
---|
91 | * @see java.lang.Object#toString() |
---|
92 | */ |
---|
93 | @Override |
---|
94 | public String toString() { |
---|
95 | String str = path; |
---|
96 | if (getVars != null && !getVars.isEmpty()) { |
---|
97 | str += "+GET" + getVars.toString().replace(" ", ""); |
---|
98 | } |
---|
99 | if (postVars != null && !postVars.isEmpty()) { |
---|
100 | str += "+POST" + postVars.toString().replace(" ", ""); |
---|
101 | } |
---|
102 | return str; |
---|
103 | } |
---|
104 | |
---|
105 | /* |
---|
106 | * (non-Javadoc) |
---|
107 | * |
---|
108 | * @see java.lang.Object#equals(java.lang.Object) |
---|
109 | */ |
---|
110 | @Override |
---|
111 | public boolean equals(Object obj) { |
---|
112 | if (obj instanceof PHPEventType) { |
---|
113 | PHPEventType other = (PHPEventType) obj; |
---|
114 | return ((path == other.path) || (path != null && path.equals(other.path))) && |
---|
115 | ((postVars == other.postVars) || (postVars!=null && postVars.equals(other.postVars))) && |
---|
116 | ((getVars == other.getVars) || (getVars!=null && getVars.equals(other.getVars))); |
---|
117 | } |
---|
118 | return false; |
---|
119 | } |
---|
120 | |
---|
121 | /* |
---|
122 | * (non-Javadoc) |
---|
123 | * |
---|
124 | * @see java.lang.Object#hashCode() |
---|
125 | */ |
---|
126 | @Override |
---|
127 | public int hashCode() { |
---|
128 | int hash = 17; |
---|
129 | int multiplier = 7; |
---|
130 | if (path != null) { |
---|
131 | hash = hash * multiplier + path.hashCode(); |
---|
132 | } |
---|
133 | if (postVars != null) { |
---|
134 | hash = hash * multiplier + postVars.hashCode(); |
---|
135 | } |
---|
136 | if (getVars != null) { |
---|
137 | hash = hash * multiplier + getVars.hashCode(); |
---|
138 | } |
---|
139 | return hash; |
---|
140 | } |
---|
141 | |
---|
142 | } |
---|