1   /*
2    * $Id: Apple.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 org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  public class Apple implements Fruit, Callable
21  {
22      /**
23       * Serial version
24       */
25      private static final long serialVersionUID = -7631993371500076921L;
26  
27      /**
28       * logger used by this class
29       */
30      private static final Log logger = LogFactory.getLog(Apple.class);
31  
32      private boolean bitten = false;
33      private boolean washed = false;
34  
35      private FruitCleaner cleaner;
36  
37      public void wash()
38      {
39          if (cleaner != null)
40          {
41              cleaner.wash(this);
42          }
43          washed = true;
44      }
45  
46      public void polish()
47      {
48          cleaner.polish(this);
49      }
50  
51      public boolean isWashed()
52      {
53          return washed;
54      }
55  
56      public void bite()
57      {
58          bitten = true;
59      }
60  
61      public boolean isBitten()
62      {
63          return bitten;
64      }
65  
66      public Object onCall(MuleEventContext context) throws MuleException
67      {
68          logger.debug("Apple received an event in UMOCallable.onEvent! MuleEvent says: "
69                          + context.getMessageAsString());
70          wash();
71          return null;
72      }
73  
74  
75      public FruitCleaner getAppleCleaner()
76      {
77          return cleaner;
78      }
79  
80      public void setAppleCleaner(FruitCleaner cleaner)
81      {
82          this.cleaner = cleaner;
83      }
84  
85      public Object methodReturningNull()
86      {
87          return null;
88      }
89  
90      public boolean equals(Object o)
91      {
92          if (this == o)
93          {
94              return true;
95          }
96          if (o == null || getClass() != o.getClass())
97          {
98              return false;
99          }
100 
101         final Apple apple = (Apple) o;
102 
103         if (bitten != apple.bitten)
104         {
105             return false;
106         }
107         if (washed != apple.washed)
108         {
109             return false;
110         }
111 
112         return true;
113     }
114 
115     public int hashCode()
116     {
117         int result;
118         result = (bitten ? 1 : 0);
119         result = 29 * result + (washed ? 1 : 0);
120         return result;
121     }
122 
123     public String toString()
124     {
125         return "Just an apple.";
126     }
127 
128     public void setBitten(boolean bitten)
129     {
130         this.bitten = bitten;
131     }
132 
133     public void setWashed(boolean washed)
134     {
135         this.washed = washed;
136     }
137 }