1   /*
2    * $Id: Orange.java 10787 2008-02-12 18:51:50Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.tck.testmodels.fruit;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.MuleEventContext;
15  import org.mule.api.lifecycle.Callable;
16  
17  import java.util.HashMap;
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  public class Orange implements Fruit, Callable
25  {
26      /**
27       * Serial version
28       */
29      private static final long serialVersionUID = 2556604671068150589L;
30  
31      /**
32       * logger used by this class
33       */
34      private static final Log logger = LogFactory.getLog(Orange.class);
35  
36      private boolean bitten = false;
37      private Integer segments = new Integer(10);
38      private Double radius = new Double(4.34);
39      private String brand;
40  
41      private FruitCleaner cleaner;
42  
43      private Map mapProperties;
44  
45      private List listProperties;
46  
47      private List arrayProperties;
48  
49      public Orange()
50      {
51          super();
52      }
53  
54      public Orange(Integer segments, Double radius, String brand)
55      {
56          super();
57          this.segments = segments;
58          this.radius = radius;
59          this.brand = brand;
60      }
61  
62      public Orange(HashMap props) throws MuleException
63      {
64          setBrand((String) props.get("brand"));
65          setRadius((Double) props.get("radius"));
66          setSegments((Integer) props.get("segments"));
67      }
68  
69      public void bite()
70      {
71          bitten = true;
72      }
73  
74      public boolean isBitten()
75      {
76          return bitten;
77      }
78  
79      public Object onCall(MuleEventContext context) throws MuleException
80      {
81          logger.debug("Orange received an event in UMOCallable.onEvent! MuleEvent says: "
82                       + context.getMessageAsString());
83          bite();
84          return null;
85      }
86  
87      /**
88       * @return
89       */
90      public String getBrand()
91      {
92          return brand;
93      }
94  
95      /**
96       * @return
97       */
98      public Integer getSegments()
99      {
100         return segments;
101     }
102 
103     /**
104      * @return
105      */
106     public Double getRadius()
107     {
108         return radius;
109     }
110 
111     /**
112      * @param string
113      */
114     public void setBrand(String string)
115     {
116         brand = string;
117     }
118 
119     /**
120      * @param integer
121      */
122     public void setSegments(Integer integer)
123     {
124         segments = integer;
125     }
126 
127     /**
128      * @param double1
129      */
130     public void setRadius(Double double1)
131     {
132         radius = double1;
133     }
134 
135     /**
136      * @return Returns the listProperties.
137      */
138     public List getListProperties()
139     {
140         return listProperties;
141     }
142 
143     /**
144      * @param listProperties The listProperties to set.
145      */
146     public void setListProperties(List listProperties)
147     {
148         this.listProperties = listProperties;
149     }
150 
151     /**
152      * @return Returns the mapProperties.
153      */
154     public Map getMapProperties()
155     {
156         return mapProperties;
157     }
158 
159     /**
160      * @param mapProperties The mapProperties to set.
161      */
162     public void setMapProperties(Map mapProperties)
163     {
164         this.mapProperties = mapProperties;
165     }
166 
167     /**
168      * @return Returns the arrayProperties.
169      */
170     public List getArrayProperties()
171     {
172         return arrayProperties;
173     }
174 
175     /**
176      * @param arrayProperties The arrayProperties to set.
177      */
178     public void setArrayProperties(List arrayProperties)
179     {
180         this.arrayProperties = arrayProperties;
181     }
182 
183 
184     public FruitCleaner getCleaner()
185     {
186         return cleaner;
187     }
188 
189     public void setCleaner(FruitCleaner cleaner)
190     {
191         this.cleaner = cleaner;
192     }
193 
194     public void wash()
195     {
196         cleaner.wash(this);
197     }
198 
199     public void polish()
200     {
201         cleaner.polish(this);
202     }
203 
204     public int hashCode()
205     {
206         final int prime = 31;
207         int result = 1;
208         result = prime * result + (bitten ? 1231 : 1237);
209         result = prime * result + ((brand == null) ? 0 : brand.hashCode());
210         result = prime * result + ((radius == null) ? 0 : radius.hashCode());
211         result = prime * result + ((segments == null) ? 0 : segments.hashCode());
212         return result;
213     }
214 
215     public boolean equals(Object obj)
216     {
217         if (this == obj)
218         {
219             return true;
220         }
221         if (obj == null)
222         {
223             return false;
224         }
225         if (getClass() != obj.getClass())
226         {
227             return false;
228         }
229         final Orange other = (Orange) obj;
230         if (bitten != other.bitten)
231         {
232             return false;
233         }
234         if (brand == null)
235         {
236             if (other.brand != null)
237             {
238                 return false;
239             }
240         }
241         else if (!brand.equals(other.brand))
242         {
243             return false;
244         }
245         if (radius == null)
246         {
247             if (other.radius != null)
248             {
249                 return false;
250             }
251         }
252         else if (!radius.equals(other.radius))
253         {
254             return false;
255         }
256         if (segments == null)
257         {
258             if (other.segments != null)
259             {
260                 return false;
261             }
262         }
263         else if (!segments.equals(other.segments))
264         {
265             return false;
266         }
267         return true;
268     }
269 
270 }