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 CommonFunctionCompNtEquTag 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("Not Equal");
103: sctiic.setInstanceDescription("Not Equal");
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 nextStiic =
117: this.operandCtchar.getInstanceInformation(0);
118:
119: operandTitle1 = nextStiic.getInstanceTitle();
120: operandDesc1 = nextStiic.getInstanceDescription();
121: }
122: //initialize second operand
123: String operandTitle2 = "";
124: String operandDesc2 = "";
125: if (this.operandCtchar.isStatic(1, inActc)) {
126: operandTitle2 =
127: this.operandCtchar.getValueAsString(1, inActc);
128: operandDesc2 =
129: this.operandCtchar.getValueAsString(1, inActc);
130: }
131: else if (this.operandCtchar.isHolderWithConceptTag(1, inActc)) {
132: StudioConceptTagInstanceInfoContext nextStiic =
133: this.operandCtchar.getInstanceInformation(1);
134:
135: operandTitle2 = nextStiic.getInstanceTitle();
136: operandDesc2 = nextStiic.getInstanceDescription();
137: }
138:
139: //set title and description
140: sctiic.setInstanceTitle(
141: "(" + operandTitle1 + " != " + operandTitle2 + ")");
142: sctiic.setInstanceDescription(
143: "(" + operandDesc1 + " != " + operandDesc2 + ")");
144: }
145: else {
146: sctiic.setInstanceTitle("(Error)");
147: sctiic.setInstanceDescription("(Error)");
148: }
149: */
150: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
151:
152: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
153:
154: scttic.setTypeTitle("Not Equal");
155: scttic
156: .setTypeDescription("Determines if one number is not equal to another");
157: } else if (inActc instanceof WebPageTagInstanceViewContext) {
158:
159: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
160:
161: WebPageTagInstanceViewContextInfo info = wptivc
162: .getInfoAsNonHtml();
163:
164: if (this .operandCtchar.getValueLength() >= 2) {
165: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
166: WebPageTagInstanceViewContextInfo nextInfo = info
167: .createNonHtmlInfo();
168: if (i > 0) {
169: nextInfo.setNonHtmlContent(" != ");
170: }
171: WebPageTagInstanceViewContext.displayView(
172: this .operandCtchar, nextInfo, wptivc, i,
173: i + 1);
174: }
175: } else if (this .operandCtchar.getValueLength() == 1) {
176: WebPageTagInstanceViewContext.displayView(
177: this .operandCtchar, info, wptivc);
178: info.setNonHtmlContent("", " != ???");
179: } else {
180: info.setNonHtmlContent("??? != ???");
181: }
182: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
183:
184: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
185:
186: scfrct.canReturnBoolean();
187: scfrct.declareFormatAsPlain();
188: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
189:
190: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
191: }
192: }
193:
194: public void determineValueAndClass(
195: DetermineValueAndClassConceptTagContext inDvacctc) {
196:
197: try {
198: ValueAndClassForConceptTag vacfct = null;
199:
200: boolean result = true;
201: BigDecimal nextOperand = null;
202:
203: if (this .operandCtchar.isStatic(0, inDvacctc)) {
204: nextOperand = new BigDecimal(this .operandCtchar
205: .getValueAsString(0, inDvacctc));
206: } else {
207: ValueAndClassForConceptTag operandVac = this .operandCtchar
208: .getDetermineValueAndClass(0, inDvacctc);
209: nextOperand = MiscHelper
210: .fromNumberToBigDecimal(operandVac.getValue());
211: }
212:
213: if (this .operandCtchar.isStatic(1, inDvacctc)) {
214: BigDecimal bd = new BigDecimal(this .operandCtchar
215: .getValueAsString(1, inDvacctc));
216: result = result & (nextOperand.compareTo(bd) != 0);
217: } else {
218: ValueAndClassForConceptTag operandVac = this .operandCtchar
219: .getDetermineValueAndClass(1, inDvacctc);
220: BigDecimal bd = MiscHelper
221: .fromNumberToBigDecimal(operandVac.getValue());
222: result = result & (nextOperand.compareTo(bd) != 0);
223: }
224: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
225: result));
226:
227: inDvacctc.setDetermineValueAndClass(vacfct);
228: } catch (DetermineValueAndClassConceptTagException dvaccte) {
229: inDvacctc.setDetermineException(dvaccte);
230: }
231: }
232:
233: public void determineClass(DetermineClassConceptTagContext inDcctc) {
234: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
235: }
236:
237: public Object createUninitializedSelf() {
238: return new CommonFunctionCompNtEquTag();
239: }
240: }
|