KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > launcher > option > OptionProperty


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: OptionProperty.java,v 1.2 2005/02/03 17:04:45 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.launcher.option;
30
31
32
33 import jregex.Pattern;
34 import jregex.RETokenizer;
35
36 import org.objectweb.util.cmdline.api.Iterator;
37 import org.objectweb.util.cmdline.lib.DefaultOptionArgument;
38 import org.objectweb.util.launcher.CommandFactory;
39
40
41 /**
42  * Definition of the --runid option.<BR>
43  * <p>
44  * This option specify the run identifier to use for starting the
45  * application.
46  * </p>
47  *
48  * @author <a HREF="mailto:Romain.Rouvoy@lifl.fr">Romain Rouvoy</a>
49  * @version 0.1
50  */

51 public class OptionProperty
52      extends DefaultOptionArgument
53 {
54     /** Short Tag Description */
55     public final static String JavaDoc shortTag = "-D" ;
56     /** Long Tag Description */
57     public final static String JavaDoc longTag = "--prop" ;
58
59     /**
60      * Default Constructor
61      */

62     public OptionProperty() {
63         super(new String JavaDoc[]{shortTag, longTag},
64               "<name=value>",
65               "The property to set",
66               "");
67     }
68
69     // ==================================================================
70
//
71
// Public methods for interface org.objectweb.util.cmdline.api.Option
72
//
73
// ==================================================================
74

75     /**
76      * Consumes command line arguments from an iterator.
77      *
78      * @param iterator The command line argument iterator.
79      */

80     public void consume(Iterator iterator) {
81         setArgument(consumeArgument(iterator));
82         String JavaDoc[] p = (new RETokenizer(new Pattern("="),getArgument())).split();
83         if (p.length==2)
84             CommandFactory.instance().getDefaultProperties().put(p[0],p[1]);
85         else if (p.length==1)
86             CommandFactory.instance().getDefaultProperties().put(p[0],"");
87     }
88
89     /**
90      * Creates a commandline representation of the property.
91      * @param value value of the property.
92      * @return commandline representation of the property.
93      */

94     public static String JavaDoc create(String JavaDoc name, String JavaDoc value) {
95         return shortTag+" "+name+"="+value+" " ;
96     }
97 }
98
Popular Tags