01: /*
02: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
03: *
04: * http://izpack.org/
05: * http://izpack.codehaus.org/
06: *
07: * Copyright 2007 Dennis Reil
08: *
09: * 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:
22: package com.izforge.izpack.rules;
23:
24: import net.n3.nanoxml.XMLElement;
25:
26: import com.izforge.izpack.util.Debug;
27:
28: /**
29: * Defines a condition where both operands have to be true
30: *
31: * @author Dennis Reil, <Dennis.Reil@reddot.de>
32: */
33: public class AndCondition extends Condition {
34:
35: /**
36: *
37: */
38: private static final long serialVersionUID = -5854944262991488370L;
39:
40: protected Condition leftoperand;
41:
42: protected Condition rightoperand;
43:
44: /**
45: *
46: */
47: public AndCondition() {
48: super ();
49: }
50:
51: /**
52: *
53: */
54: public AndCondition(Condition operand1, Condition operand2) {
55: this .leftoperand = operand1;
56: this .rightoperand = operand2;
57: }
58:
59: /*
60: * (non-Javadoc)
61: *
62: * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
63: */
64: public void readFromXML(XMLElement xmlcondition) {
65: try {
66: if (xmlcondition.getChildrenCount() != 2) {
67: Debug
68: .log("and-condition needs two conditions as operands");
69: return;
70: }
71: this .leftoperand = RulesEngine
72: .analyzeCondition(xmlcondition.getChildAtIndex(0));
73: this .rightoperand = RulesEngine
74: .analyzeCondition(xmlcondition.getChildAtIndex(1));
75: } catch (Exception e) {
76: Debug.log("missing element in and-condition");
77: }
78: }
79:
80: public boolean isTrue() {
81: return leftoperand.isTrue() && rightoperand.isTrue();
82: }
83:
84: /* (non-Javadoc)
85: * @see com.izforge.izpack.rules.Condition#getDependenciesDetails()
86: */
87: public String getDependenciesDetails() {
88: StringBuffer details = new StringBuffer();
89: details.append(this .id);
90: details.append(" depends on:<ul><li>");
91: details.append(leftoperand.getDependenciesDetails());
92: details.append("</li> AND <li>");
93: details.append(rightoperand.getDependenciesDetails());
94: details.append("</li></ul>");
95: return details.toString();
96: }
97: }
|