View Javadoc

1   /*
2    * $Id: AnnotationsConfigurationBuilder.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  
11  package org.mule.config;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.config.builders.AbstractConfigurationBuilder;
15  import org.mule.config.endpoint.RegistryBackedAnnotationsParserFactory;
16  
17  /**
18   * Enables Mule annotation processing so that annotated objects registered with the
19   * Mule registry will automatically be configured. This helper also enables JSR-330
20   * injection annotations <code>javax.inject.Inject</code> and
21   * <code>javax.inject.Named</code>.
22   * <p/>
23   * Internal Implementation note: We could have used a 'registry-bootstrap.properties'
24   * file to load the objects necessary to enable annotations however, that method
25   * would not allow the annotation processors to be easily overridden when using other
26   * platforms such as Google App Engine.
27   *
28   * @since 3.0
29   */
30  public class AnnotationsConfigurationBuilder extends AbstractConfigurationBuilder
31  {
32      @Override
33      protected void doConfigure(MuleContext muleContext) throws Exception
34      {
35          // Make the annotation parsers available
36          AnnotationsParserFactory factory = createAnnotationsParserFactory();
37          muleContext.getRegistry().registerObject("_" + factory.getClass().getSimpleName(), factory);
38      }
39  
40      protected AnnotationsParserFactory createAnnotationsParserFactory()
41      {
42          return new RegistryBackedAnnotationsParserFactory();
43      }
44  }