001: package com.opensymphony.workflow.loader;
002:
003: import java.io.PrintWriter;
004: import java.util.ArrayList;
005: import java.util.HashMap;
006: import java.util.List;
007: import java.util.Map;
008:
009: import org.w3c.dom.Element;
010:
011: /**
012: * @author baab
013: */
014: public class ConfigConditionDescriptor extends ConditionDescriptor
015: implements ArgsAware {
016: protected String plugin;
017: protected String description;
018: protected String displayName;
019: protected List modifiableArgs = new ArrayList();
020: protected Map argTypeMap = new HashMap();
021: private PaletteDescriptor palette;
022:
023: public ConfigConditionDescriptor(PaletteDescriptor palette) {
024: this .palette = palette;
025: }
026:
027: public ConfigConditionDescriptor(PaletteDescriptor palette,
028: Element condition) {
029: this .palette = palette;
030: init(condition);
031: }
032:
033: public ConfigConditionDescriptor(ConfigConditionDescriptor other) {
034: this .setPlugin(other.getPlugin());
035: this .setName(other.getName());
036: this .setNegate(other.isNegate());
037: this .setType(other.getType());
038: this .getArgs().putAll(other.getArgs());
039: displayName = other.displayName;
040: description = other.description;
041: modifiableArgs = other.modifiableArgs;
042: palette = other.palette;
043: }
044:
045: public PaletteDescriptor getPalette() {
046: return palette;
047: }
048:
049: public void setPalette(PaletteDescriptor palette) {
050: this .palette = palette;
051: }
052:
053: protected void init(Element condition) {
054: type = condition.getAttribute("type");
055:
056: String n = condition.getAttribute("negate");
057: if ("true".equalsIgnoreCase(n) || "yes".equalsIgnoreCase(n)) {
058: negate = true;
059: } else {
060: negate = false;
061: }
062:
063: List args = XMLUtil.getChildElements(condition, "arg");
064: for (int l = 0; l < args.size(); l++) {
065: Element arg = (Element) args.get(l);
066: this .args.put(arg.getAttribute("name"), XMLUtil
067: .getText(arg));
068: if ("true".equals(arg.getAttribute("modifiable"))) {
069: modifiableArgs.add(arg.getAttribute("name"));
070: String sArgType = arg.getAttribute("argtype");
071: if (sArgType != null) {
072: ArgType at = (ArgType) palette.getArgType(sArgType);
073: if (at != null) {
074: argTypeMap.put(arg.getAttribute("name"), at);
075: }
076: }
077: }
078: }
079: plugin = XMLUtil.getChildText(condition, "plugin");
080: name = XMLUtil.getChildText(condition, "name");
081: }
082:
083: public boolean isArgModifiable(String name) {
084: return modifiableArgs.contains(name);
085: }
086:
087: public ArgType getArgType(String name) {
088: return (ArgType) argTypeMap.get(name);
089: }
090:
091: public void writeXML(PrintWriter writer, int indent) {
092: throw new UnsupportedOperationException();
093: }
094:
095: public String getDescription() {
096: return description;
097: }
098:
099: public String getDisplayName() {
100: return displayName;
101: }
102:
103: public void setDisplayName(String displayName) {
104: this .displayName = displayName;
105: }
106:
107: public String getPlugin() {
108: return plugin;
109: }
110:
111: public void setDescription(String string) {
112: description = string;
113: }
114:
115: public void setPlugin(String string) {
116: plugin = string;
117: }
118:
119: public String toString() {
120: return displayName != null ? displayName : name;
121: }
122: }
|