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.ConceptTagConstraint;
024: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
025: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
026: import org.jfolder.common.tagging.ConceptTagMessageHolder;
027: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
029: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
030: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
031: import org.jfolder.common.tagging.InitializeConceptTagContext;
032: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
033: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
034: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
038:
039: //other classes
040:
041: public class CommonFunctionVarGetVarValueTag extends
042: BaseCommonFunctionCompatibilityTag implements
043: SelfArgumentlessConstructor {
044:
045: //
046: //characteristics
047: private ConceptTagCharacteristic nameCtchar = null;
048:
049: //name details
050: private final static String NAME_CTCON = "name";
051: private final static String NAME_TITLE = "Name";
052: private final static String NAME_SHORT_DESCRIPTION = "Name of local variable";
053:
054: public void initialize(InitializeConceptTagContext inIctc) {
055: //
056:
057: //
058: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
059: .newInstance(inIctc);
060:
061: //constrain "name"
062: ConceptTagConstraint nameCtcon = ConceptTagConstraint
063: .newInstance(NAME_CTCON, rootCtconh);
064: nameCtcon.setMinimumLength(1);
065: nameCtcon.setMaximumLength(1);
066: nameCtcon.setTitle(NAME_TITLE);
067: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
068: //
069: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
070: .newInstance(nameCtcon);
071: nameSctcc.setEntrySetExclusive(true);
072: ArrayList varNames = ConceptTagFlagsHelper
073: .getAllVariableNames(inIctc);
074: if (varNames.size() > 0) {
075: for (int i = 0; i < varNames.size(); i++) {
076: String nextVarName = ((String) varNames.get(i));
077: if (i == 0) {
078: nameSctcc.addDefaultValue(nextVarName);
079: }
080: nameSctcc.registerEntry(nextVarName, nextVarName);
081: }
082: } else {
083: nameSctcc.addDefaultValue("LocalVariable1");
084: }
085:
086: //
087: ConceptTagFlagsHelper
088: .pushNonIterativeCommonFunctionDepth(inIctc);
089: inIctc.initialize();
090: ConceptTagFlagsHelper
091: .popNonIterativeCommonFunctionDepth(inIctc);
092:
093: //initialize characteristics
094: this .nameCtchar = nameCtcon.getCharacteristic();
095:
096: //
097: ConceptTagMessageHolder nameCtmh = this .nameCtchar
098: .getParentMessageHolder();
099: if (!nameCtmh.isErrorPresent()) {
100: String name = this .nameCtchar.getValueAsString(0, inIctc);
101: if (!ConceptTagFlagsHelper.isGlobalOrLocalVariablePresent(
102: inIctc, name)) {
103: //
104: nameCtmh
105: .addErrorHeaderMessage("There is no global or local variable named '"
106: + name + "'");
107: }
108: }
109: }
110:
111: public void appraise(AppraiseConceptTagContext inActc) {
112:
113: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
114:
115: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
116:
117: sctiic.setInstanceTitle("Get Variable Value");
118: sctiic.setInstanceDescription("Get Variable Value");
119: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
120:
121: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
122:
123: scttic.setTypeTitle("Get Variable Value");
124: scttic.setTypeDescription("Get Variable Value");
125: } else if (inActc instanceof WebPageTagInstanceViewContext) {
126:
127: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
128:
129: WebPageTagInstanceViewContextInfo info = wptivc
130: .getInfoAsNonHtml();
131:
132: //
133: //
134: //
135: info.setNonHtmlContent("Var(", ")");
136: //
137: if (this .nameCtchar.getValueLength() > 0) {
138: WebPageTagInstanceViewContextInfo subInfo = info
139: .createNonHtmlInfo();
140: WebPageTagInstanceViewContext.displayView(
141: this .nameCtchar, subInfo, wptivc);
142: } else {
143: WebPageTagInstanceViewContextInfo subInfo = info
144: .createNonHtmlInfo(NAME_CTCON);
145: subInfo.setHtmlContent("No Name - Click Here To Add",
146: true);
147: }
148: //info.setEndContent(")");
149: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
150:
151: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
152:
153: scfrct.canReturnAnythingExceptNothing();
154: scfrct.declareFormatAsPlain();
155: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
156:
157: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
158: }
159: }
160:
161: public void determineValueAndClass(
162: DetermineValueAndClassConceptTagContext inDvacctc) {
163: //
164: ValueAndClassForConceptTag vac = null;
165:
166: ConceptTagFlagsHelper.showCurrentVariables(inDvacctc,
167: "CommFuncV1VarGetVarValTag about to get variable");
168:
169: String name = this .nameCtchar.getValueAsString(0, inDvacctc);
170: if (ConceptTagFlagsHelper.isGlobalVariablePresent(inDvacctc,
171: name)) {
172: //
173: vac = ConceptTagFlagsHelper.accessGlobalVariable(inDvacctc,
174: name);
175: } else if (ConceptTagFlagsHelper.isLocalVariablePresent(
176: inDvacctc, name)) {
177: //
178: vac = ConceptTagFlagsHelper.accessLocalVariable(inDvacctc,
179: name);
180: } else {
181: inDvacctc
182: .setDetermineException(new DetermineValueAndClassConceptTagException(
183: "Variable '" + name + "' is not declared"));
184: }
185: //
186: if (!inDvacctc.isDetermineExceptionPresent()) {
187: inDvacctc.setDetermineValueAndClass(vac);
188: }
189: }
190:
191: public void determineClass(DetermineClassConceptTagContext inDcctc) {
192: //
193: Class c = StandardDataTypes.getAnyClass();
194: if (this .nameCtchar.getValueLength() > 0
195: && this .nameCtchar.isStatic(0, inDcctc)) {
196: //
197: String name = this .nameCtchar.getValueAsString(0, inDcctc);
198: if (ConceptTagFlagsHelper.isGlobalVariablePresent(inDcctc,
199: name)) {
200: //
201: ValueAndClassForConceptTag vac = ConceptTagFlagsHelper
202: .accessGlobalVariable(inDcctc, name);
203: c = vac.getValueClass();
204: } else if (ConceptTagFlagsHelper.isLocalVariablePresent(
205: inDcctc, name)) {
206: //
207: ValueAndClassForConceptTag vac = ConceptTagFlagsHelper
208: .accessLocalVariable(inDcctc, name);
209: c = vac.getValueClass();
210: }
211: }
212: inDcctc.setDetermineClass(c);
213: }
214:
215: public Object createUninitializedSelf() {
216: return new CommonFunctionVarGetVarValueTag();
217: }
218: }
|