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.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.StudioConceptTagCreParInfoContext;
034: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
036: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
037:
038: //other classes
039:
040: public class CommonFunctionStrGetLengthTag extends
041: BaseCommonFunctionCompatibilityTag implements
042: SelfArgumentlessConstructor {
043:
044: //characteristics
045: private ConceptTagCharacteristic operandCtchar = null;
046:
047: //operand details
048: private final static String OPERAND_CTCON = "operand";
049: private final static String OPERAND_TITLE = "Operand";
050: private final static String OPERAND_SHORT_DESCRIPTION = "Value whose length will be determined";
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: //
062: operandCtcon.setTitle(OPERAND_TITLE);
063: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
064: //
065: operandCtcon.setMinimumLength(1);
066: operandCtcon.setMaximumLength(1);
067: //
068: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
069: .newInstance(operandCtcon);
070: operandDctcc.getValidator().allowReturnOfOnlyString();
071: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
072: //
073: //operandDctcc.addDefaultValue(
074: // GetApplicationAttributeWorkflowTemplateTag.class);
075: //TO DO: should there be a default?
076: //TO DO: possibly constrain return type here instead of below?
077:
078: //
079: ConceptTagFlagsHelper
080: .pushNonIterativeCommonFunctionDepth(inIctc);
081: inIctc.initialize();
082: ConceptTagFlagsHelper
083: .popNonIterativeCommonFunctionDepth(inIctc);
084: //TO DO: check if casting is acceptable after initialization
085:
086: //initialize characteristics
087: this .operandCtchar = operandCtcon.getCharacteristic();
088:
089: }
090:
091: public void appraise(AppraiseConceptTagContext inActc) {
092:
093: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
094:
095: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
096:
097: sctiic.setInstanceTitle("Get String Length");
098: sctiic.setInstanceDescription("Get String Length");
099: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
100:
101: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
102:
103: scttic.setTypeTitle("Get String Length");
104: scttic.setTypeDescription("Get String Length");
105: } else if (inActc instanceof WebPageTagInstanceViewContext) {
106:
107: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
108:
109: WebPageTagInstanceViewContextInfo info = wptivc
110: .getInfoAsNonHtml();
111:
112: //
113: //
114: WebPageTagInstanceViewContextInfo operandInfo = info
115: .createNonHtmlInfo();
116: operandInfo.setNonHtmlContent("getLength(", ")");
117: WebPageTagInstanceViewContext.displayView(
118: this .operandCtchar, operandInfo, wptivc, "???");
119: //operandInfo.setEndContent(")");
120: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
121:
122: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
123:
124: scfrct.canReturnDecimal();
125: scfrct.declareFormatAsPlain();
126: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
127:
128: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
129: }
130: }
131:
132: public void determineValueAndClass(
133: DetermineValueAndClassConceptTagContext inDvacctc) {
134:
135: try {
136:
137: ValueAndClassForConceptTag vacfct = null;
138:
139: ValueAndClassForConceptTag operandVac = this .operandCtchar
140: .getDetermineValueAndClass(0, inDvacctc);
141: BigDecimal result = new BigDecimal(((String) operandVac
142: .getValue()).length());
143: vacfct = ValueAndClassForConceptTag.newDecimal(result);
144:
145: inDvacctc.setDetermineValueAndClass(vacfct);
146: } catch (DetermineValueAndClassConceptTagException dvaccte) {
147: inDvacctc.setDetermineException(dvaccte);
148: } catch (NumberFormatException nfe) {
149: inDvacctc.setDetermineException(nfe);
150: }
151: }
152:
153: public void determineClass(DetermineClassConceptTagContext inDcctc) {
154: inDcctc.setDetermineClass(StandardDataTypes.getDecimalClass());
155: }
156:
157: public Object createUninitializedSelf() {
158: return new CommonFunctionStrGetLengthTag();
159: }
160: }
|