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.math.BigDecimal;
012:
013: //project specific classes
014: import org.jfolder.common.SelfArgumentlessConstructor;
015: import org.jfolder.common.StandardDataTypes;
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
018: import org.jfolder.common.function.WebPageTagInstanceViewContext;
019: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
020: import org.jfolder.common.tagging.AppraiseConceptTagContext;
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.DetermineClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
028: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
029: import org.jfolder.common.tagging.InitializeConceptTagContext;
030: import org.jfolder.common.tagging.ReturnableConceptTag;
031: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
032: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
033: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
034: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
036: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
037: import org.jfolder.common.utils.misc.CommonExpressions;
038: import org.jfolder.common.utils.misc.MiscHelper;
039:
040: //other classes
041:
042: public class CommonFunctionCompLsThOrEquTag extends
043: BaseCommonFunctionCompatibilityTag implements
044: SelfArgumentlessConstructor {
045:
046: //characteristics
047: private ConceptTagCharacteristic operandCtchar = null;
048:
049: //operand details
050: private final static String OPERAND_CTCON = "operand";
051: private final static String OPERAND_TITLE = "Operands";
052: private final static String OPERAND_SHORT_DESCRIPTION = "Number values to compare - "
053: + "the result is true only if the first operand is less"
054: + " than or equal to the second, false otherwise";
055:
056: public void initialize(InitializeConceptTagContext inIctc) {
057:
058: //
059: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
060: .newInstance(inIctc);
061:
062: //constrain "operand"
063: ConceptTagConstraint operandCtcon = ConceptTagConstraint
064: .newInstance(OPERAND_CTCON, rootCtconh);
065: operandCtcon.setMinimumLength(2);
066: operandCtcon.setMaximumLength(2);
067: operandCtcon.setTitle(OPERAND_TITLE);
068: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
069: //
070: StaticConceptTagConstraintContext operandSctcc = StaticConceptTagConstraintContext
071: .newInstance(operandCtcon);
072: operandSctcc.setRegularExpression(CommonExpressions.DECIMAL);
073: //
074: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
075: .newInstance(operandCtcon);
076: operandDctcc.getValidator().allowReturnOfOnlyDecimal();
077: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
078: //
079: operandSctcc.addDefaultValue("0");
080: operandSctcc.addDefaultValue("0");
081:
082: //
083: ConceptTagFlagsHelper
084: .pushNonIterativeCommonFunctionDepth(inIctc);
085: inIctc.initialize();
086: ConceptTagFlagsHelper
087: .popNonIterativeCommonFunctionDepth(inIctc);
088:
089: //initialize characteristics
090: this .operandCtchar = operandCtcon.getCharacteristic();
091:
092: }
093:
094: public void appraise(AppraiseConceptTagContext inActc) {
095:
096: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
097:
098: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
099:
100: sctiic.setInstanceTitle("Less Than Or Equal");
101: sctiic.setInstanceDescription("Less Than Or Equal");
102: /*
103: if (this.operandCtchar.getValueLength() == 2) {
104: //initialize first operand
105: String operandTitle1 = "";
106: String operandDesc1 = "";
107: if (this.operandCtchar.isStatic(0, inActc)) {
108: operandTitle1 =
109: this.operandCtchar.getValueAsString(0, inActc);
110: operandDesc1 =
111: this.operandCtchar.getValueAsString(0, inActc);
112: }
113: else if (this.operandCtchar.isHolderWithConceptTag(0, inActc)) {
114: StudioConceptTagInstanceInfoContext nextStiic =
115: this.operandCtchar.getInstanceInformation(0);
116:
117: operandTitle1 = nextStiic.getInstanceTitle();
118: operandDesc1 = nextStiic.getInstanceDescription();
119: }
120: //initialize second operand
121: String operandTitle2 = "";
122: String operandDesc2 = "";
123: if (this.operandCtchar.isStatic(1, inActc)) {
124: operandTitle2 =
125: this.operandCtchar.getValueAsString(1, inActc);
126: operandDesc2 =
127: this.operandCtchar.getValueAsString(1, inActc);
128: }
129: else if (this.operandCtchar.isHolderWithConceptTag(1, inActc)) {
130: StudioConceptTagInstanceInfoContext nextStiic =
131: this.operandCtchar.getInstanceInformation(1);
132:
133: operandTitle2 = nextStiic.getInstanceTitle();
134: operandDesc2 = nextStiic.getInstanceDescription();
135: }
136:
137: //set title and description
138: sctiic.setInstanceTitle(
139: "(" + operandTitle1 + " <= " + operandTitle2 + ")");
140: sctiic.setInstanceDescription(
141: "(" + operandDesc1 + " <= " + operandDesc2 + ")");
142: }
143: else {
144: sctiic.setInstanceTitle("(Error)");
145: sctiic.setInstanceDescription("(Error)");
146: }
147: */
148: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
149:
150: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
151:
152: scttic.setTypeTitle("Less Than Or Equal");
153: scttic
154: .setTypeDescription("Determines if one number is less than or equal to another");
155: } else if (inActc instanceof WebPageTagInstanceViewContext) {
156:
157: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
158:
159: WebPageTagInstanceViewContextInfo info = wptivc
160: .getInfoAsNonHtml();
161:
162: if (this .operandCtchar.getValueLength() >= 2) {
163: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
164: WebPageTagInstanceViewContextInfo nextInfo = info
165: .createNonHtmlInfo();
166: if (i > 0) {
167: nextInfo.setNonHtmlContent(" >= ");
168: }
169: WebPageTagInstanceViewContext.displayView(
170: this .operandCtchar, nextInfo, wptivc, i,
171: i + 1);
172: }
173: } else if (this .operandCtchar.getValueLength() == 1) {
174: WebPageTagInstanceViewContext.displayView(
175: this .operandCtchar, info, wptivc);
176: info.setNonHtmlContent("", " >= ???");
177: } else {
178: info.setNonHtmlContent("??? >= ???");
179: }
180: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
181:
182: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
183:
184: scfrct.canReturnBoolean();
185: scfrct.declareFormatAsPlain();
186: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
187:
188: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
189: }
190: }
191:
192: public void determineValueAndClass(
193: DetermineValueAndClassConceptTagContext inDvacctc) {
194:
195: try {
196: ValueAndClassForConceptTag vacfct = null;
197:
198: boolean result = true;
199: BigDecimal nextOperand = null;
200:
201: if (this .operandCtchar.isStatic(0, inDvacctc)) {
202: //MiscHelper.println("LessThEqSt arg1 = "
203: // + this.operandTc.getValueAsString(0));
204: nextOperand = new BigDecimal(this .operandCtchar
205: .getValueAsString(0, inDvacctc));
206: } else {
207: ValueAndClassForConceptTag operandVac = this .operandCtchar
208: .getDetermineValueAndClass(0, inDvacctc);
209: //MiscHelper.println("LessThEqSt arg1 = " + vac.getValue());
210: nextOperand = MiscHelper
211: .fromNumberToBigDecimal(operandVac.getValue());
212: }
213:
214: if (this .operandCtchar.isStatic(1, inDvacctc)) {
215: BigDecimal bd = new BigDecimal(this .operandCtchar
216: .getValueAsString(1, inDvacctc));
217: //MiscHelper.println("LessThEqSt arg2 = "
218: // + this.operandTc.getValueAsString(1));
219: result = result & (nextOperand.compareTo(bd) <= 0);
220: } else {
221: ValueAndClassForConceptTag operandVac = this .operandCtchar
222: .getDetermineValueAndClass(1, inDvacctc);
223: //MiscHelper.println("LessThEqSt arg2 = " + vac.getValue());
224: BigDecimal bd = MiscHelper
225: .fromNumberToBigDecimal(operandVac.getValue());
226: result = result & (nextOperand.compareTo(bd) <= 0);
227: }
228: //MiscHelper.println("LessThEqSt result = " + result);
229: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
230: result));
231:
232: inDvacctc.setDetermineValueAndClass(vacfct);
233: } catch (DetermineValueAndClassConceptTagException dvaccte) {
234: inDvacctc.setDetermineException(dvaccte);
235: }
236:
237: }
238:
239: public void determineClass(DetermineClassConceptTagContext inDcctc) {
240: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
241: }
242:
243: public Object createUninitializedSelf() {
244: return new CommonFunctionCompLsThOrEquTag();
245: }
246: }
|