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:
012: //project specific classes
013: import org.jfolder.common.SelfArgumentlessConstructor;
014: import org.jfolder.common.StandardDataTypes;
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
017: import org.jfolder.common.function.WebPageTagInstanceViewContext;
018: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
019: import org.jfolder.common.tagging.AppraiseConceptTagContext;
020: import org.jfolder.common.tagging.ConceptTag;
021: import org.jfolder.common.tagging.ConceptTagCharacteristic;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.ConceptTagHelper;
026: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
029: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
030: import org.jfolder.common.tagging.InitializeConceptTagContext;
031: import org.jfolder.common.tagging.ReturnableConceptTag;
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: import org.jfolder.common.utils.misc.CommonExpressions;
039: import org.jfolder.common.utils.misc.MiscHelper;
040:
041: //other classes
042:
043: public class CommonFunctionListGetValueTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic listCtchar = null;
049: private ConceptTagCharacteristic indexCtchar = null;
050: private ConceptTagCharacteristic castToCtchar = null;
051:
052: //
053: //list details
054: private final static String LIST_CTCON = "list";
055: private final static String LIST_TITLE = "List";
056: private final static String LIST_SHORT_DESCRIPTION = "List";
057: //
058: //index details
059: private final static String INDEX_CTCON = "index";
060: private final static String INDEX_TITLE = "Index";
061: private final static String INDEX_SHORT_DESCRIPTION = "Index";
062: //
063: //cast-to details
064: private final static String CAST_TO_CTCON = "cast-to";
065:
066: public void initialize(InitializeConceptTagContext inIctc) {
067:
068: //
069: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
070: .newInstance(inIctc);
071:
072: //constrain "list"
073: ConceptTagConstraint listCtcon = ConceptTagConstraint
074: .newInstance(LIST_CTCON, rootCtconh);
075: //
076: listCtcon.setTitle(LIST_TITLE);
077: listCtcon.setShortDescription(LIST_SHORT_DESCRIPTION);
078: //
079: //
080: listCtcon.setMinimumLength(1);
081: listCtcon.setMaximumLength(1);
082: //
083: DynamicConceptTagConstraintContext listDctcc = DynamicConceptTagConstraintContext
084: .newInstance(listCtcon);
085: listDctcc.getValidator().allowReturnOfOnlyList();
086: listDctcc.getValidator().filterDirectChildOfRootAndHtml();
087: //
088:
089: //constrain "index"
090: ConceptTagConstraint indexCtcon = ConceptTagConstraint
091: .newInstance(INDEX_CTCON, rootCtconh);
092: //
093: indexCtcon.setTitle(INDEX_TITLE);
094: indexCtcon.setShortDescription(INDEX_SHORT_DESCRIPTION);
095: //
096: //
097: indexCtcon.setMinimumLength(1);
098: indexCtcon.setMaximumLength(1);
099: //
100: DynamicConceptTagConstraintContext indexDctcc = DynamicConceptTagConstraintContext
101: .newInstance(indexCtcon);
102: indexDctcc.getValidator().allowReturnOfOnlyDecimal();
103: indexDctcc.getValidator().filterDirectChildOfRootAndHtml();
104: //
105: StaticConceptTagConstraintContext indexSctcc = StaticConceptTagConstraintContext
106: .newInstance(indexCtcon);
107: indexSctcc.setRegularExpression(
108: CommonExpressions.NON_NEGATIVE_INTEGER,
109: "Value must be non-negative integer");
110: //
111: //
112:
113: //
114: //constrain "cast-to"
115: ConceptTagConstraint castToCtcon = ConceptTagConstraint
116: .newInstance(CAST_TO_CTCON, rootCtconh);
117: ConceptTagHelper.formatConcreteVariableType(castToCtcon, true);
118:
119: //
120: ConceptTagFlagsHelper
121: .pushNonIterativeCommonFunctionDepth(inIctc);
122: inIctc.initialize();
123: ConceptTagFlagsHelper
124: .popNonIterativeCommonFunctionDepth(inIctc);
125:
126: //initialize characteristics
127: this .listCtchar = listCtcon.getCharacteristic();
128: this .indexCtchar = indexCtcon.getCharacteristic();
129: this .castToCtchar = castToCtcon.getCharacteristic();
130: }
131:
132: public void appraise(AppraiseConceptTagContext inActc) {
133:
134: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
135:
136: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
137:
138: //
139: sctiic.setInstanceTitle("Get List Value");
140: sctiic.setInstanceDescription("Get List Value");
141: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
142:
143: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
144:
145: scttic.setTypeTitle("Get List Value");
146: scttic.setTypeDescription("Get List Value");
147: } else if (inActc instanceof WebPageTagInstanceViewContext) {
148:
149: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
150:
151: WebPageTagInstanceViewContextInfo info = wptivc
152: .getInfoAsNonHtml();
153:
154: //
155: //
156: WebPageTagInstanceViewContextInfo indexInfo = info
157: .createNonHtmlInfo();
158: indexInfo.setNonHtmlContent("Get Value At Index (");
159: WebPageTagInstanceViewContext.displayView(this .indexCtchar,
160: indexInfo, wptivc, "???");
161: //
162: //
163: WebPageTagInstanceViewContextInfo fromInfo = info
164: .createNonHtmlInfo();
165: fromInfo.setNonHtmlContent(") From (", ")");
166: WebPageTagInstanceViewContext.displayView(this .listCtchar,
167: fromInfo, wptivc, "???");
168: //
169: //
170: WebPageTagInstanceViewContextInfo castToInfo = info
171: .createNonHtmlInfo();
172: castToInfo.setNonHtmlContent(" As (", ")");
173: WebPageTagInstanceViewContext.displayView(
174: this .castToCtchar, castToInfo, wptivc, "???");
175: //fromInfo.setEndContent(")");
176: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
177:
178: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
179:
180: scfrct.canReturnAnythingExceptNothing();
181: scfrct.declareFormatAsPlain();
182: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
183:
184: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
185: }
186: }
187:
188: public void determineValueAndClass(
189: DetermineValueAndClassConceptTagContext inDvacctc) {
190:
191: try {
192: ValueAndClassForConceptTag vacfct = null;
193:
194: ValueAndClassForConceptTag listVacfct = this .listCtchar
195: .getDetermineValueAndClass(0, inDvacctc);
196:
197: Object index = null;
198: if (this .indexCtchar.isStatic(0, inDvacctc)) {
199: //
200: index = StandardDataTypes
201: .getDecimalInstance(this .indexCtchar
202: .getValueAsString(0, inDvacctc));
203: } else {
204: ValueAndClassForConceptTag indexVacfct = this .indexCtchar
205: .getDetermineValueAndClass(0, inDvacctc);
206: //
207: index = indexVacfct.getValue();
208: }
209: //BigDecimal bd = StandardDataTypes.getListLength(
210: // listVacfct.getValue());
211:
212: Object o = StandardDataTypes.getListValue(listVacfct
213: .getValue(), index);
214: vacfct = ((ValueAndClassForConceptTag) o);
215:
216: //vacfct = ValueAndClassForConceptTag.newDecimal(bd);
217:
218: inDvacctc.setDetermineValueAndClass(vacfct);
219: } catch (DetermineValueAndClassConceptTagException dvaccte) {
220: inDvacctc.setDetermineException(dvaccte);
221: }
222: }
223:
224: public void determineClass(DetermineClassConceptTagContext inDcctc) {
225:
226: Class result = StandardDataTypes.getAnyClass();
227: if (!this .castToCtchar.getParentMessageHolder()
228: .isErrorPresent()) {
229: result = StandardDataTypes.getActualClass(this .castToCtchar
230: .getValueAsString(0, inDcctc));
231: }
232:
233: inDcctc.setDetermineClass(result);
234: }
235:
236: public Object createUninitializedSelf() {
237: return new CommonFunctionListGetValueTag();
238: }
239:
240: }
|