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.web.page.v1;
009:
010: //base classes
011: import java.util.HashMap;
012:
013: //project specific classes
014: import org.jfolder.common.StandardDataTypes;
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.files.WebPageTagMacro;
017: import org.jfolder.common.files.WebPageTagMacroHelper;
018: import org.jfolder.common.function.BaseWebPageTag;
019: import org.jfolder.common.function.WebPageTagInstanceViewContext;
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.ConceptTagPreferences;
025: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
026: import org.jfolder.common.tagging.DynamicConceptTagValidator;
027: import org.jfolder.common.tagging.InitializeConceptTagContext;
028: import org.jfolder.common.tagging.PreIterValForCompoundConceptTagConContext;
029: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
030: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
031: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
032: import org.jfolder.common.utils.misc.CommonExpressions;
033:
034: //other classes
035:
036: public class PreIterCompoundValForMacroValue implements
037: PreIterValForCompoundConceptTagConContext {
038:
039: //
040: private ConceptTagConstraint nameCtcon = null;
041: private String valueCtconName = null;
042:
043: //
044: private PreIterCompoundValForMacroValue(
045: ConceptTagConstraint inNameCtcon, String inValueCtconName) {
046: //
047: this .nameCtcon = inNameCtcon;
048: this .valueCtconName = inValueCtconName;
049: }
050:
051: //
052: protected final static PreIterCompoundValForMacroValue newInstance(
053: ConceptTagConstraint inNameCtcon, String inValueCtconName) {
054: //
055: PreIterCompoundValForMacroValue outValue = null;
056:
057: outValue = new PreIterCompoundValForMacroValue(inNameCtcon,
058: inValueCtconName);
059:
060: return outValue;
061: }
062:
063: //
064: public void preIterativeValidate(int inIndex,
065: InitializeConceptTagContext inIctc,
066: ConceptTagConstraintHolder inCtconh) {
067: //
068: ConceptTagCharacteristic nameCtchar = this .nameCtcon
069: .getCharacteristic();
070: if (nameCtchar.getValueLength() > 0
071: && nameCtchar.isStatic(0, inIctc)
072: && !inCtconh.isParentErrorPresent()) {
073: preIterativeValidateWithValidData(inIndex, inIctc, inCtconh);
074: }
075: }
076:
077: //
078: //
079: //
080: public void preIterativeValidateWithValidData(int inIndex,
081: InitializeConceptTagContext inIctc,
082: ConceptTagConstraintHolder inCtconh) {
083: //
084: ConceptTagCharacteristic nameCtchar = this .nameCtcon
085: .getCharacteristic();
086: //
087: //
088: ConceptTagConstraint valueCtcon = inCtconh
089: .getConstraint(this .valueCtconName);
090: //
091: String macroHandle = nameCtchar.getValueAsString(0, inIctc);
092: WebPageTagMacro macro = WebPageTagMacroHelper
093: .getMacroFromMacroHandle(macroHandle);
094: //
095: String parameterType = macro.getParameterType(inIndex);
096: //throw UnexpectedSystemException.notImplemented();
097: HashMap dntc = StandardDataTypes.getDisplayNameToClass();
098: if (dntc.containsKey(parameterType)) {
099: //
100: Class parameterClass = ((Class) dntc.get(parameterType));
101: //
102: if (valueCtcon.isStaticContextPresent()) {
103: valueCtcon.unregisterStaticConstraintContext();
104: }
105: //
106: if (valueCtcon.isDynamicContextPresent()) {
107: valueCtcon.unregisterDynamicConstraintContext();
108: }
109: //
110: if (StandardDataTypes.isBooleanClass(parameterClass)) {
111: //
112: StaticConceptTagConstraintContext ctconSctcc = StaticConceptTagConstraintContext
113: .newInstance(valueCtcon);
114: //
115: ctconSctcc.setEntrySetExclusive(true);
116: ctconSctcc.registerEntry(true + "", true + "");
117: ctconSctcc.registerEntry(false + "", false + "");
118: ctconSctcc.addDefaultValue(true + "");
119: //
120: DynamicConceptTagConstraintContext ctconDctcc = DynamicConceptTagConstraintContext
121: .newInstance(valueCtcon);
122: DynamicConceptTagValidator ctconDctv = ctconDctcc
123: .getValidator();
124: ctconDctv.addReturnClassesMustBe(StandardDataTypes
125: .getBooleanClass(), "Value must be Boolean");
126: } else if (StandardDataTypes.isDecimalClass(parameterClass)) {
127: //
128: StaticConceptTagConstraintContext ctconSctcc = StaticConceptTagConstraintContext
129: .newInstance(valueCtcon);
130: //
131: ctconSctcc.setRegularExpression(
132: CommonExpressions.DECIMAL,
133: "Value must be Decimal");
134: ctconSctcc.addDefaultValue(0 + "");
135: //
136: DynamicConceptTagConstraintContext ctconDctcc = DynamicConceptTagConstraintContext
137: .newInstance(valueCtcon);
138: DynamicConceptTagValidator ctconDctv = ctconDctcc
139: .getValidator();
140: ctconDctv.addReturnClassesMustBe(StandardDataTypes
141: .getDecimalClass(), "Value must be Decimal");
142: } else if (StandardDataTypes.isStringClass(parameterClass)) {
143: //
144: StaticConceptTagConstraintContext ctconSctcc = StaticConceptTagConstraintContext
145: .newInstance(valueCtcon);
146: //
147: ctconSctcc.addDefaultValue("YourTextHere");
148: ctconSctcc.setMultiLine(true);
149: //
150: DynamicConceptTagConstraintContext ctconDctcc = DynamicConceptTagConstraintContext
151: .newInstance(valueCtcon);
152: DynamicConceptTagValidator ctconDctv = ctconDctcc
153: .getValidator();
154: ctconDctv.addReturnClassesMustBe(StandardDataTypes
155: .getStringClass(), "Value must be String");
156: } else {
157: throw UnexpectedSystemException.unknownState();
158: }
159: }
160:
161: }
162: }
|