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: package com.izforge.izpack.rules;
22:
23: import net.n3.nanoxml.XMLElement;
24:
25: import com.izforge.izpack.util.Debug;
26:
27: /**
28: * @author Dennis Reil, <Dennis.Reil@reddot.de>
29: * @version $Id: XOrCondition.java,v 1.1 2006/09/29 14:40:38 dennis Exp $
30: */
31: public class XOrCondition extends OrCondition {
32:
33: /**
34: *
35: */
36: private static final long serialVersionUID = 3148555083095194992L;
37:
38: /**
39: *
40: */
41: public XOrCondition() {
42: super ();
43: }
44:
45: /**
46: * @param operand1
47: * @param operand2
48: */
49: public XOrCondition(Condition operand1, Condition operand2) {
50: super (operand1, operand2);
51: }
52:
53: /*
54: * (non-Javadoc)
55: *
56: * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
57: */
58: public void readFromXML(XMLElement xmlcondition) {
59: try {
60: if (xmlcondition.getChildrenCount() != 2) {
61: Debug
62: .log("xor-condition needs two conditions as operands");
63: return;
64: }
65: this .leftoperand = RulesEngine
66: .analyzeCondition(xmlcondition.getChildAtIndex(0));
67: this .rightoperand = RulesEngine
68: .analyzeCondition(xmlcondition.getChildAtIndex(1));
69: } catch (Exception e) {
70: Debug.log("missing element in xor-condition");
71: }
72: }
73:
74: public boolean isTrue() {
75: boolean op1true = leftoperand.isTrue();
76: boolean op2true = rightoperand.isTrue();
77:
78: if (op1true && op2true) {
79: // in case where both are true
80: return false;
81: }
82: return op1true || op2true;
83: }
84:
85: /* (non-Javadoc)
86: * @see com.izforge.izpack.rules.OrCondition#getDependenciesDetails()
87: */
88: public String getDependenciesDetails() {
89: StringBuffer details = new StringBuffer();
90: details.append(this .id);
91: details.append(" depends on:<ul><li>");
92: details.append(leftoperand.getDependenciesDetails());
93: details.append("</li> XOR <li>");
94: details.append(rightoperand.getDependenciesDetails());
95: details.append("</li></ul>");
96: return details.toString();
97: }
98: }
|