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.MiscHelper;
039:
040: //other classes
041:
042: public class CommonFunctionLogCompAndTag extends
043: BaseCommonFunctionCompatibilityTag implements
044: SelfArgumentlessConstructor {
045:
046: //ConceptTag 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 = "Boolean values (true/false) to compared - the result is true"
053: + " only if all operands are true, false otherwise";
054:
055: public void initialize(InitializeConceptTagContext inIctc) {
056:
057: //
058: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
059: .newInstance(inIctc);
060:
061: //constrain "addend"
062: ConceptTagConstraint addendCtcon = ConceptTagConstraint
063: .newInstance(OPERAND_CTCON, rootCtconh);
064: addendCtcon.setMinimumLength(2);
065: addendCtcon.setLengthUnbounded(true);
066: addendCtcon.setTitle(OPERAND_TITLE);
067: addendCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
068: //
069: DynamicConceptTagConstraintContext addendDctcc = DynamicConceptTagConstraintContext
070: .newInstance(addendCtcon);
071: addendDctcc.getValidator().allowReturnOfOnlyBoolean();
072: addendDctcc.getValidator().filterDirectChildOfRootAndHtml();
073: //
074: //addendDctcc.addDefaultValue(BooleanWorkflowTemplateTag.class);
075: //addendDctcc.addDefaultValue(BooleanWorkflowTemplateTag.class);
076:
077: //
078: ConceptTagFlagsHelper
079: .pushNonIterativeCommonFunctionDepth(inIctc);
080: inIctc.initialize();
081: ConceptTagFlagsHelper
082: .popNonIterativeCommonFunctionDepth(inIctc);
083:
084: //
085: this .operandCtchar = addendCtcon.getCharacteristic();
086: }
087:
088: public void appraise(AppraiseConceptTagContext inActc) {
089:
090: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
091:
092: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
093:
094: sctiic.setInstanceTitle("And");
095: sctiic.setInstanceDescription("And");
096: /*
097: StringBuffer titleSb = new StringBuffer("");
098: StringBuffer descSb = new StringBuffer("");
099: for (int i = 0; i < this.operandCtchar.getValueLength(); i++) {
100: if (i > 0) {
101: titleSb.append(" AND ");
102: descSb.append(" AND ");
103: }
104: if (this.operandCtchar.isHolderWithConceptTag(i, inActc)) {
105: StudioConceptTagInstanceInfoContext nextStiic =
106: this.operandCtchar.getInstanceInformation(i);
107: titleSb.append(nextStiic.getInstanceTitle());
108: descSb.append(nextStiic.getInstanceDescription());
109: }
110: }
111: //titleSb.append(")");
112: //descSb.append(")");
113: sctiic.setInstanceTitle(titleSb.toString());
114: sctiic.setInstanceDescription(descSb.toString());
115: */
116: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
117:
118: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
119:
120: scttic.setTypeTitle("And");
121: scttic
122: .setTypeDescription("Logical 'and' two or more boolean values - "
123: + " return true only if all values are true");
124: } else if (inActc instanceof WebPageTagInstanceViewContext) {
125:
126: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
127:
128: WebPageTagInstanceViewContextInfo info = wptivc
129: .getInfoAsNonHtml();
130:
131: if (this .operandCtchar.getValueLength() >= 2) {
132: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
133: WebPageTagInstanceViewContextInfo nextInfo = info
134: .createNonHtmlInfo();
135: if (i > 0) {
136: nextInfo.setNonHtmlContent(" AND ");
137: }
138: WebPageTagInstanceViewContext.displayView(
139: this .operandCtchar, nextInfo, wptivc, i,
140: i + 1);
141: }
142: } else if (this .operandCtchar.getValueLength() == 1) {
143: WebPageTagInstanceViewContext.displayView(
144: this .operandCtchar, info, wptivc);
145: info.setNonHtmlContent("", " AND ???");
146: } else {
147: info.setNonHtmlContent("", " AND ---");
148: WebPageTagInstanceViewContextInfo subInfo = info
149: .createNonHtmlInfo(OPERAND_CTCON);
150: subInfo.setNonHtmlContent("???");
151: }
152: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
153:
154: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
155:
156: scfrct.canReturnBoolean();
157: scfrct.declareFormatAsPlain();
158: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
159:
160: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
161: }
162: }
163:
164: public void determineValueAndClass(
165: DetermineValueAndClassConceptTagContext inDvacctc) {
166:
167: try {
168: MiscHelper.println("Short AND implemented as default");
169: ValueAndClassForConceptTag vacfct = null;
170:
171: boolean result = true;
172:
173: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
174: ValueAndClassForConceptTag nextVac = this .operandCtchar
175: .getDetermineValueAndClass(i, inDvacctc);
176: Boolean b = (Boolean) nextVac.getValue();
177: result = result & b.booleanValue();
178: if (!result) {
179: break;
180: }
181: }
182: //
183: MiscHelper.println("ComFuncLogCompAndTag RESULT " + result);
184: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
185: result));
186:
187: inDvacctc.setDetermineValueAndClass(vacfct);
188: } catch (DetermineValueAndClassConceptTagException dvaccte) {
189: inDvacctc.setDetermineException(dvaccte);
190: }
191: }
192:
193: public void determineClass(DetermineClassConceptTagContext inDcctc) {
194: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
195: }
196:
197: public Object createUninitializedSelf() {
198: return new CommonFunctionLogCompAndTag();
199: }
200: }
|