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