View Javadoc

1   /*
2    * $Id: ApplicationFactory.java 22568 2011-07-28 18:52:55Z julien.eluard $
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.application;
12  
13  import org.mule.MuleCoreExtension;
14  import org.mule.module.launcher.AppBloodhound;
15  import org.mule.module.launcher.DefaultAppBloodhound;
16  import org.mule.module.launcher.DeploymentService;
17  import org.mule.module.launcher.descriptor.ApplicationDescriptor;
18  
19  import java.io.IOException;
20  import java.util.Map;
21  
22  /**
23   * Responsible for creating application objects. E.g. handles the default/priviledged app,
24   * wrapper objects, etc.
25   */
26  public class ApplicationFactory
27  {
28      protected DeploymentService deploymentService;
29      protected Map<Class<? extends MuleCoreExtension>, MuleCoreExtension> coreExtensions;
30  
31      public ApplicationFactory(DeploymentService deploymentService, Map<Class<? extends MuleCoreExtension>, MuleCoreExtension> coreExtensions)
32      {
33          this.deploymentService = deploymentService;
34          this.coreExtensions = coreExtensions;
35      }
36  
37      public Application createApp(String appName) throws IOException
38      {
39          AppBloodhound bh = new DefaultAppBloodhound();
40          final ApplicationDescriptor descriptor = bh.fetch(appName);
41          if (descriptor.isPrivileged())
42          {
43              final PriviledgedMuleApplication delegate = new PriviledgedMuleApplication(descriptor);
44              delegate.setDeploymentService(deploymentService);
45              delegate.setCoreExtensions(coreExtensions);
46              return new ApplicationWrapper(delegate);
47          }
48          else
49          {
50              final DefaultMuleApplication delegate = new DefaultMuleApplication(descriptor);
51              delegate.setDeploymentService(deploymentService);
52              return new ApplicationWrapper(delegate);
53          }
54      }
55  }