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 CommonFunctionListAddValueTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic listCtchar = null;
049: private ConceptTagCharacteristic indexCtchar = null;
050: private ConceptTagCharacteristic valueCtchar = null;
051:
052: //list details
053: private final static String LIST_CTCON = "list";
054: private final static String LIST_TITLE = "List";
055: private final static String LIST_SHORT_DESCRIPTION = "List";
056: //
057: private final static String INDEX_CTCON = "index";
058: private final static String INDEX_TITLE = "Index";
059: private final static String INDEX_SHORT_DESCRIPTION = "Index";
060: //
061: private final static String VALUE_CTCON = "value";
062: private final static String VALUE_TITLE = "Value";
063: private final static String VALUE_SHORT_DESCRIPTION = "Value";
064:
065: public void initialize(InitializeConceptTagContext inIctc) {
066:
067: //
068: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
069: .newInstance(inIctc);
070:
071: //constrain "list"
072: ConceptTagConstraint listCtcon = ConceptTagConstraint
073: .newInstance(LIST_CTCON, rootCtconh);
074: //
075: listCtcon.setTitle(LIST_TITLE);
076: listCtcon.setShortDescription(LIST_SHORT_DESCRIPTION);
077: //
078: //
079: listCtcon.setMinimumLength(1);
080: listCtcon.setMaximumLength(1);
081: //
082: DynamicConceptTagConstraintContext listDctcc = DynamicConceptTagConstraintContext
083: .newInstance(listCtcon);
084: listDctcc.getValidator().allowReturnOfOnlyList();
085: listDctcc.getValidator().filterDirectChildOfRootAndHtml();
086: //
087:
088: //constrain "index"
089: ConceptTagConstraint indexCtcon = ConceptTagConstraint
090: .newInstance(INDEX_CTCON, rootCtconh);
091: //
092: indexCtcon.setTitle(INDEX_TITLE);
093: indexCtcon.setShortDescription(INDEX_SHORT_DESCRIPTION);
094: //
095: //
096: indexCtcon.setMinimumLength(0);
097: indexCtcon.setMaximumLength(1);
098: //
099: DynamicConceptTagConstraintContext indexDctcc = DynamicConceptTagConstraintContext
100: .newInstance(indexCtcon);
101: indexDctcc.getValidator().allowReturnOfOnlyList();
102: indexDctcc.getValidator().filterDirectChildOfRootAndHtml();
103: //
104: StaticConceptTagConstraintContext indexSctcc = StaticConceptTagConstraintContext
105: .newInstance(indexCtcon);
106: indexSctcc.setRegularExpression(
107: CommonExpressions.NON_NEGATIVE_INTEGER,
108: "Value must be non-negative integer");
109:
110: //constrain "value"
111: ConceptTagConstraint valueCtcon = ConceptTagConstraint
112: .newInstance(VALUE_CTCON, rootCtconh);
113: //
114: valueCtcon.setTitle(VALUE_TITLE);
115: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
116: //
117: //
118: valueCtcon.setMinimumLength(1);
119: valueCtcon.setMaximumLength(1);
120: //
121: DynamicConceptTagConstraintContext valueDctcc = DynamicConceptTagConstraintContext
122: .newInstance(valueCtcon);
123: valueDctcc.getValidator().allowReturnOfAnythingExceptNothing();
124: valueDctcc.getValidator().filterDirectChildOfRootAndHtml();
125: //
126:
127: //
128: ConceptTagFlagsHelper
129: .pushNonIterativeCommonFunctionDepth(inIctc);
130: inIctc.initialize();
131: ConceptTagFlagsHelper
132: .popNonIterativeCommonFunctionDepth(inIctc);
133:
134: //initialize characteristics
135: this .listCtchar = listCtcon.getCharacteristic();
136: this .indexCtchar = indexCtcon.getCharacteristic();
137: this .valueCtchar = valueCtcon.getCharacteristic();
138: }
139:
140: public void appraise(AppraiseConceptTagContext inActc) {
141:
142: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
143:
144: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
145:
146: //
147: sctiic.setInstanceTitle("Add List Value");
148: sctiic.setInstanceDescription("Add List Value");
149: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
150:
151: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
152:
153: scttic.setTypeTitle("Add List Value");
154: scttic.setTypeDescription("Add List Value");
155: } else if (inActc instanceof WebPageTagInstanceViewContext) {
156:
157: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
158:
159: WebPageTagInstanceViewContextInfo info = wptivc
160: .getInfoAsNonHtml();
161:
162: //
163: //
164: WebPageTagInstanceViewContextInfo addInfo = info
165: .createNonHtmlInfo();
166: addInfo.setNonHtmlContent("Add Value (");
167: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
168: addInfo, wptivc);
169: //
170: //
171: WebPageTagInstanceViewContextInfo indexInfo = info
172: .createNonHtmlInfo();
173: //if (this.indexCtchar.getValueLength() > 0) {
174: indexInfo.setNonHtmlContent(") To Index (", ") Of (");
175: WebPageTagInstanceViewContext.displayView(this .indexCtchar,
176: indexInfo, wptivc, "End");
177: //indexInfo.setEndContent(") Of (");
178: //}
179: //else {
180: // indexInfo.setNonHtmlContent(") To The End Of (");
181: //}
182: //
183: //
184: //
185: WebPageTagInstanceViewContextInfo listInfo = info
186: .createNonHtmlInfo();
187: WebPageTagInstanceViewContext.displayView(this .listCtchar,
188: listInfo, wptivc);
189: listInfo.setNonHtmlContent("", ")");
190: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
191:
192: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
193:
194: scfrct.canReturnNothing();
195: scfrct.declareFormatAsPlain();
196: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
197:
198: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
199: }
200: }
201:
202: public void determineValueAndClass(
203: DetermineValueAndClassConceptTagContext inDvacctc) {
204:
205: try {
206: ValueAndClassForConceptTag listVacfct = this .listCtchar
207: .getDetermineValueAndClass(0, inDvacctc);
208:
209: Object index = StandardDataTypes.getListLength(listVacfct
210: .getValue());
211: //
212: if (this .indexCtchar.getValueLength() > 0) {
213: if (this .indexCtchar.isStatic(0, inDvacctc)) {
214: //
215: index = StandardDataTypes
216: .getDecimalInstance(this .indexCtchar
217: .getValueAsString(0, inDvacctc));
218: } else {
219: ValueAndClassForConceptTag indexVacfct = this .indexCtchar
220: .getDetermineValueAndClass(0, inDvacctc);
221: //
222: index = indexVacfct.getValue();
223: }
224: }
225:
226: ValueAndClassForConceptTag valueVacfct = this .valueCtchar
227: .getDetermineValueAndClass(0, inDvacctc);
228:
229: StandardDataTypes.addListValue(listVacfct.getValue(),
230: index, valueVacfct);
231:
232: inDvacctc
233: .setDetermineValueAndClass(ValueAndClassForConceptTag
234: .newNothing());
235: } catch (DetermineValueAndClassConceptTagException dvaccte) {
236: inDvacctc.setDetermineException(dvaccte);
237: }
238: }
239:
240: public void determineClass(DetermineClassConceptTagContext inDcctc) {
241: inDcctc.setDetermineClass(StandardDataTypes.getNothingClass());
242: }
243:
244: public Object createUninitializedSelf() {
245: return new CommonFunctionListAddValueTag();
246: }
247:
248: }
|