View Javadoc

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