Coverage Report - org.mule.module.launcher.ApplicationWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationWrapper
0%
0/53
0%
0/14
0
 
 1  
 /*
 2  
  * $Id: ApplicationWrapper.java 19191 2010-08-25 21:05:23Z tcarlson $
 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.module.launcher;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 
 15  
 /**
 16  
  * Decorates the target deployer to properly switch out context classloader for deployment
 17  
  * one where applicable. E.g. init() phase may load custom classes for an application, which
 18  
  * must be executed with deployment (app) classloader in the context, and not Mule system
 19  
  * classloader.
 20  
  */
 21  
 public class ApplicationWrapper implements Application
 22  
 {
 23  
 
 24  
     private Application delegate;
 25  
 
 26  
     public ApplicationWrapper(Application delegate)
 27  0
     {
 28  0
         this.delegate = delegate;
 29  0
     }
 30  
 
 31  
     public void dispose()
 32  
     {
 33  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 34  
         try
 35  
         {
 36  0
             ClassLoader appCl = getDeploymentClassLoader();
 37  
             // if not initialized yet, it can be null
 38  0
             if (appCl != null)
 39  
             {
 40  0
                 Thread.currentThread().setContextClassLoader(appCl);
 41  
             }
 42  0
             delegate.dispose();
 43  0
             if (appCl != null)
 44  
             {
 45  
                 // close classloader to release jar connections in lieu of Java 7's ClassLoader.close()
 46  0
                 if (appCl instanceof GoodCitizenClassLoader)
 47  
                 {
 48  0
                     GoodCitizenClassLoader classLoader = (GoodCitizenClassLoader) appCl;
 49  0
                     classLoader.close();
 50  
                 }
 51  
             }
 52  
         }
 53  
         finally
 54  
         {
 55  0
             Thread.currentThread().setContextClassLoader(originalCl);
 56  0
         }
 57  0
     }
 58  
 
 59  
     public ClassLoader getDeploymentClassLoader()
 60  
     {
 61  0
         return delegate.getDeploymentClassLoader();
 62  
     }
 63  
 
 64  
     public MuleContext getMuleContext()
 65  
     {
 66  0
         return delegate.getMuleContext();
 67  
     }
 68  
 
 69  
     public void init()
 70  
     {
 71  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 72  
         try
 73  
         {
 74  0
             ClassLoader appCl = getDeploymentClassLoader();
 75  
             // if not initialized yet, it can be null
 76  0
             if (appCl != null)
 77  
             {
 78  0
                 Thread.currentThread().setContextClassLoader(appCl);
 79  
             }
 80  0
             delegate.init();
 81  
         }
 82  
         finally
 83  
         {
 84  0
             Thread.currentThread().setContextClassLoader(originalCl);
 85  0
         }
 86  0
     }
 87  
 
 88  
     public void install() throws InstallException
 89  
     {
 90  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 91  
         try
 92  
         {
 93  0
             ClassLoader appCl = getDeploymentClassLoader();
 94  
             // if not initialized yet, it can be null
 95  0
             if (appCl != null)
 96  
             {
 97  0
                 Thread.currentThread().setContextClassLoader(appCl);
 98  
             }
 99  0
             delegate.install();
 100  
         }
 101  
         finally
 102  
         {
 103  0
             Thread.currentThread().setContextClassLoader(originalCl);
 104  0
         }
 105  0
     }
 106  
 
 107  
     public void redeploy()
 108  
     {
 109  0
         delegate.redeploy();
 110  0
     }
 111  
 
 112  
     public void start() throws DeploymentStartException
 113  
     {
 114  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 115  
         try
 116  
         {
 117  0
             ClassLoader appCl = getDeploymentClassLoader();
 118  
             // if not initialized yet, it can be null
 119  0
             if (appCl != null)
 120  
             {
 121  0
                 Thread.currentThread().setContextClassLoader(appCl);
 122  
             }
 123  0
             delegate.start();
 124  
         }
 125  
         finally
 126  
         {
 127  0
             Thread.currentThread().setContextClassLoader(originalCl);
 128  0
         }
 129  0
     }
 130  
 
 131  
     public void stop()
 132  
     {
 133  0
         final ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
 134  
         try
 135  
         {
 136  0
             ClassLoader appCl = getDeploymentClassLoader();
 137  
             // if not initialized yet, it can be null
 138  0
             if (appCl != null)
 139  
             {
 140  0
                 Thread.currentThread().setContextClassLoader(appCl);
 141  
             }
 142  0
             delegate.stop();
 143  
         }
 144  
         finally
 145  
         {
 146  0
             Thread.currentThread().setContextClassLoader(originalCl);
 147  0
         }
 148  0
     }
 149  
 
 150  
     public String getAppName()
 151  
     {
 152  0
         return delegate.getAppName();
 153  
     }
 154  
 
 155  
     @Override
 156  
     public String toString()
 157  
     {
 158  0
         return String.format("%s(%s)@%s", getClass().getName(),
 159  
                              delegate,
 160  
                              Integer.toHexString(System.identityHashCode(this)));
 161  
 
 162  
     }
 163  
 }