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.HashMap;
024:
025: import net.n3.nanoxml.XMLElement;
026:
027: import com.izforge.izpack.util.Debug;
028:
029: /**
030: * @author Dennis Reil, <Dennis.Reil@reddot.de>
031: */
032: public class VariableCondition extends Condition {
033:
034: /**
035: *
036: */
037: private static final long serialVersionUID = 2881336115632480575L;
038:
039: protected String variablename;
040:
041: protected String value;
042:
043: public VariableCondition(String variablename, String value,
044: HashMap packstoremove) {
045: super ();
046: this .variablename = variablename;
047: this .value = value;
048: }
049:
050: public VariableCondition(String variablename, String value) {
051: super ();
052: this .variablename = variablename;
053: this .value = value;
054: }
055:
056: public VariableCondition() {
057: super ();
058: }
059:
060: public String getValue() {
061: return value;
062: }
063:
064: public void setValue(String value) {
065: this .value = value;
066: }
067:
068: public String getVariablename() {
069: return variablename;
070: }
071:
072: public void setVariablename(String variablename) {
073: this .variablename = variablename;
074: }
075:
076: /*
077: * (non-Javadoc)
078: *
079: * @see de.reddot.installer.rules.Condition#readFromXML(net.n3.nanoxml.XMLElement)
080: */
081: public void readFromXML(XMLElement xmlcondition) {
082: try {
083: this .variablename = xmlcondition.getFirstChildNamed("name")
084: .getContent();
085: this .value = xmlcondition.getFirstChildNamed("value")
086: .getContent();
087: } catch (Exception e) {
088: Debug
089: .log("missing element in <condition type=\"variable\"/>");
090: }
091:
092: }
093:
094: public boolean isTrue() {
095: if (this .installdata != null) {
096: String val = this .installdata.getVariable(variablename);
097: if (val == null) {
098: return false;
099: } else {
100: return val.equals(value);
101: }
102: } else {
103: return false;
104: }
105: }
106:
107: /* (non-Javadoc)
108: * @see com.izforge.izpack.rules.Condition#getDependenciesDetails()
109: */
110: public String getDependenciesDetails() {
111: StringBuffer details = new StringBuffer();
112: details.append(this .id);
113: details.append(" depends on a value of <b>");
114: details.append(this .value);
115: details.append("</b> on variable <b>");
116: details.append(this .variablename);
117: details.append(" (current value: ");
118: details.append(this .installdata.getVariable(variablename));
119: details.append(")");
120: details.append("</b><br/>");
121: return details.toString();
122: }
123: }
|