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.ConceptTag;
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.ConceptTagHelper;
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.ReturnableConceptTag;
033: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
034: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
037: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
038: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
039: import org.jfolder.common.utils.misc.CommonExpressions;
040: import org.jfolder.common.utils.misc.MiscHelper;
041:
042: //other classes
043:
044: public class CommonFunctionCompGrThTag extends
045: BaseCommonFunctionCompatibilityTag implements
046: SelfArgumentlessConstructor {
047:
048: //characteristics
049: private ConceptTagCharacteristic operandCtchar = null;
050:
051: //operand details
052: private final static String OPERAND_CTCON = "operand";
053: private final static String OPERAND_TITLE = "Operands";
054: private final static String OPERAND_SHORT_DESCRIPTION = "Number values to compare - "
055: + "the result is true only if the first operand is greater"
056: + " than the second, false otherwise";
057:
058: public void initialize(InitializeConceptTagContext inIctc) {
059:
060: //
061: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
062: .newInstance(inIctc);
063:
064: //constrain "operand"
065: ConceptTagConstraint operandCtcon = ConceptTagConstraint
066: .newInstance(OPERAND_CTCON, rootCtconh);
067: operandCtcon.setMinimumLength(2);
068: operandCtcon.setMaximumLength(2);
069: operandCtcon.setTitle(OPERAND_TITLE);
070: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
071: //
072: StaticConceptTagConstraintContext operandSctcc = StaticConceptTagConstraintContext
073: .newInstance(operandCtcon);
074: operandSctcc.setRegularExpression(CommonExpressions.DECIMAL);
075: //
076: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
077: .newInstance(operandCtcon);
078: operandDctcc.getValidator().allowReturnOfOnlyDecimal();
079: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
080: //
081: operandSctcc.addDefaultValue("0");
082: operandSctcc.addDefaultValue("0");
083:
084: //
085: ConceptTagFlagsHelper
086: .pushNonIterativeCommonFunctionDepth(inIctc);
087: inIctc.initialize();
088: ConceptTagFlagsHelper
089: .popNonIterativeCommonFunctionDepth(inIctc);
090:
091: //initialize characteristics
092: this .operandCtchar = operandCtcon.getCharacteristic();
093:
094: }
095:
096: public void appraise(AppraiseConceptTagContext inActc) {
097:
098: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
099:
100: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
101:
102: sctiic.setInstanceTitle("Greater Than");
103: sctiic.setInstanceDescription("Greater Than");
104: /*
105: if (this.operandCtchar.getValueLength() == 2) {
106: //initialize first operand
107: String operandTitle1 = "";
108: String operandDesc1 = "";
109: if (this.operandCtchar.isStatic(0, inActc)) {
110: operandTitle1 =
111: this.operandCtchar.getValueAsString(0, inActc);
112: operandDesc1 =
113: this.operandCtchar.getValueAsString(0, inActc);
114: }
115: else if (this.operandCtchar.isHolderWithConceptTag(0, inActc)) {
116: StudioConceptTagInstanceInfoContext nextSctiic =
117: this.operandCtchar.getInstanceInformation(0);
118: operandTitle1 = nextSctiic.getInstanceTitle();
119: operandDesc1 = nextSctiic.getInstanceDescription();
120: }
121: //initialize second operand
122: String operandTitle2 = "";
123: String operandDesc2 = "";
124: if (this.operandCtchar.isStatic(1, inActc)) {
125: operandTitle2 =
126: this.operandCtchar.getValueAsString(1, inActc);
127: operandDesc2 =
128: this.operandCtchar.getValueAsString(1, inActc);
129: }
130: else if (this.operandCtchar.isHolderWithConceptTag(1, inActc)) {
131: StudioConceptTagInstanceInfoContext nextSctiic =
132: this.operandCtchar.getInstanceInformation(1);
133: operandTitle2 = nextSctiic.getInstanceTitle();
134: operandDesc2 = nextSctiic.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("Greater Than");
153: scttic
154: .setTypeDescription("Determines if one number is greater than 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: nextOperand = new BigDecimal(this .operandCtchar
203: .getValueAsString(0, inDvacctc));
204: } else {
205: ValueAndClassForConceptTag operandVac = this .operandCtchar
206: .getDetermineValueAndClass(0, inDvacctc);
207: nextOperand = MiscHelper
208: .fromNumberToBigDecimal(operandVac.getValue());
209: }
210:
211: if (this .operandCtchar.isStatic(1, inDvacctc)) {
212: BigDecimal bd = new BigDecimal(this .operandCtchar
213: .getValueAsString(1, inDvacctc));
214: result = result & (nextOperand.compareTo(bd) > 0);
215: } else {
216: ValueAndClassForConceptTag operandVac = this .operandCtchar
217: .getDetermineValueAndClass(1, inDvacctc);
218: BigDecimal bd = MiscHelper
219: .fromNumberToBigDecimal(operandVac.getValue());
220: result = result & (nextOperand.compareTo(bd) > 0);
221: }
222: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
223: result));
224:
225: inDvacctc.setDetermineValueAndClass(vacfct);
226: } catch (DetermineValueAndClassConceptTagException dvaccte) {
227: inDvacctc.setDetermineException(dvaccte);
228: }
229: }
230:
231: public void determineClass(DetermineClassConceptTagContext inDcctc) {
232: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
233: }
234:
235: public Object createUninitializedSelf() {
236: return new CommonFunctionCompGrThTag();
237: }
238: }
|