KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import com.izforge.izpack.Pack;
28 import com.izforge.izpack.util.Debug;
29
30 import net.n3.nanoxml.XMLElement;
31
32 /**
33  * @author Dennis Reil, <Dennis.Reil@reddot.de>
34  * @version $Id: PackselectionCondition.java,v 1.1 2006/11/03 13:03:26 dennis Exp $
35  */

36 public class PackselectionCondition extends Condition
37 {
38
39     protected String JavaDoc packid;
40
41     /**
42      *
43      */

44     public PackselectionCondition()
45     {
46         // TODO Auto-generated constructor stub
47
}
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see de.reddot.installer.rules.Condition#isTrue(java.util.Properties)
53      */

54     private boolean isTrue(Properties JavaDoc variables)
55     {
56         // no information about selected packs given, so return false
57
return false;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
64      */

65     public void readFromXML(XMLElement xmlcondition)
66     {
67         try
68         {
69             this.packid = xmlcondition.getFirstChildNamed("packid").getContent();
70         }
71         catch (Exception JavaDoc e)
72         {
73             Debug.log("missing element in <condition type=\"variable\"/>");
74         }
75     }
76
77     private boolean isTrue(Properties JavaDoc variables, List JavaDoc selectedpacks)
78     {
79         if (selectedpacks != null)
80         {
81             for (Iterator JavaDoc iter = selectedpacks.iterator(); iter.hasNext();)
82             {
83                 Pack p = (Pack) iter.next();
84                 if (packid.equals(p.id))
85                 {
86                     // pack is selected
87
return true;
88                 }
89             }
90         }
91         // pack is not selected
92
return false;
93     }
94
95     public boolean isTrue()
96     {
97         return this.isTrue(this.installdata.getVariables(), this.installdata.selectedPacks);
98     }
99
100 }
101
Popular Tags