View Javadoc

1   /*
2    * $Id: TransformerResolver.java 19715 2010-09-24 15:08:06Z 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.api.registry;
11  
12  import org.mule.api.transformer.DataType;
13  import org.mule.api.transformer.Transformer;
14  
15  /**
16   * A TransformResolver is used to find transformers that match a certain criteria in the registry.  Implementations
17   * of this class will use some or all of the information passed in to discover a matching transformer.
18   * <p/>
19   * Any implementations of this class must be registered with the registry before it will get picked up. Typically this
20   * is done using the registry-bootstrap.properties.
21   *
22   * @since 3.0.0
23   */
24  public interface TransformerResolver
25  {
26      /**
27       * Possible registry actions that occur that will trigger an event fired via {@link #transformerChange()} method.
28       */
29      enum RegistryAction
30      {
31          /**
32           * signals that a transformer was added to the registry
33           */
34          ADDED,
35          /**
36           * signals that a transformer was removed from the registry
37           */
38          REMOVED
39      }
40  
41      /**
42       * Responsible for finding a transformer with the given criteria.  Note that if a transformer is not found
43       * null should be return, an exception must NOT be thrown.
44       *
45       * @param source information about the source object including the object iself
46       * @param result information about the result object to transform to
47       * @return a transformer from the registry that matches the criteria or null if a transformer was not found
48       * @throws ResolverException Only thrown if an exception is thrown during the search, this exception will just be a wrapper
49       */
50      Transformer resolve(DataType<?> source, DataType<?> result) throws ResolverException;
51  
52      /**
53       * A callback that is called when a transformer is registered or unregistered from the registry.  This is used
54       * in situations where the resolver caches transformers and the cache needs to be updated
55       *
56       * @param transformer    the transformer that has changed
57       * @param registryAction whether the transformer was added or removed
58       */
59      void transformerChange(Transformer transformer, RegistryAction registryAction);
60  }