001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.function.v1;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.SelfArgumentlessConstructor;
016: import org.jfolder.common.StandardDataTypes;
017: import org.jfolder.common.UnexpectedSystemException;
018: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
019: import org.jfolder.common.function.WebPageTagInstanceViewContext;
020: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
021: import org.jfolder.common.tagging.AppraiseConceptTagContext;
022: import org.jfolder.common.tagging.ConceptTagCharacteristic;
023: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
024: import org.jfolder.common.tagging.ConceptTagConstraint;
025: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
026: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
027: import org.jfolder.common.tagging.ConceptTagHelper;
028: import org.jfolder.common.tagging.ConceptTagMessageHolder;
029: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
030: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
031: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
032: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
033: import org.jfolder.common.tagging.InitializeConceptTagContext;
034: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
035: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
036: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
037: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
038: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
039: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
040: import org.jfolder.common.utils.misc.MiscHelper;
041:
042: //other classes
043:
044: public class CommonFunctionVarDeclareLocalVarTag extends
045: BaseCommonFunctionCompatibilityTag implements
046: SelfArgumentlessConstructor {
047:
048: //
049: //characteristics
050: private ConceptTagCharacteristic nameCtchar = null;
051: private ConceptTagCharacteristic typeCtchar = null;
052: private ConceptTagCharacteristic valueCtchar = null;
053:
054: //name details
055: private final static String NAME_CTCON = "name";
056: private final static String NAME_TITLE = "Name";
057: private final static String NAME_SHORT_DESCRIPTION = "Name of local variable";
058:
059: //type details
060: private final static String TYPE_CTCON = "type";
061: private final static String TYPE_TITLE = "Type";
062: private final static String TYPE_SHORT_DESCRIPTION = "Type of local variable";
063:
064: //value details
065: private final static String VALUE_CTCON = "value";
066: private final static String VALUE_TITLE = "Value";
067: private final static String VALUE_SHORT_DESCRIPTION = "Value of local variable";
068:
069: public void initialize(InitializeConceptTagContext inIctc) {
070: //
071:
072: //
073: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
074: .newInstance(inIctc);
075: ConceptTagCharacteristicHolder rootCtcharh = rootCtconh
076: .getCharacteristicHolder();
077:
078: //constrain "name"
079: ConceptTagConstraint nameCtcon = ConceptTagConstraint
080: .newInstance(NAME_CTCON, rootCtconh);
081: nameCtcon.setTitle(NAME_TITLE);
082: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
083: //
084: //nameCtcon.setMinimumLength(1);
085: //nameCtcon.setMaximumLength(1);
086: ////
087: //StaticConceptTagConstraintContext nameSctcc =
088: // StaticConceptTagConstraintContext.newInstance(nameCtcon);
089: //nameSctcc.addDefaultValue("LocalVariable1");
090:
091: //constrain "type"
092: ConceptTagConstraint typeCtcon = ConceptTagConstraint
093: .newInstance(TYPE_CTCON, rootCtconh);
094: //
095: typeCtcon.setTitle(TYPE_TITLE);
096: typeCtcon.setShortDescription(TYPE_SHORT_DESCRIPTION);
097: //
098: //
099: //
100: ArrayList varList = rootCtcharh.getHandleAsArrayList();
101: varList.remove(varList.size() - 1);
102: String varHandle = MiscHelper.reassembleHandle(varList,
103: rootCtconh.getPreferences().getHandleConjunction());
104: PostConstraintValidatorForVarNameAndType
105: .initializeNameAndTypeCtcon(nameCtcon, typeCtcon,
106: NAME_CTCON, TYPE_CTCON, VALUE_CTCON, true,
107: varHandle, rootCtcharh
108: .getParentCharacteristicIndex() + 1);
109: //
110: //
111: //
112: //typeCtcon.setMinimumLength(1);
113: //typeCtcon.setMaximumLength(1);
114: ////
115: //StaticConceptTagConstraintContext typeSctcc =
116: // StaticConceptTagConstraintContext.newInstance(typeCtcon);
117: //typeSctcc.setEntrySetExclusive(true);
118: ////
119: ////HashMap ctdn = StandardDataTypes.getClassToDisplayName();
120: //ArrayList variableTypes = StandardDataTypes.getVariableTypes();
121: //for (int i = 0; i < variableTypes.size(); i++) {
122: // String nextType = ((String)variableTypes.get(i));
123: // if (i == 0) {
124: // typeSctcc.addDefaultValue(nextType);
125: // }
126: // typeSctcc.registerEntry(nextType, nextType);
127: //}
128: ////addendSctcc.setRegularExpression(CommonExpressions.DECIMAL);
129: //typeCtcon.registerPostValidator(
130: // PostConstraintValidatorForVarNameAndType.newInstance(
131: // NAME_CTCON, TYPE_CTCON, VALUE_CTCON, true));
132: //
133: //DynamicConceptTagConstraintContext addendDctcc =
134: // DynamicConceptTagConstraintContext.newInstance(addendCtcon);
135: //addendDctcc.getValidator().allowReturnOfOnlyDecimal();
136: //
137: //addendSctcc.addDefaultValue("0");
138: //addendSctcc.addDefaultValue("0");
139:
140: //constrain "value"
141: ConceptTagConstraint valueCtcon = ConceptTagConstraint
142: .newInstance(VALUE_CTCON, rootCtconh);
143: valueCtcon.setMinimumLength(1);
144: valueCtcon.setMaximumLength(1);
145: valueCtcon.setTitle(VALUE_TITLE);
146: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
147: //
148: //StaticConceptTagConstraintContext valueSctcc =
149: // StaticConceptTagConstraintContext.newInstance(valueCtcon);
150: //DynamicConceptTagConstraintContext valueDctcc =
151: // DynamicConceptTagConstraintContext.newInstance(valueCtcon);
152: //valueDctcc.getValidator().filterDirectChildOfRootAndHtml();
153: //valueSctcc.addDefaultValue("(Your Text Here)");
154:
155: //
156: ConceptTagFlagsHelper
157: .pushNonIterativeCommonFunctionDepth(inIctc);
158: inIctc.initialize();
159: ConceptTagFlagsHelper.showCurrentVariables(inIctc,
160: "ComFunVarDecLocVarTag");
161: ConceptTagFlagsHelper
162: .popNonIterativeCommonFunctionDepth(inIctc);
163:
164: //initialize characteristics
165: this .nameCtchar = nameCtcon.getCharacteristic();
166: this .typeCtchar = typeCtcon.getCharacteristic();
167: this .valueCtchar = valueCtcon.getCharacteristic();
168:
169: //
170: //ConceptTagMessageHolder nameCtmh =
171: // this.nameCtchar.getParentMessageHolder();
172: //ConceptTagMessageHolder typeCtmh =
173: // this.typeCtchar.getParentMessageHolder();
174: //ConceptTagMessageHolder valueCtmh =
175: // this.valueCtchar.getParentMessageHolder();
176: //
177: //if (!nameCtmh.isErrorPresent() && !typeCtmh.isErrorPresent()
178: // && !valueCtmh.isErrorPresent()) {
179: // //
180: // String name = this.nameCtchar.getValueAsString(0);
181: // String type = this.typeCtchar.getValueAsString(0);
182: // String value = this.valueCtchar.getValueAsString(0);
183: //
184: // if (!ConceptTagFlagsHelper.isVariableNameValid(name)) {
185: // nameCtmh.addErrorHeaderMessage(
186: // "Cannot declare local variable '" + name
187: // + "' because variables must start with a letter,"
188: // + " and each other character must be a letter, digit,"
189: // + " or underscore");
190: // }
191: // else if (ConceptTagFlagsHelper.isGlobalVariablePresent(
192: // inIctc, name)) {
193: // //
194: // nameCtmh.addErrorHeaderMessage(
195: // "Cannot declare local variable '" + name
196: // + "' because it is already declared"
197: // + " as a global variable");
198: // }
199: // else if (ConceptTagFlagsHelper.isLocalVariablePresent(
200: // inIctc, name)) {
201: // //
202: // nameCtmh.addErrorHeaderMessage(
203: // "Cannot declare local variable '" + name
204: // + "' because it is already declared"
205: // + " as a local variable");
206: // }
207: // else {
208: // HashMap dntc = StandardDataTypes.getDisplayNameToClass();
209: // if (dntc.containsKey(type)) {
210: // Class typeClass = ((Class)dntc.get(type));
211: // if (typeClass.equals(
212: // StandardDataTypes.getStringClass())) {
213: // ConceptTagFlagsHelper.createLocalAndParentOfLocalVariable(
214: // inIctc, typeClass, name, null);
215: // }
216: // else {
217: // typeCtmh.addErrorHeaderMessage(
218: // "Unknown data type '" + type + "'");
219: // }
220: // }
221: // else {
222: // typeCtmh.addErrorHeaderMessage(
223: // "Unknown data type '" + type + "'");
224: // }
225: // }
226: //
227: //}
228: }
229:
230: public void appraise(AppraiseConceptTagContext inActc) {
231:
232: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
233:
234: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
235:
236: sctiic.setInstanceTitle("Declare Local Variable");
237: sctiic.setInstanceDescription("Declare Local Variable");
238: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
239:
240: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
241:
242: scttic.setTypeTitle("Declare Local Variable");
243: scttic.setTypeDescription("Declare Local Variable");
244: } else if (inActc instanceof WebPageTagInstanceViewContext) {
245:
246: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
247:
248: WebPageTagInstanceViewContextInfo info = wptivc
249: .getInfoAsNonHtml();
250:
251: //
252: //
253: //
254: WebPageTagInstanceViewContextInfo typeInfo = info
255: .createNonHtmlInfo();
256: typeInfo.setNonHtmlContent("", " ");
257: //
258: WebPageTagInstanceViewContext.displayView(this .typeCtchar,
259: typeInfo, wptivc, "(Unknown Type)");
260: //
261: //
262: WebPageTagInstanceViewContextInfo nameInfo = info
263: .createNonHtmlInfo();
264: nameInfo.setNonHtmlContent("", " = ");
265: //
266: WebPageTagInstanceViewContext.displayView(this .nameCtchar,
267: nameInfo, wptivc, "(Unknown Name)");
268: //
269: //
270: WebPageTagInstanceViewContextInfo valueInfo = info
271: .createNonHtmlInfo();
272: //
273: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
274: valueInfo, wptivc, "(Unknown Value)");
275: //
276: //
277: //
278: //
279: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
280:
281: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
282:
283: scfrct.canReturnNothing();
284: scfrct.declareFormatAsPlain();
285: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
286:
287: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
288: }
289: }
290:
291: public void determineValueAndClass(
292: DetermineValueAndClassConceptTagContext inDvacctc) {
293: //
294: //
295: try {
296: //
297: Class type = ConceptTagHelper
298: .getClassFromDisplayType(this .typeCtchar);
299: Object value = ConceptTagHelper.getStandardValueFromChar(
300: this .valueCtchar, this .typeCtchar.getValueAsString(
301: 0, inDvacctc), 0, inDvacctc);
302: //
303: ConceptTagFlagsHelper.createLocalAndParentOfLocalVariable(
304: inDvacctc, type, this .nameCtchar.getValueAsString(
305: 0, inDvacctc), value);
306: //if (type.equals(StandardDataTypes.getStringClass())) {
307: // String s = null;
308: // if (this.valueCtchar.isStatic(0)) {
309: // s = this.valueCtchar.getValueAsString(0);
310: // }
311: // else if (this.valueCtchar.isHolderWithConceptTag(0)) {
312: // ValueAndClassForConceptTag valueVac =
313: // this.valueCtchar.getDetermineValueAndClass(
314: // 0, inDvacctc);
315: // s = ((String)valueVac.getValue());
316: // }
317: // else {
318: // throw UnexpectedSystemException.unknownState();
319: // }
320: // ConceptTagFlagsHelper.showCurrentVariables(
321: // inDvacctc, "CommFuncVarDecLocVarTag before declare");
322: // ConceptTagFlagsHelper.createLocalAndParentOfLocalVariable(
323: // inDvacctc,
324: // ConceptTagHelper.getClassFromDisplayType(this.typeCtchar),
325: // this.nameCtchar.getValueAsString(0), s);
326: // ConceptTagFlagsHelper.showCurrentVariables(
327: // inDvacctc, "CommFuncVarDecLocVarTag after declare");
328: //}
329: //else {
330: // throw new UnexpectedSystemException(
331: // "Unknown data type '" + type.getName() + "'");
332: //}
333: //
334: inDvacctc
335: .setDetermineValueAndClass(ValueAndClassForConceptTag
336: .newNothing());
337: } catch (DetermineValueAndClassConceptTagException dvaccte) {
338: inDvacctc.setDetermineException(dvaccte);
339: }
340: }
341:
342: public void determineClass(DetermineClassConceptTagContext inDcctc) {
343: //
344: //ConceptTagHelper.declareVariableInDetermineClassIfValid(
345: // this.nameCtchar, this.typeCtchar, inDcctc);
346: //
347: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
348: }
349:
350: public Object createUninitializedSelf() {
351: return new CommonFunctionVarDeclareLocalVarTag();
352: }
353:
354: }
|