KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > launcher > types > ConditionalArgument


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.launcher.types;
18
19 import java.io.File JavaDoc;
20
21 import org.apache.tools.ant.ProjectHelper;
22 import org.apache.tools.ant.types.Commandline;
23 import org.apache.tools.ant.types.DataType;
24 import org.apache.tools.ant.types.Path;
25
26 /**
27  * A class that represents nested <arg> or <jvmarg> elements. This class
28  * provides the same functionality as the class that represents these same
29  * elements in a "java" task. In addition, this class supports conditional "if"
30  * and "unless" attributes.
31  *
32  * @author Patrick Luby
33  */

34 public class ConditionalArgument extends DataType {
35
36     //------------------------------------------------------------------ Fields
37

38     /**
39      * Cached "if" condition flag.
40      */

41     private String JavaDoc ifCondition = null;
42
43     /**
44      * Cached "unless" condition flag.
45      */

46     private String JavaDoc unlessCondition = null;
47
48     /**
49      * Cached command line arguments.
50      */

51     private String JavaDoc[] parts = null;
52
53     //----------------------------------------------------------------- Methods
54

55     /**
56      * Get the "if" condition flag.
57      *
58      * @return the "if" condition flag
59      */

60     public String JavaDoc getIf() {
61  
62         return ProjectHelper.replaceProperties(project, ifCondition, project.getProperties());
63
64     }
65
66     /**
67      * Get a single command line argument.
68      *
69      * @return a single command line argument
70      */

71     public String JavaDoc[] getParts() {
72
73         String JavaDoc[] list = new String JavaDoc[parts.length];
74         for (int i = 0; i < parts.length; i++)
75             list[i] = ProjectHelper.replaceProperties(project, parts[i], project.getProperties());
76         return list;
77
78     }
79
80     /**
81      * Get the "unless" condition flag.
82      *
83      * @return the "unless" condition flag
84      */

85     public String JavaDoc getUnless() {
86  
87         return ProjectHelper.replaceProperties(project, unlessCondition, project.getProperties());
88
89     }
90
91     /**
92      * Set a single command line argument to the absolute
93      * filename of the specified file.
94      *
95      * @param file a single command line argument
96      */

97     public void setFile(File JavaDoc file) {
98
99         this.parts = new String JavaDoc[]{ file.getAbsolutePath() };
100
101     }
102
103     /**
104      * Set the "if" condition. Tasks that nest this class as an element
105      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
106      * following conditions are true, the task should process this element:
107      * <ul>
108      * <ol>The flag is neither null nor a empty string
109      * <ol>The property that the flag resolves to after macro substitution
110      * is defined
111      * </ul>
112      *
113      * @param property a property name or macro
114      */

115     public void setIf(String JavaDoc property) {
116  
117         this.ifCondition = property;
118
119     }
120
121     /**
122      * Set a line to split into several command line arguments.
123      *
124      * @param line line to split into several commandline arguments
125      */

126     public void setLine(String JavaDoc line) {
127
128         parts = Commandline.translateCommandline(line);
129
130     }
131
132     /**
133      * Set a single command line argument and treat it like a path. The
134      * correct path separator for the platform is used.
135      *
136      * @param path a single command line argument
137      */

138     public void setPath(Path path) {
139
140         this.parts = new String JavaDoc[]{ path.toString() };
141
142     }
143
144     /**
145      * Set the "unless" condition. Tasks that nest this class as an element
146      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
147      * following conditions are true, the task should ignore this element:
148      * <ul>
149      * <ol>The flag is neither null nor a empty string
150      * <ol>The property that the flag resolves to after macro substitution
151      * is defined
152      * </ul>
153      *
154      * @param property a property name or macro
155      */

156     public void setUnless(String JavaDoc property) {
157  
158         this.unlessCondition = property;
159
160     }
161
162     /**
163      * Set a single command line argument.
164      *
165      * @param value a single command line argument
166      */

167     public void setValue(String JavaDoc value) {
168
169         this.parts = new String JavaDoc[]{ value };
170
171     }
172
173 }
174
Popular Tags