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.model.resolvers;
8   
9   import org.mule.api.MuleRuntimeException;
10  import org.mule.api.model.EntryPointResolver;
11  import org.mule.config.i18n.CoreMessages;
12  import org.mule.util.ClassUtils;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  
17  /**
18   * An {@link org.mule.api.model.EntryPointResolverSet} that mimics the behaviour of the Mule 1.x
19   * DynamicEntryPointResolver.
20   * <b>NOTE:</b> Since 3.0 this legacy entry point resolver will always invoked after message
21   * transformation  and not before.
22   */
23  public class LegacyEntryPointResolverSet extends DefaultEntryPointResolverSet
24  {
25      private static final String ANNOTATED_ENTRYPOINT_RESOLVER_CLASS = "org.mule.impl.model.resolvers.AnnotatedEntryPointResolver";
26      private static final Log logger = LogFactory.getLog(LegacyEntryPointResolverSet.class);
27  
28      public LegacyEntryPointResolverSet()
29      {
30          addAnnotatedEntryPointResolver();
31          addEntryPointResolver(new MethodHeaderPropertyEntryPointResolver());
32          addEntryPointResolver(new CallableEntryPointResolver());
33  
34          ReflectionEntryPointResolver reflectionResolver = new ReflectionEntryPointResolver();
35          //In Mule 1.x you could call setXX methods as service methods by default
36          reflectionResolver.removeIgnoredMethod("set*");
37          addEntryPointResolver(reflectionResolver);
38      }
39  
40      protected void addAnnotatedEntryPointResolver()
41      {
42          //Annotations support is not part of Mule core, but we want default handling for annotations we have
43          //work-arounds like this to avoid importing annotation classes
44          //See MULE-4962 for details
45          try
46          {
47              Class<? extends EntryPointResolver> annotatedEntrypointResolver =
48                      ClassUtils.loadClass(ANNOTATED_ENTRYPOINT_RESOLVER_CLASS, getClass(), EntryPointResolver.class);
49              addEntryPointResolver(ClassUtils.instanciateClass(annotatedEntrypointResolver, ClassUtils.NO_ARGS));
50          }
51          catch (ClassNotFoundException e)
52          {
53              if(logger.isDebugEnabled())
54              {
55                  logger.warn("Mule annotations module is not on your classpath, annotations cannot be used on components");
56              }
57          }
58          catch (Exception e)
59          {
60              throw new MuleRuntimeException(CoreMessages.cannotLoadFromClasspath(ANNOTATED_ENTRYPOINT_RESOLVER_CLASS));
61          }
62      }
63  }