View Javadoc

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