KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > rules > VariableCondition


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2007 Dennis Reil
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21 package com.izforge.izpack.rules;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import net.n3.nanoxml.XMLElement;
27 import com.izforge.izpack.util.Debug;
28
29 /**
30  * @author Dennis Reil, <Dennis.Reil@reddot.de>
31  */

32 public class VariableCondition extends Condition
33 {
34
35     protected String JavaDoc variablename;
36
37     protected String JavaDoc value;
38
39     public VariableCondition(String JavaDoc variablename, String JavaDoc value, HashMap JavaDoc packstoremove)
40     {
41         super();
42         this.variablename = variablename;
43         this.value = value;
44     }
45
46     public VariableCondition(String JavaDoc variablename, String JavaDoc value)
47     {
48         super();
49         this.variablename = variablename;
50         this.value = value;
51     }
52
53     public VariableCondition()
54     {
55         super();
56     }
57
58     public String JavaDoc getValue()
59     {
60         return value;
61     }
62
63     public void setValue(String JavaDoc value)
64     {
65         this.value = value;
66     }
67
68     public String JavaDoc getVariablename()
69     {
70         return variablename;
71     }
72
73     public void setVariablename(String JavaDoc variablename)
74     {
75         this.variablename = variablename;
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
82      */

83     public void readFromXML(XMLElement xmlcondition)
84     {
85         try
86         {
87             this.variablename = xmlcondition.getFirstChildNamed("name").getContent();
88             this.value = xmlcondition.getFirstChildNamed("value").getContent();
89         }
90         catch (Exception JavaDoc e)
91         {
92             Debug.log("missing element in <condition type=\"variable\"/>");
93         }
94
95     }
96
97     public boolean isTrue()
98     {
99         String JavaDoc val = this.installdata.getVariable(variablename);
100         if (val == null)
101         {
102             return false;
103         }
104         else
105         {
106             return val.equals(value);
107         }
108     }
109 }
Popular Tags