KickJava   Java API By Example, From Geeks To Geeks.

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


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.DataType;
23 import org.apache.tools.ant.types.Path;
24
25 /**
26  * A class that represents nested <sysproperty> or <env> elements. This class
27  * provides the same functionality as the class that represents these same
28  * elements in a "java" task. In addition, this class supports conditional "if"
29  * and "unless" attributes.
30  *
31  * @author Patrick Luby
32  */

33 public class ConditionalVariable extends DataType {
34
35     //------------------------------------------------------------------ Fields
36

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

40     private String JavaDoc ifCondition = null;
41
42     /**
43      * Cached key.
44      */

45     private String JavaDoc key = null;
46
47     /**
48      * Cached "unless" condition flag.
49      */

50     private String JavaDoc unlessCondition = null;
51
52     /**
53      * Cached value.
54      */

55     private String JavaDoc value = null;
56
57     //----------------------------------------------------------------- Methods
58

59     /**
60      * Get the "if" condition flag.
61      *
62      * @return the "if" condition flag
63      */

64     public String JavaDoc getIf() {
65
66         return ProjectHelper.replaceProperties(project, ifCondition, project.getProperties());
67
68     }
69
70     /**
71      * Get the key.
72      *
73      * @return the key for this variable
74      */

75     public String JavaDoc getKey() {
76
77         return ProjectHelper.replaceProperties(project, key, project.getProperties());
78
79     }
80
81     /**
82      * Get the "unless" condition flag.
83      *
84      * @return the "unless" condition flag
85      */

86     public String JavaDoc getUnless() {
87  
88         return ProjectHelper.replaceProperties(project, unlessCondition, project.getProperties());
89
90     }
91
92     /**
93      * Get the value.
94      *
95      * @return the value for this variable
96      */

97     public String JavaDoc getValue() {
98
99         return ProjectHelper.replaceProperties(project, value, project.getProperties());
100
101     }
102
103     /**
104      * Set the value to a {@link File}.
105      *
106      * @param value the {@link File} for this variable
107      */

108     public void setFile(File JavaDoc file) {
109
110         this.value = file.getAbsolutePath();
111
112     }
113
114     /**
115      * Set the value to a {@link Path}.
116      *
117      * @param value the {@link Path} for this variable
118      */

119     public void setPath(Path path) {
120
121         this.value = path.toString();
122
123     }
124
125     /**
126      * Set the "if" condition. Tasks that nest this class as an element
127      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
128      * following conditions are true, the task should process this element:
129      * <ul>
130      * <ol>The flag is neither null nor a empty string
131      * <ol>The property that the flag resolves to after macro substitution
132      * is defined
133      * </ul>
134      *
135      * @param property a property name or macro
136      */

137     public void setIf(String JavaDoc property) {
138  
139         this.ifCondition = property;
140
141     }
142
143     /**
144      * Set the key.
145      *
146      * @param key the key for this variable
147      */

148     public void setKey(String JavaDoc key) {
149
150         this.key = key;
151
152     }
153
154     /**
155      * Set the value to a {@link Path}.
156      *
157      * @param value the {@link Path} for this variable
158      */

159     public void setFile(Path path) {
160
161         this.value = path.toString();
162
163     }
164
165     /**
166      * Set the "unless" condition. Tasks that nest this class as an element
167      * should evaluate this flag in their {@link org.apache.tools.ant.Task#execute()} method. If the
168      * following conditions are true, the task should ignore this element:
169      * <ul>
170      * <ol>The flag is neither null nor a empty string
171      * <ol>The property that the flag resolves to after macro substitution
172      * is defined
173      * </ul>
174      *
175      * @param property a property name or macro
176      */

177     public void setUnless(String JavaDoc property) {
178  
179         this.unlessCondition = property;
180
181     }
182
183     /**
184      * Set the value.
185      *
186      * @param value the value for this variable
187      */

188     public void setValue(String JavaDoc value) {
189
190         this.value = value;
191
192     }
193
194 }
195
Popular Tags