1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.testmodels.fruit; |
12 | |
|
13 | |
import org.mule.umo.UMOEvent; |
14 | |
import org.mule.umo.UMOException; |
15 | |
import org.mule.umo.lifecycle.Disposable; |
16 | |
import org.mule.umo.lifecycle.Startable; |
17 | |
import org.mule.umo.lifecycle.Stoppable; |
18 | |
|
19 | |
import java.util.HashMap; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
public class WaterMelon implements Fruit, Startable, Stoppable, Disposable |
25 | |
{ |
26 | |
|
27 | |
|
28 | |
|
29 | |
private static final long serialVersionUID = -8860598811203869100L; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | private static final Log logger = LogFactory.getLog(WaterMelon.class); |
35 | |
|
36 | 0 | private boolean bitten = false; |
37 | 0 | private Integer seeds = new Integer(100); |
38 | 0 | private Double radius = new Double(4.34); |
39 | |
private String brand; |
40 | 0 | private String state = "void"; |
41 | |
|
42 | |
public WaterMelon() |
43 | |
{ |
44 | 0 | super(); |
45 | 0 | } |
46 | |
|
47 | |
public WaterMelon(HashMap props) throws UMOException |
48 | 0 | { |
49 | 0 | logger.info("Initialisaing Water melon with hashmap constructor"); |
50 | 0 | setBrand((String) props.get("namespace.brand")); |
51 | 0 | setRadius((Double) props.get("another.namespace.radius")); |
52 | 0 | setSeeds((Integer) props.get("seeds")); |
53 | 0 | state = "initialised"; |
54 | 0 | } |
55 | |
|
56 | |
public void bite() |
57 | |
{ |
58 | 0 | bitten = true; |
59 | 0 | } |
60 | |
|
61 | |
public boolean isBitten() |
62 | |
{ |
63 | 0 | return bitten; |
64 | |
} |
65 | |
|
66 | |
public void myEventHandler(UMOEvent event) throws UMOException |
67 | |
{ |
68 | 0 | logger.debug("Water Melon received an event in MyEventHandler! Event says: " |
69 | |
+ event.getMessageAsString()); |
70 | 0 | bite(); |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public String getBrand() |
77 | |
{ |
78 | 0 | return brand; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public Integer getSeeds() |
85 | |
{ |
86 | 0 | return seeds; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public Double getRadius() |
93 | |
{ |
94 | 0 | return radius; |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void setBrand(String string) |
101 | |
{ |
102 | 0 | brand = string; |
103 | 0 | } |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public void setSeeds(Integer integer) |
109 | |
{ |
110 | 0 | seeds = integer; |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public void setRadius(Double double1) |
117 | |
{ |
118 | 0 | radius = double1; |
119 | 0 | } |
120 | |
|
121 | |
public String getState() |
122 | |
{ |
123 | 0 | return state; |
124 | |
} |
125 | |
|
126 | |
public void start() |
127 | |
{ |
128 | 0 | state = "started"; |
129 | 0 | } |
130 | |
|
131 | |
public void stop() |
132 | |
{ |
133 | 0 | state = "stopped"; |
134 | 0 | } |
135 | |
|
136 | |
public void dispose() |
137 | |
{ |
138 | 0 | state = "disposed"; |
139 | 0 | } |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public boolean equals(Object obj) |
147 | |
{ |
148 | 0 | if (obj instanceof WaterMelon) |
149 | |
{ |
150 | 0 | WaterMelon melon = (WaterMelon) obj; |
151 | 0 | return (getBrand().equals(melon.getBrand()) && getRadius().equals(melon.getRadius()) |
152 | |
&& getSeeds().equals(melon.getSeeds()) && getState().equals(getState())); |
153 | |
} |
154 | |
|
155 | 0 | return super.equals(obj); |
156 | |
} |
157 | |
|
158 | |
public int hashCode () |
159 | |
{ |
160 | |
int result; |
161 | 0 | result = (bitten ? 1 : 0); |
162 | 0 | result = 31 * result + seeds.hashCode(); |
163 | 0 | result = 31 * result + radius.hashCode(); |
164 | 0 | result = 31 * result + (brand != null ? brand.hashCode() : 0); |
165 | 0 | result = 31 * result + state.hashCode(); |
166 | 0 | return result; |
167 | |
} |
168 | |
} |