View Javadoc
1   package org.codehaus.mojo.natives.manager;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.codehaus.mojo.natives.EnvFactory;
7   import org.codehaus.mojo.natives.NativeBuildException;
8   import org.codehaus.plexus.component.annotations.Component;
9   
10  /**
11   * Construct EnvFactory
12   */
13  @Component(role = EnvFactoryManager.class, hint = "default", instantiationStrategy = "singleton")
14  public class DefaultEnvFactoryManager
15      implements EnvFactoryManager
16  {
17      private Map envFactoryCache = new HashMap();
18  
19      public EnvFactory getEnvFactory( String className )
20          throws NativeBuildException
21      {
22          EnvFactory envFactory = (EnvFactory) envFactoryCache.get( className );
23  
24          if ( envFactory == null )
25          {
26              try
27              {
28                  envFactory = (EnvFactory) Class.forName( className ).newInstance();
29                  envFactoryCache.put( className, envFactory );
30              }
31              catch ( Exception e )
32              {
33                  throw new NativeBuildException( "Unable to find EnvFactory: " + className );
34              }
35          }
36  
37          return envFactory;
38  
39      }
40  
41  }