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.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagConstraint;
022: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
023: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
024: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
025: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
027: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
028: import org.jfolder.common.tagging.InitializeConceptTagContext;
029: import org.jfolder.common.tagging.ReturnableConceptTag;
030: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
031: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
033: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
034: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
035:
036: //other classes
037:
038: public class CommonFunctionLogCompXorTag extends
039: BaseCommonFunctionCompatibilityTag implements
040: SelfArgumentlessConstructor {
041:
042: //characteristics
043: private ConceptTagCharacteristic operandCtchar = null;
044:
045: //operand details
046: private final static String OPERAND_CTCON = "operand";
047: private final static String OPERAND_TITLE = "Operands";
048: private final static String OPERAND_SHORT_DESCRIPTION = "True/false values to compare - "
049: + "the result is true only if exactly one operand is true,"
050: + " false otherwise";
051:
052: public void initialize(InitializeConceptTagContext inIctc) {
053:
054: //
055: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
056: .newInstance(inIctc);
057:
058: //constrain "operand"
059: ConceptTagConstraint operandCtcon = ConceptTagConstraint
060: .newInstance(OPERAND_CTCON, rootCtconh);
061: operandCtcon.setMinimumLength(2);
062: operandCtcon.setMaximumLength(2);
063: operandCtcon.setTitle(OPERAND_TITLE);
064: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
065: //
066: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
067: .newInstance(operandCtcon);
068: operandDctcc.getValidator().allowReturnOfOnlyBoolean();
069: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
070: //
071: operandCtcon.setMinimumLength(2);
072: operandCtcon.setMaximumLength(2);
073: //
074: //operandDctcc.addDefaultValue(
075: // GetApplicationAttributeWorkflowTemplateTag.class);
076: //operandDctcc.addDefaultValue(
077: // GetApplicationAttributeWorkflowTemplateTag.class);
078:
079: //
080: ConceptTagFlagsHelper
081: .pushNonIterativeCommonFunctionDepth(inIctc);
082: inIctc.initialize();
083: ConceptTagFlagsHelper
084: .popNonIterativeCommonFunctionDepth(inIctc);
085:
086: //initialize characteristics
087: this .operandCtchar = operandCtcon.getCharacteristic();
088: }
089:
090: public void appraise(AppraiseConceptTagContext inActc) {
091:
092: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
093:
094: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
095:
096: sctiic.setInstanceTitle("Xor");
097: sctiic.setInstanceDescription("Xor");
098: /*
099: if (this.operandCtchar.getValueLength() == 2) {
100: //initialize first operand
101: String operandTitle1 = "";
102: String operandDesc1 = "";
103: if (this.operandCtchar.isStatic(0, inActc)) {
104: operandTitle1 =
105: this.operandCtchar.getValueAsString(0, inActc);
106: operandDesc1 =
107: this.operandCtchar.getValueAsString(0, inActc);
108: }
109: else if (this.operandCtchar.isHolderWithConceptTag(0, inActc)) {
110: StudioConceptTagInstanceInfoContext nextStiic =
111: this.operandCtchar.getInstanceInformation(0);
112: operandTitle1 = nextStiic.getInstanceTitle();
113: operandDesc1 = nextStiic.getInstanceDescription();
114: }
115: //initialize second operand
116: String operandTitle2 = "";
117: String operandDesc2 = "";
118: if (this.operandCtchar.isStatic(1, inActc)) {
119: operandTitle2 =
120: this.operandCtchar.getValueAsString(1, inActc);
121: operandDesc2 =
122: this.operandCtchar.getValueAsString(1, inActc);
123: }
124: else if (this.operandCtchar.isHolderWithConceptTag(1, inActc)) {
125: StudioConceptTagInstanceInfoContext nextStiic =
126: this.operandCtchar.getInstanceInformation(1);
127:
128: operandTitle2 = nextStiic.getInstanceTitle();
129: operandDesc2 = nextStiic.getInstanceDescription();
130: }
131:
132: //set title and description
133: sctiic.setInstanceTitle(
134: "(" + operandTitle1 + " XOR " + operandTitle2 + ")");
135: sctiic.setInstanceDescription(
136: "(" + operandDesc1 + " XOR " + operandDesc2 + ")");
137: }
138: else {
139: sctiic.setInstanceTitle("(Error)");
140: sctiic.setInstanceDescription("(Error)");
141: }
142: */
143: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
144:
145: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
146:
147: scttic.setTypeTitle("XOR");
148: scttic
149: .setTypeDescription("Performs a logical xor - returns false"
150: + " unless on operand is true and the other is false");
151: } else if (inActc instanceof WebPageTagInstanceViewContext) {
152:
153: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
154:
155: WebPageTagInstanceViewContextInfo info = wptivc
156: .getInfoAsNonHtml();
157:
158: if (this .operandCtchar.getValueLength() >= 2) {
159: for (int i = 0; i < this .operandCtchar.getValueLength(); i++) {
160: WebPageTagInstanceViewContextInfo nextInfo = info
161: .createNonHtmlInfo();
162: if (i > 0) {
163: nextInfo.setNonHtmlContent(" XOR ");
164: }
165: WebPageTagInstanceViewContext.displayView(
166: this .operandCtchar, nextInfo, wptivc, i,
167: i + 1);
168: }
169: } else if (this .operandCtchar.getValueLength() == 1) {
170: WebPageTagInstanceViewContext.displayView(
171: this .operandCtchar, info, wptivc);
172: info.setNonHtmlContent("", " XOR ???");
173: } else {
174: info.setNonHtmlContent("", " XOR ---");
175: WebPageTagInstanceViewContextInfo subInfo = info
176: .createNonHtmlInfo(OPERAND_CTCON);
177: subInfo.setNonHtmlContent("???");
178: }
179: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
180:
181: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
182:
183: scfrct.canReturnBoolean();
184: scfrct.declareFormatAsPlain();
185: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
186:
187: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
188: }
189: }
190:
191: public void determineValueAndClass(
192: DetermineValueAndClassConceptTagContext inDvacctc) {
193:
194: try {
195: ValueAndClassForConceptTag vacfct = null;
196:
197: ValueAndClassForConceptTag operandVac1 = this .operandCtchar
198: .getDetermineValueAndClass(0, inDvacctc);
199: ValueAndClassForConceptTag operandVac2 = this .operandCtchar
200: .getDetermineValueAndClass(1, inDvacctc);
201:
202: boolean b1 = ((Boolean) operandVac1.getValue())
203: .booleanValue();
204: boolean b2 = ((Boolean) operandVac2.getValue())
205: .booleanValue();
206:
207: vacfct = ValueAndClassForConceptTag.newBoolean(new Boolean(
208: b1 ^ b2));
209:
210: inDvacctc.setDetermineValueAndClass(vacfct);
211: ;
212: } catch (DetermineValueAndClassConceptTagException dvaccte) {
213: inDvacctc.setDetermineException(dvaccte);
214: }
215: }
216:
217: public void determineClass(DetermineClassConceptTagContext inDcctc) {
218: inDcctc.setDetermineClass(StandardDataTypes.getBooleanClass());
219: }
220:
221: public Object createUninitializedSelf() {
222: return new CommonFunctionLogCompXorTag();
223: }
224: }
|