View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.launcher.application;
8   
9   import org.mule.module.launcher.AppBloodhound;
10  import org.mule.module.launcher.DefaultAppBloodhound;
11  import org.mule.module.launcher.DeploymentService;
12  import org.mule.module.launcher.descriptor.ApplicationDescriptor;
13  
14  import java.io.IOException;
15  
16  /**
17   * Responsible for creating application objects. E.g. handles the default/priviledged app,
18   * wrapper objects, etc.
19   */
20  public class ApplicationFactory
21  {
22      protected DeploymentService deploymentService;
23  
24      public ApplicationFactory(DeploymentService deploymentService)
25      {
26          this.deploymentService = deploymentService;
27      }
28  
29      public Application createApp(String appName) throws IOException
30      {
31          AppBloodhound bh = new DefaultAppBloodhound();
32          final ApplicationDescriptor descriptor = bh.fetch(appName);
33          if (descriptor.isPriviledged())
34          {
35              final PriviledgedMuleApplication delegate = new PriviledgedMuleApplication(appName);
36              delegate.setDeploymentService(deploymentService);
37              return new ApplicationWrapper(delegate);
38          }
39          else
40          {
41              return new ApplicationWrapper(new DefaultMuleApplication(appName));
42          }
43      }
44  }