Coverage Report - org.guiceyfruit.mule.MuleModule
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleModule
0%
0/7
N/A
0
MuleModule$1
0%
0/3
N/A
0
MuleModule$1$1
0%
0/8
0%
0/4
0
 
 1  
  /*
 2  
   * $Id$
 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.guiceyfruit.mule;
 11  
  
 12  
  import org.mule.api.MuleContext;
 13  
  import org.mule.api.lifecycle.Initialisable;
 14  
  
 15  
  import com.google.inject.Guice;
 16  
  import com.google.inject.Injector;
 17  
  import com.google.inject.Module;
 18  
  import com.google.inject.ProvisionException;
 19  
  import com.google.inject.TypeLiteral;
 20  
  import com.google.inject.internal.Iterables;
 21  
  import com.google.inject.matcher.Matchers;
 22  
  import com.google.inject.spi.InjectionListener;
 23  
  import com.google.inject.spi.TypeEncounter;
 24  
  import com.google.inject.spi.TypeListener;
 25  
  
 26  
  import java.util.Arrays;
 27  
  import java.util.Collections;
 28  
  
 29  
  import org.guiceyfruit.jsr250.Jsr250Module;
 30  
  import org.guiceyfruit.mule.support.DisposableCloser;
 31  
  
 32  
  /**
 33  
   * TODO
 34  
   */
 35  0
  public class MuleModule extends Jsr250Module
 36  
  {
 37  
      /**
 38  
       * Returns a new Injector with support for
 39  
       * Mule lifecycle support along with JSR 250 support included.
 40  
       */
 41  
      public static Injector createInjector(Module... modules)
 42  
      {
 43  0
          Iterable<? extends Module> iterable = Iterables.concat(
 44  
                  Collections.singletonList(new MuleModule()), Arrays.asList(modules));
 45  
  
 46  0
          return Guice.createInjector(iterable);
 47  
      }
 48  
  
 49  
      protected void configure()
 50  
      {
 51  0
          super.configure();
 52  
  
 53  0
          bindListener(Matchers.any(), new TypeListener()
 54  0
          {
 55  
              public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter)
 56  
              {
 57  
  
 58  0
                  encounter.register(new InjectionListener<I>()
 59  0
                  {
 60  
                      public void afterInjection(I injectee)
 61  
                      {
 62  0
                          if (injectee instanceof Initialisable && !(injectee instanceof MuleContext))
 63  
                          {
 64  0
                              Initialisable initialisable = (Initialisable) injectee;
 65  
                              try
 66  
                              {
 67  0
                                  initialisable.initialise();
 68  
                              }
 69  0
                              catch (Exception e)
 70  
                              {
 71  0
                                  throw new ProvisionException("Failed to invoke initialise(): " + e, e);
 72  0
                              }
 73  
                          }
 74  0
                      }
 75  
                  });
 76  
  
 77  0
              }
 78  
          });
 79  
  
 80  0
          bind(DisposableCloser.class);
 81  0
      }
 82  
  
 83  
  }