KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > dotnet > DotnetDefine


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.taskdefs.optional.dotnet;
19
20 import org.apache.tools.ant.BuildException;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.Project;
23
24 /**
25  * definitions can be conditional. What .NET conditions can not be
26  * is in any state other than defined and undefined; you cannot give
27  * a definition a value.
28  */

29 public class DotnetDefine {
30     private String JavaDoc name;
31     private String JavaDoc ifCond;
32     private String JavaDoc unlessCond;
33
34
35     /**
36      * the name of a property which must be defined for
37      * the definition to be set. Optional.
38      * @param condition the name of the property
39      */

40     public void setIf(String JavaDoc condition) {
41         this.ifCond = condition;
42     }
43
44     /**
45      * the name of a property which must be undefined for
46      * the definition to be set. Optional.
47      * @param condition the name of the property
48      */

49     public void setUnless(String JavaDoc condition) {
50         this.unlessCond = condition;
51     }
52
53     /**
54      * Get the name of the definition.
55      * @return the name.
56      */

57     public String JavaDoc getName() {
58         return name;
59     }
60
61     /**
62      * the name of the definition. Required.
63      * @param name the name value.
64      */

65     public void setName(String JavaDoc name) {
66         this.name = name;
67     }
68
69     /**
70      * This method gets the value of this definition. Will be null if a condition
71      * was declared and not met
72      * @param owner owning task
73      * @return The value of the definition.
74      * @throws BuildException if there is an error.
75      */

76     public String JavaDoc getValue(Task owner) throws BuildException {
77         if (name == null) {
78             throw new BuildException("No name provided for the define element",
79                 owner.getLocation());
80         }
81         if (!isSet(owner)) {
82             return null;
83         }
84         return name;
85     }
86
87
88     /**
89      * logic taken from patternset
90      * @param owner the owning task.
91      * @return true if the condition is valid
92      */

93     public boolean isSet(Task owner) {
94         Project p = owner.getProject();
95         if (ifCond != null && p.getProperty(ifCond) == null) {
96             return false;
97         } else if (unlessCond != null && p.getProperty(unlessCond) != null) {
98             return false;
99         }
100         return true;
101     }
102 }
103
Popular Tags