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 CommonFunctionCompEquTag 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 = "Values to compare - the result is true only"
055: + " if all operands are equal, false otherwise";
056:
057: public void initialize(InitializeConceptTagContext inIctc) {
058:
059: //
060: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
061: .newInstance(inIctc);
062:
063: MiscHelper.println("String compare not implemented");
064:
065: //constrain "addend"
066: ConceptTagConstraint operandCtcon = ConceptTagConstraint
067: .newInstance(OPERAND_CTCON, rootCtconh);
068: operandCtcon.setMinimumLength(2);
069: operandCtcon.setLengthUnbounded(true);
070: operandCtcon.setTitle(OPERAND_TITLE);
071: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
072: //
073: StaticConceptTagConstraintContext operandSctcc = StaticConceptTagConstraintContext
074: .newInstance(operandCtcon);
075: operandSctcc.setRegularExpression(CommonExpressions.DECIMAL);
076: //
077: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
078: .newInstance(operandCtcon);
079: operandDctcc.getValidator().allowReturnOfOnlyDecimal();
080: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
081: //
082: operandSctcc.addDefaultValue("0");
083: operandSctcc.addDefaultValue("0");
084:
085: //
086: ConceptTagFlagsHelper
087: .pushNonIterativeCommonFunctionDepth(inIctc);
088: inIctc.initialize();
089: ConceptTagFlagsHelper
090: .popNonIterativeCommonFunctionDepth(inIctc);
091:
092: //initialize characteristics
093: this .operandCtchar = operandCtcon.getCharacteristic();
094: }
095:
096: public void appraise(AppraiseConceptTagContext inActc) {
097:
098: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
099:
100: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
101:
102: sctiic.setInstanceTitle("Equals");
103: sctiic.setInstanceDescription("Equals");
104: /*
105: StringBuffer titleSb = new StringBuffer("");
106: StringBuffer descSb = new StringBuffer("");
107: for (int i = 0; i < this.operandCtchar.getValueLength(); i++) {
108: if (i > 0) {
109: titleSb.append(" == ");
110: descSb.append(" == ");
111: }
112: if (this.operandCtchar.isHolderWithConceptTag(i, inActc)) {
113: StudioConceptTagInstanceInfoContext nextSctiic =
114: this.operandCtchar.getInstanceInformation(i);
115: titleSb.append(nextSctiic.getInstanceTitle());
116: descSb.append(nextSctiic.getInstanceDescription());
117: }
118: }
119: //titleSb.append(")");
120: //descSb.append(")");
121: sctiic.setInstanceTitle(titleSb.toString());
122: sctiic.setInstanceDescription(descSb.toString());
123: */
124: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
125:
126: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
127:
128: scttic.setTypeTitle("Equal");
129: scttic
130: .setTypeDescription("Checks if two numbers are equal");
131: } else if (inActc instanceof WebPageTagInstanceViewContext) {
132:
133: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
134:
135: WebPageTagInstanceViewContextInfo info = wptivc
136: .getInfoAsNonHtml();
137:
138: if (this .operandCtchar.getValueLength() >= 2) {
139: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
140: WebPageTagInstanceViewContextInfo nextInfo = info
141: .createNonHtmlInfo();
142: if (i > 0) {
143: nextInfo.setNonHtmlContent(" == ");
144: }
145: WebPageTagInstanceViewContext.displayView(
146: this .operandCtchar, nextInfo, wptivc, i,
147: i + 1);
148: }
149: } else if (this .operandCtchar.getValueLength() == 1) {
150: WebPageTagInstanceViewContext.displayView(
151: this .operandCtchar, info, wptivc);
152: info.setNonHtmlContent("", " == ???");
153: } else {
154: info.setNonHtmlContent("??? == ???");
155: }
156: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
157:
158: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
159:
160: scfrct.canReturnBoolean();
161: scfrct.declareFormatAsPlain();
162: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
163:
164: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
165: }
166: }
167:
168: public void determineValueAndClass(
169: DetermineValueAndClassConceptTagContext inDvacctc) {
170:
171: try {
172: ValueAndClassForConceptTag vacfct = null;
173:
174: //ComponentsForReturnableScriptTag wcfrt =
175: // ScriptTagHelper.getComponentsForReturnableScriptTag(inRvacc);
176:
177: boolean result = true;
178: BigDecimal nextOperand = null;
179:
180: if (this .operandCtchar.isStatic(0, inDvacctc)) {
181: nextOperand = new BigDecimal(this .operandCtchar
182: .getValueAsString(0, inDvacctc));
183: } else {
184: ValueAndClassForConceptTag operandVac = this .operandCtchar
185: .getDetermineValueAndClass(0, inDvacctc);
186: nextOperand = MiscHelper
187: .fromNumberToBigDecimal(operandVac.getValue());
188: }
189:
190: for (int i = 1; i < this .operandCtchar.getValueLength(); i++) {
191: if (this .operandCtchar.isStatic(i, inDvacctc)) {
192: BigDecimal bd = new BigDecimal(this .operandCtchar
193: .getValueAsString(i, inDvacctc));
194: result = result & (nextOperand.compareTo(bd) == 0);
195: } else {
196: ValueAndClassForConceptTag operandVac = this .operandCtchar
197: .getDetermineValueAndClass(i, inDvacctc);
198: BigDecimal bd = MiscHelper
199: .fromNumberToBigDecimal(operandVac
200: .getValue());
201: result = result & (nextOperand.compareTo(bd) == 0);
202: }
203: }
204: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
205: result));
206:
207: inDvacctc.setDetermineValueAndClass(vacfct);
208: } catch (DetermineValueAndClassConceptTagException dvaccte) {
209: inDvacctc.setDetermineException(dvaccte);
210: }
211: }
212:
213: public void determineClass(DetermineClassConceptTagContext inDcctc) {
214: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
215: }
216:
217: public Object createUninitializedSelf() {
218: return new CommonFunctionCompEquTag();
219: }
220: }
|