001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 Dennis Reil
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021: package com.izforge.izpack.rules;
022:
023: import net.n3.nanoxml.XMLElement;
024:
025: import com.izforge.izpack.util.Debug;
026:
027: /**
028: * @author Dennis Reil, <Dennis.Reil@reddot.de>
029: * @version $Id: OrCondition.java,v 1.1 2006/09/29 14:40:38 dennis Exp $
030: */
031: public class OrCondition extends Condition {
032:
033: /**
034: *
035: */
036: private static final long serialVersionUID = 8341350377205144199L;
037:
038: protected Condition leftoperand;
039:
040: protected Condition rightoperand;
041:
042: /**
043: *
044: */
045: public OrCondition() {
046: super ();
047: // TODO Auto-generated constructor stub
048: }
049:
050: /**
051: *
052: */
053: public OrCondition(Condition operand1, Condition operand2) {
054: this .leftoperand = operand1;
055: this .rightoperand = operand2;
056: }
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see de.reddot.installer.util.Condition#isTrue()
062: */
063: /*
064: * public boolean isTrue(Properties variables) { return this.leftoperand.isTrue(variables) ||
065: * this.rightoperand.isTrue(variables); }
066: */
067: /*
068: * (non-Javadoc)
069: *
070: * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
071: */
072: public void readFromXML(XMLElement xmlcondition) {
073: try {
074: if (xmlcondition.getChildrenCount() != 2) {
075: Debug
076: .log("or-condition needs two conditions as operands");
077: return;
078: }
079: this .leftoperand = RulesEngine
080: .analyzeCondition(xmlcondition.getChildAtIndex(0));
081: this .rightoperand = RulesEngine
082: .analyzeCondition(xmlcondition.getChildAtIndex(1));
083: } catch (Exception e) {
084: Debug.log("missing element in or-condition");
085: }
086: }
087:
088: /*
089: * public boolean isTrue(Properties variables, List selectedpacks) { return
090: * this.leftoperand.isTrue(variables, selectedpacks) || this.rightoperand.isTrue(variables,
091: * selectedpacks); }
092: */
093: public boolean isTrue() {
094: return this .leftoperand.isTrue() || this .rightoperand.isTrue();
095: }
096:
097: /* (non-Javadoc)
098: * @see com.izforge.izpack.rules.Condition#getDependenciesDetails()
099: */
100: public String getDependenciesDetails() {
101: StringBuffer details = new StringBuffer();
102: details.append(this .id);
103: details.append(" depends on:<ul><li>");
104: details.append(leftoperand.getDependenciesDetails());
105: details.append("</li> OR <li>");
106: details.append(rightoperand.getDependenciesDetails());
107: details.append("</li></ul>");
108: return details.toString();
109: }
110: }
|