/Users/lyon/j4p/src/javagroup/process/ProcessManagerHolder.java

1    /* 
2     * Copyright (C) 1997 Luke Gorrie 
3     * 
4     * This library is free software; you can redistribute it and/or 
5     * modify it under the terms of the GNU Library General Public 
6     * License as published by the Free Software Foundation; either 
7     * version 2 of the License, or (at your option) any later version. 
8     * 
9     * This library is distributed in the hope that it will be useful, 
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of 
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12    * Library General Public License for more details. 
13    * 
14    * You should have received a copy of the GNU Library General Public 
15    * License along with this library; if not, write to the 
16    * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
17    * MA 02139, USA. 
18    */ 
19    
20   package javagroup.process; 
21    
22   import javagroup.util.Namespace; 
23   import javagroup.util.URLClassLoader; 
24    
25   import java.net.URL; 
26    
27   /** 
28    * Place holder for accessing a ProcessManager. 
29    * 
30    * @author Luke Gorrie 
31    */ 
32   public class ProcessManagerHolder { 
33    
34       /** 
35        * Return a ProcessManager instance.  This method should be used to 
36        * access ProcessManagers rather than direct instantiation. 
37        */ 
38       public static synchronized ProcessManager getProcessManager() { 
39    
40           // grab ProcessManager instance 
41           ProcessManager manager = (ProcessManager) 
42                   Namespace.getNamespace().getInstanceForClass( 
43                           ProcessManager.class); 
44           // if there isn't one, create one using the default implementation 
45           if (manager == null) { 
46               manager = instantiateProcessManager(); 
47    
48               // register the default manager for the Namespace 
49               Namespace 
50                       .registerDefaultInstanceForClass(ProcessManager.class, 
51                               manager); 
52           } 
53    
54           return manager; 
55       } 
56    
57       private static ProcessManager instantiateProcessManager() { 
58    
59           // default classpath 
60           URL[] paths = 
61                   URLClassLoader.decodePathString( 
62                           System.getProperty("default.classpath")); 
63    
64           ProcessManager manager; 
65    
66           // if possible, instantiate a process manager with the default classpath 
67           if (paths != null) 
68               manager = new StandardProcessManager(paths); 
69           else 
70               manager = new StandardProcessManager(); 
71    
72           return manager; 
73       } 
74    
75   } 
76    
77