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