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