View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.testmodels.fruit;
8   
9   import org.mule.api.transformer.DiscoverableTransformer;
10  import org.mule.api.transformer.TransformerException;
11  import org.mule.transformer.AbstractTransformer;
12  import org.mule.transformer.types.DataTypeFactory;
13  
14  /**
15   * Converts a FruitBowl to a FruitBasket (for testing obviously :)
16   */
17  public class FruitBowlToFruitBasket extends AbstractTransformer implements DiscoverableTransformer
18  {
19      private int weighting = 1;
20  
21      public FruitBowlToFruitBasket()
22      {
23          registerSourceType(DataTypeFactory.create(FruitBowl.class));
24          setReturnDataType(DataTypeFactory.create(FruitBasket.class));
25      }
26  
27      @Override
28      protected Object doTransform(Object src, String encoding) throws TransformerException
29      {
30          FruitBowl bowl = (FruitBowl)src;
31          FruitBasket basket = new FruitBasket();
32          basket.setFruit(bowl.getFruit());
33          return basket;
34      }
35  
36      /**
37       * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
38       *
39       * @return the priority weighting for this transformer. This is a value between
40       *         {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
41       */
42      public int getPriorityWeighting()
43      {
44          return weighting;
45      }
46  
47      /**
48       * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
49       *
50       * @param weighting the priority weighting for this transformer. This is a value between
51       *                  {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
52       */
53      public void setPriorityWeighting(int weighting)
54      {
55          this.weighting = weighting;
56      }
57  }