KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > tck > testmodels > fruit > WaterMelon


1 /*
2  * $Id: WaterMelon.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.umo.UMOEvent;
16 import org.mule.umo.UMOException;
17 import org.mule.umo.lifecycle.Disposable;
18 import org.mule.umo.lifecycle.Startable;
19 import org.mule.umo.lifecycle.Stoppable;
20
21 import java.util.HashMap JavaDoc;
22
23 public class WaterMelon implements Fruit, Startable, Stoppable, Disposable
24 {
25     /**
26      * Serial version
27      */

28     private static final long serialVersionUID = -8860598811203869100L;
29
30     /**
31      * logger used by this class
32      */

33     private static Log logger = LogFactory.getLog(WaterMelon.class);
34
35     private boolean bitten = false;
36     private Integer JavaDoc seeds = new Integer JavaDoc(100);
37     private Double JavaDoc radius = new Double JavaDoc(4.34);
38     private String JavaDoc brand;
39     private String JavaDoc state = "void";
40
41     public WaterMelon()
42     {
43         super();
44     }
45
46     public WaterMelon(HashMap JavaDoc props) throws UMOException
47     {
48         logger.info("Initialisaing Water melon with hashmap constructor");
49         setBrand((String JavaDoc)props.get("namespace.brand"));
50         setRadius((Double JavaDoc)props.get("another.namespace.radius"));
51         setSeeds((Integer JavaDoc)props.get("seeds"));
52         state = "initialised";
53     }
54
55     public void bite()
56     {
57         bitten = true;
58     }
59
60     public boolean isBitten()
61     {
62         return bitten;
63     }
64
65     public void myEventHandler(UMOEvent event) throws UMOException
66     {
67         logger.debug("Water Melon received an event in MyEventHandler! Event says: "
68                      + event.getMessageAsString());
69         bite();
70     }
71
72     /**
73      * @return
74      */

75     public String JavaDoc getBrand()
76     {
77         return brand;
78     }
79
80     /**
81      * @return
82      */

83     public Integer JavaDoc getSeeds()
84     {
85         return seeds;
86     }
87
88     /**
89      * @return
90      */

91     public Double JavaDoc getRadius()
92     {
93         return radius;
94     }
95
96     /**
97      * @param string
98      */

99     public void setBrand(String JavaDoc string)
100     {
101         brand = string;
102     }
103
104     /**
105      * @param integer
106      */

107     public void setSeeds(Integer JavaDoc integer)
108     {
109         seeds = integer;
110     }
111
112     /**
113      * @param double1
114      */

115     public void setRadius(Double JavaDoc double1)
116     {
117         radius = double1;
118     }
119
120     public String JavaDoc getState()
121     {
122         return state;
123     }
124
125     public void start()
126     {
127         state = "started";
128     }
129
130     public void stop()
131     {
132         state = "stopped";
133     }
134
135     public void dispose()
136     {
137         state = "disposed";
138     }
139
140     /*
141      * (non-Javadoc)
142      *
143      * @see java.lang.Object#equals(java.lang.Object)
144      */

145     public boolean equals(Object JavaDoc obj)
146     {
147         if (obj instanceof WaterMelon)
148         {
149             WaterMelon melon = (WaterMelon)obj;
150             return (getBrand().equals(melon.getBrand()) && getRadius().equals(melon.getRadius())
151                     && getSeeds().equals(melon.getSeeds()) && getState().equals(getState()));
152         }
153
154         return super.equals(obj);
155     }
156
157 }
158
Popular Tags