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