View Javadoc

1   /*
2    * $Id: FruitBowlToFruitBasket.java 19250 2010-08-30 16:53:14Z 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  package org.mule.tck.testmodels.fruit;
11  
12  import org.mule.api.transformer.DiscoverableTransformer;
13  import org.mule.api.transformer.TransformerException;
14  import org.mule.transformer.AbstractTransformer;
15  import org.mule.transformer.types.DataTypeFactory;
16  
17  /**
18   * Converts a FruitBowl to a FruitBasket (for testing obviously :)
19   */
20  public class FruitBowlToFruitBasket extends AbstractTransformer implements DiscoverableTransformer
21  {
22      private int weighting = 1;
23  
24      public FruitBowlToFruitBasket()
25      {
26          registerSourceType(DataTypeFactory.create(FruitBowl.class));
27          setReturnDataType(DataTypeFactory.create(FruitBasket.class));
28      }
29  
30      @Override
31      protected Object doTransform(Object src, String encoding) throws TransformerException
32      {
33          FruitBowl bowl = (FruitBowl)src;
34          FruitBasket basket = new FruitBasket();
35          basket.setFruit(bowl.getFruit());
36          return basket;
37      }
38  
39      /**
40       * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
41       *
42       * @return the priority weighting for this transformer. This is a value between
43       *         {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
44       */
45      public int getPriorityWeighting()
46      {
47          return weighting;
48      }
49  
50      /**
51       * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
52       *
53       * @param weighting the priority weighting for this transformer. This is a value between
54       *                  {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
55       */
56      public void setPriorityWeighting(int weighting)
57      {
58          this.weighting = weighting;
59      }
60  }