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 java.util.Iterator;
024: import java.util.List;
025: import java.util.Properties;
026:
027: import com.izforge.izpack.Pack;
028: import com.izforge.izpack.util.Debug;
029:
030: import net.n3.nanoxml.XMLElement;
031:
032: /**
033: * @author Dennis Reil, <Dennis.Reil@reddot.de>
034: * @version $Id: PackselectionCondition.java,v 1.1 2006/11/03 13:03:26 dennis Exp $
035: */
036: public class PackselectionCondition extends Condition {
037:
038: /**
039: *
040: */
041: private static final long serialVersionUID = 9193011814966195963L;
042: protected String packid;
043:
044: /**
045: *
046: */
047: public PackselectionCondition() {
048: // TODO Auto-generated constructor stub
049: }
050:
051: /*
052: * (non-Javadoc)
053: *
054: * @see de.reddot.installer.rules.Condition#isTrue(java.util.Properties)
055: */
056: private boolean isTrue(Properties variables) {
057: // no information about selected packs given, so return false
058: return false;
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
065: */
066: public void readFromXML(XMLElement xmlcondition) {
067: try {
068: this .packid = xmlcondition.getFirstChildNamed("packid")
069: .getContent();
070: } catch (Exception e) {
071: Debug
072: .log("missing element in <condition type=\"variable\"/>");
073: }
074: }
075:
076: private boolean isTrue(Properties variables, List selectedpacks) {
077: if (selectedpacks != null) {
078: for (Object selectedpack : selectedpacks) {
079: Pack p = (Pack) selectedpack;
080: if (packid.equals(p.id)) {
081: // pack is selected
082: return true;
083: }
084: }
085: }
086: // pack is not selected
087: return false;
088: }
089:
090: public boolean isTrue() {
091: return this .isTrue(this .installdata.getVariables(),
092: this .installdata.selectedPacks);
093: }
094:
095: /* (non-Javadoc)
096: * @see com.izforge.izpack.rules.Condition#getDependenciesDetails()
097: */
098: public String getDependenciesDetails() {
099: StringBuffer details = new StringBuffer();
100: details.append(this .id);
101: details.append("depends on the selection of pack <b>");
102: details.append(this .packid);
103: details.append("</b><br/>");
104: return details.toString();
105: }
106:
107: }
|