View Javadoc

1   /*
2    * $Id: ApplicationFactory.java 20320 2010-11-24 15:03:31Z dfeist $
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.module.launcher.AppBloodhound;
14  import org.mule.module.launcher.DefaultAppBloodhound;
15  import org.mule.module.launcher.DeploymentService;
16  import org.mule.module.launcher.descriptor.ApplicationDescriptor;
17  
18  import java.io.IOException;
19  
20  /**
21   * Responsible for creating application objects. E.g. handles the default/priviledged app,
22   * wrapper objects, etc.
23   */
24  public class ApplicationFactory
25  {
26      protected DeploymentService deploymentService;
27  
28      public ApplicationFactory(DeploymentService deploymentService)
29      {
30          this.deploymentService = deploymentService;
31      }
32  
33      public Application createApp(String appName) throws IOException
34      {
35          AppBloodhound bh = new DefaultAppBloodhound();
36          final ApplicationDescriptor descriptor = bh.fetch(appName);
37          if (descriptor.isPriviledged())
38          {
39              final PriviledgedMuleApplication delegate = new PriviledgedMuleApplication(appName);
40              delegate.setDeploymentService(deploymentService);
41              return new ApplicationWrapper(delegate);
42          }
43          else
44          {
45              return new ApplicationWrapper(new DefaultMuleApplication(appName));
46          }
47      }
48  }