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: import java.text.DecimalFormat;
013:
014: //project specific classes
015: import org.jfolder.common.SelfArgumentlessConstructor;
016: import org.jfolder.common.StandardDataTypes;
017: import org.jfolder.common.UnexpectedSystemException;
018: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
019: import org.jfolder.common.function.WebPageTagInstanceViewContext;
020: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
021: import org.jfolder.common.tagging.AppraiseConceptTagContext;
022: import org.jfolder.common.tagging.ConceptTagCharacteristic;
023: import org.jfolder.common.tagging.ConceptTagConstraint;
024: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
025: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
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.SelectionCriteriaForReturnableConceptTag;
032: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
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: import org.jfolder.common.utils.misc.MiscHelper;
038:
039: //other classes
040:
041: public class CommonFunctionStrFormatDecimalTag extends
042: BaseCommonFunctionCompatibilityTag implements
043: SelfArgumentlessConstructor {
044:
045: //
046: private ConceptTagCharacteristic formatCtchar = null;
047: private ConceptTagCharacteristic valueCtchar = null;
048:
049: //format details
050: private final static String FORMAT_CTCON = "format";
051: private final static String FORMAT_TITLE = "Decimal Format";
052: private final static String FORMAT_SHORT_DESCRIPTION = "Format of the value";
053:
054: //value details
055: private final static String VALUE_CTCON = "value";
056: private final static String VALUE_TITLE = "Value";
057: private final static String VALUE_SHORT_DESCRIPTION = "Value of this string";
058:
059: //
060:
061: public void initialize(InitializeConceptTagContext inIctc) {
062:
063: //
064: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
065: .newInstance(inIctc);
066: //
067:
068: //constrain "format"
069: ConceptTagConstraint formatCtcon = ConceptTagConstraint
070: .newInstance(FORMAT_CTCON, rootCtconh);
071: //
072: formatCtcon.setTitle(FORMAT_TITLE);
073: formatCtcon.setShortDescription(FORMAT_SHORT_DESCRIPTION);
074: //
075: formatCtcon.setMinimumLength(1);
076: formatCtcon.setMaximumLength(1);
077: //
078: StaticConceptTagConstraintContext formatSctcc = StaticConceptTagConstraintContext
079: .newInstance(formatCtcon);
080: //
081: formatSctcc.setEntrySetExclusive(true);
082: formatSctcc.registerEntry("0.001", "0.001");
083: formatSctcc.registerEntry("0.01", "0.01");
084: formatSctcc.registerEntry("0.1", "0.1");
085: formatSctcc.registerEntry("1", "1");
086: formatSctcc.registerEntry("10", "10");
087: formatSctcc.registerEntry("100", "100");
088: formatSctcc.registerEntry("1000", "1000");
089: formatSctcc.registerEntry("1000000", "1000000");
090:
091: //constrain "value"
092: ConceptTagConstraint valueCtcon = ConceptTagConstraint
093: .newInstance(VALUE_CTCON, rootCtconh);
094: //
095: valueCtcon.setMinimumLength(1);
096: valueCtcon.setMaximumLength(1);
097: //
098: valueCtcon.setTitle(VALUE_TITLE);
099: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
100: //
101: DynamicConceptTagConstraintContext valueDctcc = DynamicConceptTagConstraintContext
102: .newInstance(valueCtcon);
103: valueDctcc.getValidator().filterDirectChildOfRootAndHtml();
104:
105: //
106: ConceptTagFlagsHelper
107: .pushNonIterativeCommonFunctionDepth(inIctc);
108: inIctc.initialize();
109: ConceptTagFlagsHelper
110: .popNonIterativeCommonFunctionDepth(inIctc);
111:
112: //
113: this .formatCtchar = formatCtcon.getCharacteristic();
114: this .valueCtchar = valueCtcon.getCharacteristic();
115: }
116:
117: public void appraise(AppraiseConceptTagContext inActc) {
118:
119: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
120:
121: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
122:
123: sctiic.setInstanceTitle("Format Decimal");
124: sctiic.setInstanceDescription("Format Decimal");
125: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
126:
127: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
128:
129: scttic.setTypeTitle("Format Decimal");
130: scttic.setTypeDescription("Format Decimal");
131: } else if (inActc instanceof WebPageTagInstanceViewContext) {
132:
133: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
134:
135: WebPageTagInstanceViewContextInfo info = wptivc
136: .getInfoAsNonHtml();
137: //
138: //
139: WebPageTagInstanceViewContextInfo firstInfo = info
140: .createNonHtmlInfo();
141: //
142: firstInfo.setNonHtmlContent("Format Decimal(",
143: ") To Granularity");
144: //
145: WebPageTagInstanceViewContext.displayView(this .valueCtchar,
146: firstInfo, wptivc, "???");
147: //
148: //
149: //
150: WebPageTagInstanceViewContextInfo secondInfo = info
151: .createNonHtmlInfo();
152: //
153: secondInfo.setNonHtmlContent("(", ")");
154: //
155: WebPageTagInstanceViewContext.displayView(
156: this .formatCtchar, secondInfo, wptivc, "???");
157: //
158: //
159: //
160: //info.setNonHtmlContent("FormatDec - Not Impl");
161:
162: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
163:
164: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
165:
166: scfrct.canReturnString();
167: scfrct.declareFormatAsPlain();
168: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
169:
170: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
171: }
172: }
173:
174: public void determineValueAndClass(
175: DetermineValueAndClassConceptTagContext inDvacctc) {
176:
177: try {
178: //
179: ValueAndClassForConceptTag vacfct = null;
180: //
181: String format = this .formatCtchar.getValueAsString(0,
182: inDvacctc);
183: BigDecimal formatBd = new BigDecimal(format);
184: //
185: ValueAndClassForConceptTag valueVac = this .valueCtchar
186: .getDetermineValueAndClass(0, inDvacctc);
187: //
188: BigDecimal value = (BigDecimal) valueVac.getValue();
189: //
190: value = value.divide(formatBd);
191: value = new BigDecimal(value.toBigInteger());
192: value = value.multiply(formatBd);
193: //
194: //DecimalFormat df = new DecimalFormat(format);
195: vacfct = ValueAndClassForConceptTag.newString(value
196: .toString());
197:
198: inDvacctc.setDetermineValueAndClass(vacfct);
199: } catch (DetermineValueAndClassConceptTagException dvaccte) {
200: inDvacctc.setDetermineException(dvaccte);
201: }
202: }
203:
204: public void determineClass(DetermineClassConceptTagContext inDcctc) {
205:
206: inDcctc.setDetermineClass(StandardDataTypes.getStringClass());
207: }
208:
209: public Object createUninitializedSelf() {
210: return new CommonFunctionStrFormatDecimalTag();
211: }
212: }
|