001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKMarkupParamCall.java,v 1.6 2000/06/01 15:02:56 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import com.teamkonzept.lib.*;
008:
009: public class TKMarkupParamCall implements TKSortable {
010:
011: public TKMarkupParamDefinition param;
012:
013: public String name;
014: public boolean isOptional;
015: public boolean useDefault;
016: public boolean editable;
017:
018: // bitte NICHT ˆffentlich machen
019: private String defaultValue;
020: private TKMarkupStatics statics = TKMarkupStatics.setup();
021:
022: public TKMarkupParamCall(String name, String paramName,
023: boolean isOptional, boolean useDefault, boolean editable,
024: String defaultValue) {
025:
026: if ((name == null) || (name.length() == 0))
027: throw new Error(
028: "Markup-Parameter-Name in der Definition fehlt");
029:
030: if ((paramName == null) || (paramName.length() == 0))
031: throw new Error(
032: "Markup-Parameter-Name in der Definition fehlt");
033:
034: this .name = name.toUpperCase();
035: this .isOptional = isOptional;
036: this .useDefault = useDefault;
037: this .editable = editable;
038: this .param = paramName != null ? TKMarkupParamDefinition
039: .lookup(statics, paramName.toUpperCase()) : null;
040:
041: setDefaultValue(defaultValue);
042:
043: if (this .param == null)
044: throw new Error("Markup-Parameter '" + name + "/"
045: + paramName + "': Definition fehlt");
046: }
047:
048: public TKMarkupParamCall(String name, int paramId,
049: boolean isOptional, boolean useDefault, boolean editable,
050: String defaultValue) {
051:
052: if ((name == null) || (name.length() == 0))
053: throw new Error(
054: "Markup-Parameter-Name in der Definition fehlt");
055:
056: this .name = name.toUpperCase();
057: this .isOptional = isOptional;
058: this .useDefault = useDefault;
059: this .editable = editable;
060:
061: setDefaultValue(defaultValue);
062:
063: if (paramId < 0)
064: throw new Error(
065: "Markup-Parameter-Id in der Definition fehlt");
066:
067: this .param = TKMarkupParamDefinition.lookup(paramId);
068:
069: if (this .param == null)
070: throw new Error("Markup-Parameter '" + name + "/" + paramId
071: + "': Definition fehlt");
072: }
073:
074: public TKMarkupParamCall(TKMarkupParamCall definition) throws Error {
075:
076: if (definition == null)
077: throw new Error("Markup-Parameter Definition fehlt");
078:
079: this .name = definition.name.toUpperCase();
080: this .isOptional = definition.isOptional;
081: this .useDefault = definition.useDefault;
082: this .editable = definition.editable;
083: this .param = definition.param;
084:
085: setDefaultValue(definition.defaultValue());
086:
087: if (this .param == null)
088: throw new Error("Markup-Parameter '" + name
089: + "': Definition fehlt");
090: }
091:
092: private TKMarkupParamCall() {
093: }
094:
095: public static TKMarkupParamCall makeDummy(String name,
096: String paramName, boolean isOptional, boolean useDefault,
097: boolean editable, String defaultValue) {
098:
099: TKMarkupParamCall paramCall = new TKMarkupParamCall();
100:
101: if (name == null)
102: name = "";
103:
104: paramCall.name = name.toUpperCase();
105: paramCall.isOptional = isOptional;
106: paramCall.useDefault = useDefault;
107: paramCall.editable = editable;
108:
109: if ((paramName == null) || (paramName.length() == 0))
110: paramCall.param = null;
111: else {
112: paramCall.param = TKMarkupParamDefinition.lookup(paramName
113: .toUpperCase());
114:
115: if (paramCall.param == null)
116: paramCall.param = TKMarkupParamDefinition
117: .makeDummy(paramName);
118: }
119:
120: paramCall.setDefaultValue(defaultValue);
121:
122: return paramCall;
123: }
124:
125: public String defaultValue() {
126:
127: if (defaultValue == null)
128: return null;
129: if (defaultValue.length() == 0)
130: defaultValue = null;
131: return defaultValue;
132: }
133:
134: public void setDefaultValue(String value) {
135:
136: if ((value == null) || (value.length() == 0))
137: defaultValue = null;
138: else
139: defaultValue = ((param == null) || param.isCaseSensitive) ? value
140: : value.toUpperCase();
141: }
142:
143: public String toString() {
144:
145: StringBuffer buf = new StringBuffer();
146:
147: buf.append("name=").append(name).append(" isOptional=").append(
148: isOptional).append(" useDefault=").append(useDefault)
149: .append(" editable=").append(editable).append(
150: " defaultValue=\"").append(defaultValue)
151: .append('"').append(" param=[").append(param).append(
152: ']');
153:
154: return new String(buf);
155: }
156:
157: public int cmp(TKSortable other) {
158:
159: if (!(other instanceof TKMarkupParamCall))
160: return toString().compareTo(other.toString());
161:
162: TKMarkupParamCall otherParam = (TKMarkupParamCall) other;
163:
164: if ((name == null) && (otherParam.name != null))
165: return -1;
166: else if ((name != null) && (otherParam.name == null))
167: return 1;
168: else if ((name != null) && (otherParam.name != null)) {
169:
170: int rv = name.compareTo(otherParam.name);
171: if (rv != 0)
172: return rv;
173: }
174:
175: if ((param == null) && (otherParam.param != null))
176: return -1;
177: else if ((param != null) && (otherParam.param == null))
178: return 1;
179: else if ((param == null) && (otherParam.param == null))
180: return 0;
181: else
182: return param.cmp(otherParam.param);
183: };
184: //{{DECLARE_CONTROLS
185: //}}
186: }
|