KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > launcher > CommandFactory


1 /*====================================================================
2
3 ObjectWeb Util Launcher Package.
4 Copyright (C) 2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Romain Rouvoy.
23 Contributor(s): .
24
25 --------------------------------------------------------------------
26 $Id: CommandFactory.java,v 1.1 2004/05/19 15:58:29 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.launcher ;
30
31
32 import java.util.Properties JavaDoc ;
33
34
35 /**
36  * Implementation of a particular Java Command which takes into account.
37  * <ul>
38  * <li>an Identifier for the command</li>
39  * <li>a bootstrap class name for executing the command</li>
40  * <li>a specific classloader where class are stored</li>
41  * <li>a list of java properties to associate to the command</li>
42  * <li>a list of arguments to give to the bootstrap class</li>
43  * <li>a particular mode of execution</li>
44  * </ul>
45  *
46  * <p>
47  * This command represent most of the command which could be executed
48  * in the context of Java developements.
49  * </p>
50  *
51  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
52  * @version 0.2
53  */

54 public class CommandFactory
55 {
56     /** Singleton for the CommandFactory */
57     protected static CommandFactory factory_ = null ;
58     
59     /** List of default Properties */
60     protected Properties JavaDoc default_properties_ ;
61     /** List of default Arguments */
62     protected StringList default_arguments_ ;
63     /** Description of the default classpath */
64     protected StringList default_classpath_ ;
65     
66
67     /**
68      * Default Constructor
69      *
70      */

71     public CommandFactory() {
72         this.default_properties_ = new Properties JavaDoc();
73         this.default_arguments_ = new StringList();
74         this.default_classpath_ = new StringList();
75     }
76
77     /**
78      * Retrieves default properties for the factory.
79      * @return previously defined properties.
80      */

81     public Properties JavaDoc getDefaultProperties() {
82         return this.default_properties_;
83     }
84
85     /**
86      * Retrieves default arguments for the factory.
87      * @return previously defined arguments.
88      */

89     public StringList getDefaultArguments() {
90         return this.default_arguments_;
91     }
92
93     /**
94      * Retrieves the default classpath.
95      * @return previously defined classpath.
96      */

97     public StringList getDefaultClasspath() {
98         return this.default_classpath_;
99     }
100
101     /**
102      * Creates a new instance of pre-configured command.
103      * @return the instance of a pre-configured command.
104      */

105     public CommandJava create() {
106         CommandJava cmd = new CommandJava(new XBootClassLoader());
107         cmd.addProperties(getDefaultProperties());
108         cmd.addArguments(getDefaultArguments());
109         try {
110             cmd.getLoader().addURL(getDefaultClasspath().toStringArray());
111         } catch (java.net.MalformedURLException JavaDoc ex) {
112             throw new LauncherException(ex);
113         }
114         return cmd;
115     }
116
117     /**
118      * Singleton access method to the CommandFactory.
119      * @return the default instance of CommandFactory.
120      */

121     public static CommandFactory instance() {
122         if (factory_ == null) factory_ = new CommandFactory();
123         return factory_ ;
124     }
125 }
126
Popular Tags