KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > optional > ScriptCondition


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

18 package org.apache.tools.ant.types.optional;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.taskdefs.condition.Condition;
22
23 /**
24  * A condition that lets you include script.
25  * The condition component sets a bean "self", whose attribute "value"
26  * must be set to true for the condition to succeed, false to fail.
27  * The default is 'false'
28  */

29 public class ScriptCondition extends AbstractScriptComponent implements Condition {
30
31     /**
32      * result field
33      */

34     private boolean value = false;
35
36
37     /**
38      * Is this condition true?
39      *
40      * @return true if the condition is true
41      *
42      * @throws org.apache.tools.ant.BuildException
43      * if an error occurs
44      */

45     public boolean eval() throws BuildException {
46         initScriptRunner();
47         executeScript("ant_condition");
48         return getValue();
49     }
50
51     /**
52      * get the current value of the conditon
53      * @return true if the condition
54      */

55     public boolean getValue() {
56         return value;
57     }
58
59     /**
60      * set the value of the condition.
61      * This is used by the script to pass the return value.
62      * It can be used by an attribute, in which case it sets the default
63      * value
64      * @param value the value to set the condition to
65      */

66     public void setValue(boolean value) {
67         this.value = value;
68     }
69 }
70
Popular Tags