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 CommonFunctionConvStrToDecTag 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 to be converted into a decimal";
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.setTitle(OPERAND_TITLE);
062: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
063: operandCtcon.setMinimumLength(1);
064: operandCtcon.setMaximumLength(1);
065: //
066: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
067: .newInstance(operandCtcon);
068: operandDctcc.getValidator().allowReturnOfOnlyString();
069: operandDctcc.getValidator().filterDirectChildOfRootAndHtml();
070: //
071: //operandDctcc.addDefaultValue(
072: // GetApplicationAttributeWorkflowTemplateTag.class);
073: //TO DO: should there be a default?
074: //TO DO: possibly constrain return type here instead of below?
075:
076: //
077: ConceptTagFlagsHelper
078: .pushNonIterativeCommonFunctionDepth(inIctc);
079: inIctc.initialize();
080: ConceptTagFlagsHelper
081: .popNonIterativeCommonFunctionDepth(inIctc);
082: //TO DO: check if casting is acceptable after initialization
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("String To Decimal");
096: sctiic
097: .setInstanceDescription("Converts String to a Decimal");
098: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
099:
100: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
101:
102: scttic.setTypeTitle("String To Decimal");
103: scttic.setTypeDescription("Converts String to a Decimal");
104: } else if (inActc instanceof WebPageTagInstanceViewContext) {
105:
106: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
107:
108: WebPageTagInstanceViewContextInfo info = wptivc
109: .getInfoAsNonHtml();
110:
111: //
112: //
113: WebPageTagInstanceViewContextInfo operandInfo = info
114: .createNonHtmlInfo();
115: operandInfo.setNonHtmlContent("ToDecimal(", ")");
116: WebPageTagInstanceViewContext.displayView(
117: this .operandCtchar, operandInfo, wptivc, "???");
118: //operandInfo.setEndContent(")");
119: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
120:
121: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
122:
123: scfrct.canReturnDecimal();
124: scfrct.declareFormatAsPlain();
125: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
126:
127: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
128: }
129: }
130:
131: public void determineValueAndClass(
132: DetermineValueAndClassConceptTagContext inDvacctc) {
133:
134: try {
135:
136: ValueAndClassForConceptTag vacfct = null;
137:
138: ValueAndClassForConceptTag operandVac = this .operandCtchar
139: .getDetermineValueAndClass(0, inDvacctc);
140: BigDecimal result = new BigDecimal((String) operandVac
141: .getValue());
142: vacfct = ValueAndClassForConceptTag.newDecimal(result);
143:
144: inDvacctc.setDetermineValueAndClass(vacfct);
145: } catch (DetermineValueAndClassConceptTagException dvaccte) {
146: inDvacctc.setDetermineException(dvaccte);
147: } catch (NumberFormatException nfe) {
148: inDvacctc.setDetermineException(nfe);
149: }
150: }
151:
152: public void determineClass(DetermineClassConceptTagContext inDcctc) {
153: inDcctc.setDetermineClass(StandardDataTypes.getDecimalClass());
154: }
155:
156: public Object createUninitializedSelf() {
157: return new CommonFunctionConvStrToDecTag();
158: }
159: }
|