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 Andrea Capitani (a.capitani@leonardomultimedia.it)
013: */
014: public class ConfigValidatorDescriptor extends ValidatorDescriptor
015: implements ArgsAware {
016: protected String name;
017: protected String plugin;
018: protected String description;
019: protected List modifiableArgs = new ArrayList();
020: protected Map argTypeMap = new HashMap();
021: private PaletteDescriptor palette;
022:
023: public ConfigValidatorDescriptor(PaletteDescriptor palette) {
024: this .palette = palette;
025: }
026:
027: public ConfigValidatorDescriptor(PaletteDescriptor palette,
028: Element validator) {
029: this .palette = palette;
030: init(validator);
031: }
032:
033: public ConfigValidatorDescriptor(ConfigValidatorDescriptor other) {
034: this .setPlugin(other.getPlugin());
035: this .setName(other.getName());
036: this .setType(other.getType());
037: this .getArgs().putAll(other.getArgs());
038: description = other.description;
039: modifiableArgs = other.modifiableArgs;
040: palette = other.palette;
041: }
042:
043: public PaletteDescriptor getPalette() {
044: return palette;
045: }
046:
047: public void setPalette(PaletteDescriptor palette) {
048: this .palette = palette;
049: }
050:
051: protected void init(Element validator) {
052: type = validator.getAttribute("type");
053:
054: List args = XMLUtil.getChildElements(validator, "arg");
055: for (int l = 0; l < args.size(); l++) {
056: Element arg = (Element) args.get(l);
057: this .args.put(arg.getAttribute("name"), XMLUtil
058: .getText(arg));
059: if ("true".equals(arg.getAttribute("modifiable"))) {
060: modifiableArgs.add(arg.getAttribute("name"));
061: String sArgType = arg.getAttribute("argtype");
062: if (sArgType != null) {
063: ArgType at = (ArgType) palette.getArgType(sArgType);
064: if (at != null) {
065: argTypeMap.put(arg.getAttribute("name"), at);
066: }
067: }
068: }
069: }
070: plugin = XMLUtil.getChildText(validator, "plugin");
071: name = XMLUtil.getChildText(validator, "name");
072: }
073:
074: public boolean isArgModifiable(String name) {
075: return modifiableArgs.contains(name);
076: }
077:
078: public ArgType getArgType(String name) {
079: return (ArgType) argTypeMap.get(name);
080: }
081:
082: public void writeXML(PrintWriter writer, int indent) {
083: throw new UnsupportedOperationException();
084: }
085:
086: public String getDescription() {
087: return description;
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: public void setName(String name) {
095: this .name = name;
096: }
097:
098: public String getPlugin() {
099: return plugin;
100: }
101:
102: public void setDescription(String string) {
103: description = string;
104: }
105:
106: public void setPlugin(String string) {
107: plugin = string;
108: }
109:
110: public String toString() {
111: return getName();
112: }
113: }
|