Coverage Report - org.mule.context.DefaultMuleContextBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultMuleContextBuilder
0%
0/60
0%
0/12
0
 
 1  
 /*
 2  
  * $Id: DefaultMuleContextBuilder.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.context;
 12  
 
 13  
 import org.mule.DefaultMuleContext;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.api.MuleRuntimeException;
 16  
 import org.mule.api.config.MuleConfiguration;
 17  
 import org.mule.api.config.ThreadingProfile;
 18  
 import org.mule.api.context.MuleContextBuilder;
 19  
 import org.mule.api.context.WorkManager;
 20  
 import org.mule.api.context.notification.ConnectionNotificationListener;
 21  
 import org.mule.api.context.notification.CustomNotificationListener;
 22  
 import org.mule.api.context.notification.ExceptionNotificationListener;
 23  
 import org.mule.api.context.notification.ManagementNotificationListener;
 24  
 import org.mule.api.context.notification.ModelNotificationListener;
 25  
 import org.mule.api.context.notification.MuleContextNotificationListener;
 26  
 import org.mule.api.context.notification.RegistryNotificationListener;
 27  
 import org.mule.api.context.notification.RoutingNotificationListener;
 28  
 import org.mule.api.context.notification.SecurityNotificationListener;
 29  
 import org.mule.api.context.notification.ServiceNotificationListener;
 30  
 import org.mule.api.context.notification.TransactionNotificationListener;
 31  
 import org.mule.api.lifecycle.LifecycleManager;
 32  
 import org.mule.config.DefaultMuleConfiguration;
 33  
 import org.mule.config.i18n.Message;
 34  
 import org.mule.config.i18n.MessageFactory;
 35  
 import org.mule.context.notification.ConnectionNotification;
 36  
 import org.mule.context.notification.CustomNotification;
 37  
 import org.mule.context.notification.ExceptionNotification;
 38  
 import org.mule.context.notification.ManagementNotification;
 39  
 import org.mule.context.notification.ModelNotification;
 40  
 import org.mule.context.notification.MuleContextNotification;
 41  
 import org.mule.context.notification.RegistryNotification;
 42  
 import org.mule.context.notification.RoutingNotification;
 43  
 import org.mule.context.notification.SecurityNotification;
 44  
 import org.mule.context.notification.ServerNotificationManager;
 45  
 import org.mule.context.notification.ServiceNotification;
 46  
 import org.mule.context.notification.TransactionNotification;
 47  
 import org.mule.lifecycle.MuleContextLifecycleManager;
 48  
 import org.mule.util.ClassUtils;
 49  
 import org.mule.util.SplashScreen;
 50  
 import org.mule.work.DefaultWorkListener;
 51  
 import org.mule.work.MuleWorkManager;
 52  
 
 53  
 import javax.resource.spi.work.WorkListener;
 54  
 
 55  
 import org.apache.commons.logging.Log;
 56  
 import org.apache.commons.logging.LogFactory;
 57  
 
 58  
 /**
 59  
  * Implementation of {@link MuleContextBuilder} that uses {@link DefaultMuleContext}
 60  
  * as the default {@link MuleContext} implementation and builds it with defaults
 61  
  * values for {@link MuleConfiguration}, {@link LifecycleManager}, {@link WorkManager}, 
 62  
  * {@link WorkListener} and {@link ServerNotificationManager}.
 63  
  */
 64  0
 public class DefaultMuleContextBuilder implements MuleContextBuilder
 65  
 {
 66  0
     protected static final Log logger = LogFactory.getLog(DefaultMuleContextBuilder.class);
 67  
     
 68  
     protected MuleConfiguration config;
 69  
 
 70  
     protected MuleContextLifecycleManager lifecycleManager;
 71  
 
 72  
     protected WorkManager workManager;
 73  
 
 74  
     protected WorkListener workListener;
 75  
 
 76  
     protected ServerNotificationManager notificationManager;
 77  
 
 78  
     protected SplashScreen startupScreen;
 79  
 
 80  
     protected SplashScreen shutdownScreen;
 81  
 
 82  
     /**
 83  
      * {@inheritDoc}
 84  
      */
 85  
     public MuleContext buildMuleContext()
 86  
     {
 87  0
         logger.debug("Building new DefaultMuleContext instance with MuleContextBuilder: " + this);
 88  0
         MuleContextLifecycleManager manager = getLifecycleManager();
 89  0
         DefaultMuleContext muleContext = new DefaultMuleContext(getMuleConfiguration(),
 90  
                                                          getWorkManager(),
 91  
                                                          getWorkListener(),
 92  
                                                          manager,
 93  
                                                          getNotificationManager());
 94  0
         manager.setMuleContext(muleContext);
 95  0
         muleContext.setExecutionClassLoader(Thread.currentThread().getContextClassLoader());
 96  0
         return muleContext;
 97  
     }
 98  
 
 99  
     public void setMuleConfiguration(MuleConfiguration config)
 100  
     {
 101  0
         this.config = config;
 102  0
     }
 103  
     
 104  
     public void setWorkManager(WorkManager workManager)
 105  
     {
 106  0
         this.workManager = workManager;
 107  0
     }
 108  
 
 109  
     public void setWorkListener(WorkListener workListener)
 110  
     {
 111  0
         this.workListener = workListener;
 112  0
     }
 113  
     
 114  
     public void setNotificationManager(ServerNotificationManager notificationManager)
 115  
     {
 116  0
         this.notificationManager = notificationManager;
 117  0
     }
 118  
     
 119  
     protected MuleConfiguration getMuleConfiguration()
 120  
     {
 121  0
         if (config != null)
 122  
         {
 123  0
             return config;
 124  
         }
 125  
         else
 126  
         {
 127  0
             return createMuleConfiguration();
 128  
         }
 129  
     }
 130  
 
 131  
     protected MuleContextLifecycleManager getLifecycleManager()
 132  
     {
 133  0
         if (lifecycleManager != null)
 134  
         {
 135  0
             return lifecycleManager;
 136  
         }
 137  
         else
 138  
         {
 139  0
             return createLifecycleManager();
 140  
         }
 141  
     }
 142  
 
 143  
     public void setLifecycleManager(LifecycleManager manager)
 144  
     {
 145  0
         if (!(manager instanceof MuleContextLifecycleManager))
 146  
         {
 147  0
             Message msg = MessageFactory.createStaticMessage(
 148  
                 "lifecycle manager for MuleContext must be a MuleContextLifecycleManager");
 149  0
             throw new MuleRuntimeException(msg);
 150  
         }
 151  
         
 152  0
         lifecycleManager = (MuleContextLifecycleManager) manager;
 153  0
     }
 154  
 
 155  
     protected WorkManager getWorkManager()
 156  
     {
 157  0
         if (workManager != null)
 158  
         {
 159  0
             return workManager;
 160  
         }
 161  
         else
 162  
         {
 163  0
             return createWorkManager();
 164  
         }
 165  
     }
 166  
 
 167  
     protected WorkListener getWorkListener()
 168  
     {
 169  0
         if (workListener != null)
 170  
         {
 171  0
             return workListener;
 172  
         }
 173  
         else
 174  
         {
 175  0
             return createWorkListener();
 176  
         }
 177  
     }
 178  
 
 179  
     protected ServerNotificationManager getNotificationManager()
 180  
     {
 181  0
         if (notificationManager != null)
 182  
         {
 183  0
             return notificationManager;
 184  
         }
 185  
         else
 186  
         {
 187  0
             return createNotificationManager();
 188  
         }
 189  
     }
 190  
 
 191  
     public SplashScreen getStartupScreen()
 192  
     {
 193  0
         return startupScreen;
 194  
     }
 195  
 
 196  
     public void setStartupScreen(SplashScreen startupScreen)
 197  
     {
 198  0
         this.startupScreen = startupScreen;
 199  0
     }
 200  
 
 201  
     public SplashScreen getShutdownScreen()
 202  
     {
 203  0
         return shutdownScreen;
 204  
     }
 205  
 
 206  
     public void setShutdownScreen(SplashScreen shutdownScreen)
 207  
     {
 208  0
         this.shutdownScreen = shutdownScreen;
 209  0
     }
 210  
 
 211  
     protected DefaultMuleConfiguration createMuleConfiguration()
 212  
     {
 213  0
         return new DefaultMuleConfiguration();
 214  
     }
 215  
 
 216  
     protected MuleContextLifecycleManager createLifecycleManager()
 217  
     {
 218  0
         return new MuleContextLifecycleManager();
 219  
     }
 220  
 
 221  
     protected MuleWorkManager createWorkManager()
 222  
     {
 223  0
         return new MuleWorkManager(ThreadingProfile.DEFAULT_THREADING_PROFILE, "MuleServer", getMuleConfiguration().getShutdownTimeout());
 224  
     }
 225  
 
 226  
     protected DefaultWorkListener createWorkListener()
 227  
     {
 228  0
         return new DefaultWorkListener();
 229  
     }
 230  
 
 231  
     protected ServerNotificationManager createNotificationManager()
 232  
     {
 233  0
         ServerNotificationManager manager = new ServerNotificationManager();
 234  0
         manager.addInterfaceToType(MuleContextNotificationListener.class,
 235  
                                    MuleContextNotification.class);
 236  0
         manager.addInterfaceToType(ModelNotificationListener.class, ModelNotification.class);
 237  0
         manager.addInterfaceToType(RoutingNotificationListener.class, RoutingNotification.class);
 238  0
         manager.addInterfaceToType(ServiceNotificationListener.class,
 239  
                                    ServiceNotification.class);
 240  0
         manager.addInterfaceToType(SecurityNotificationListener.class,
 241  
                                    SecurityNotification.class);
 242  0
         manager.addInterfaceToType(ManagementNotificationListener.class,
 243  
                                    ManagementNotification.class);
 244  0
         manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class);
 245  0
         manager.addInterfaceToType(ConnectionNotificationListener.class,
 246  
                                    ConnectionNotification.class);
 247  0
         manager.addInterfaceToType(RegistryNotificationListener.class,
 248  
                                    RegistryNotification.class);
 249  0
         manager.addInterfaceToType(ExceptionNotificationListener.class,
 250  
                                    ExceptionNotification.class);
 251  0
         manager.addInterfaceToType(TransactionNotificationListener.class,
 252  
                                    TransactionNotification.class);
 253  0
         return manager;
 254  
     }
 255  
 
 256  
     @Override
 257  
     public String toString()
 258  
     {
 259  0
         return ClassUtils.getClassName(getClass()) +
 260  
             "{muleConfiguration=" + config +
 261  
             ", lifecycleManager=" + lifecycleManager +
 262  
             ", workManager=" + workManager +
 263  
             ", workListener=" + workListener +
 264  
             ", notificationManager=" + notificationManager + "}";
 265  
     }
 266  
 }