View Javadoc

1   /*
2    * $Id: Apple.java 22409 2011-07-14 05:14:27Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.MuleEventContext;
14  import org.mule.api.MuleException;
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 Apple()
38      {
39      }
40  
41      public Apple(boolean bitten)
42      {
43          this.bitten = bitten;
44      }
45  
46      public void wash()
47      {
48          if (cleaner != null)
49          {
50              cleaner.wash(this);
51          }
52          washed = true;
53      }
54  
55      public void polish()
56      {
57          cleaner.polish(this);
58      }
59  
60      public boolean isWashed()
61      {
62          return washed;
63      }
64  
65      @Override
66      public void bite()
67      {
68          bitten = true;
69      }
70  
71      @Override
72      public boolean isBitten()
73      {
74          return bitten;
75      }
76  
77      @Override
78      public Object onCall(MuleEventContext context) throws MuleException
79      {
80          logger.debug("Apple received an event in Callable.onEvent! MuleEvent says: "
81                          + context.getMessageAsString());
82          wash();
83          return null;
84      }
85  
86  
87      public FruitCleaner getAppleCleaner()
88      {
89          return cleaner;
90      }
91  
92      public void setAppleCleaner(FruitCleaner cleaner)
93      {
94          this.cleaner = cleaner;
95      }
96  
97      public Object methodReturningNull()
98      {
99          return null;
100     }
101 
102     @Override
103     public boolean equals(Object o)
104     {
105         if (this == o)
106         {
107             return true;
108         }
109         if (o == null || getClass() != o.getClass())
110         {
111             return false;
112         }
113 
114         final Apple apple = (Apple) o;
115 
116         if (bitten != apple.bitten)
117         {
118             return false;
119         }
120         if (washed != apple.washed)
121         {
122             return false;
123         }
124 
125         return true;
126     }
127 
128     @Override
129     public int hashCode()
130     {
131         int result;
132         result = (bitten ? 1 : 0);
133         result = 29 * result + (washed ? 1 : 0);
134         return result;
135     }
136 
137     @Override
138     public String toString()
139     {
140         return "Just an apple.";
141     }
142 
143     public void setBitten(boolean bitten)
144     {
145         this.bitten = bitten;
146     }
147 
148     public void setWashed(boolean washed)
149     {
150         this.washed = washed;
151     }
152 }