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.ConceptTag;
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.StaticConceptTagConstraintContext;
034: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
038: import org.jfolder.common.utils.misc.CommonExpressions;
039: import org.jfolder.common.utils.misc.MiscHelper;
040:
041: //other classes
042:
043: public class CommonFunctionMapGetValueTag extends
044: BaseCommonFunctionCompatibilityTag implements
045: SelfArgumentlessConstructor {
046:
047: //characteristics
048: private ConceptTagCharacteristic mapCtchar = null;
049: private ConceptTagCharacteristic keyCtchar = null;
050: private ConceptTagCharacteristic castToCtchar = null;
051:
052: //map details
053: private final static String MAP_CTCON = "map";
054: private final static String MAP_TITLE = "Map";
055: private final static String MAP_SHORT_DESCRIPTION = "Map";
056:
057: //key details
058: private final static String KEY_CTCON = "key";
059: private final static String KEY_TITLE = "Key";
060: private final static String KEY_SHORT_DESCRIPTION = "Key";
061:
062: //cast-to details
063: private final static String CAST_TO_CTCON = "cast-to";
064:
065: public void initialize(InitializeConceptTagContext inIctc) {
066:
067: //
068: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
069: .newInstance(inIctc);
070:
071: //constrain "map"
072: ConceptTagConstraint mapCtcon = ConceptTagConstraint
073: .newInstance(MAP_CTCON, rootCtconh);
074: //
075: mapCtcon.setTitle(MAP_TITLE);
076: mapCtcon.setShortDescription(MAP_SHORT_DESCRIPTION);
077: //
078: //
079: mapCtcon.setMinimumLength(1);
080: mapCtcon.setMaximumLength(1);
081: //
082: DynamicConceptTagConstraintContext mapDctcc = DynamicConceptTagConstraintContext
083: .newInstance(mapCtcon);
084: mapDctcc.getValidator().allowReturnOfOnlyMap();
085: mapDctcc.getValidator().filterDirectChildOfRootAndHtml();
086: //
087:
088: //constrain "key"
089: ConceptTagConstraint keyCtcon = ConceptTagConstraint
090: .newInstance(KEY_CTCON, rootCtconh);
091: //
092: keyCtcon.setTitle(KEY_TITLE);
093: keyCtcon.setShortDescription(KEY_SHORT_DESCRIPTION);
094: //
095: //
096: keyCtcon.setMinimumLength(1);
097: keyCtcon.setMaximumLength(1);
098: //
099: DynamicConceptTagConstraintContext keyDctcc = DynamicConceptTagConstraintContext
100: .newInstance(keyCtcon);
101: keyDctcc.getValidator().allowReturnOfAnythingExceptNothing();
102: keyDctcc.getValidator().filterDirectChildOfRootAndHtml();
103: //
104:
105: //
106: //constrain "cast-to"
107: ConceptTagConstraint castToCtcon = ConceptTagConstraint
108: .newInstance(CAST_TO_CTCON, rootCtconh);
109: ConceptTagHelper.formatConcreteVariableType(castToCtcon, true);
110:
111: //
112: ConceptTagFlagsHelper
113: .pushNonIterativeCommonFunctionDepth(inIctc);
114: inIctc.initialize();
115: ConceptTagFlagsHelper
116: .popNonIterativeCommonFunctionDepth(inIctc);
117:
118: //initialize characteristics
119: this .mapCtchar = mapCtcon.getCharacteristic();
120: this .keyCtchar = keyCtcon.getCharacteristic();
121: this .castToCtchar = castToCtcon.getCharacteristic();
122: }
123:
124: public void appraise(AppraiseConceptTagContext inActc) {
125:
126: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
127:
128: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
129:
130: //
131: sctiic.setInstanceTitle("Get Map Value");
132: sctiic.setInstanceDescription("Get Map Value");
133: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
134:
135: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
136:
137: scttic.setTypeTitle("Get Map Value");
138: scttic.setTypeDescription("Get Map Value");
139: } else if (inActc instanceof WebPageTagInstanceViewContext) {
140:
141: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
142:
143: WebPageTagInstanceViewContextInfo info = wptivc
144: .getInfoAsNonHtml();
145:
146: //
147: WebPageTagInstanceViewContextInfo getInfo = info
148: .createNonHtmlInfo();
149: getInfo.setNonHtmlContent("Get Value with Key (");
150: WebPageTagInstanceViewContext.displayView(this .keyCtchar,
151: getInfo, wptivc, "???");
152:
153: //
154: WebPageTagInstanceViewContextInfo fromInfo = info
155: .createNonHtmlInfo();
156: fromInfo.setNonHtmlContent(") From Map (", ")");
157: WebPageTagInstanceViewContext.displayView(this .mapCtchar,
158: fromInfo, wptivc, "???");
159: //fromInfo.setEndContent(")");
160:
161: //
162: //
163: WebPageTagInstanceViewContextInfo castToInfo = info
164: .createNonHtmlInfo();
165: castToInfo.setNonHtmlContent(" As (", ")");
166: WebPageTagInstanceViewContext.displayView(
167: this .castToCtchar, castToInfo, wptivc, "???");
168: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
169:
170: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
171:
172: scfrct.canReturnAnythingExceptNothing();
173: scfrct.declareFormatAsPlain();
174: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
175:
176: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
177: }
178: }
179:
180: public void determineValueAndClass(
181: DetermineValueAndClassConceptTagContext inDvacctc) {
182:
183: try {
184: ValueAndClassForConceptTag vacfct = null;
185:
186: ValueAndClassForConceptTag mapVacfct = this .mapCtchar
187: .getDetermineValueAndClass(0, inDvacctc);
188:
189: ValueAndClassForConceptTag keyVacfct = this .keyCtchar
190: .getDetermineValueAndClass(0, inDvacctc);
191:
192: Object o = StandardDataTypes.getValueFromMap(mapVacfct
193: .getValue(), keyVacfct);
194:
195: vacfct = ((ValueAndClassForConceptTag) o);
196:
197: inDvacctc.setDetermineValueAndClass(vacfct);
198: } catch (DetermineValueAndClassConceptTagException dvaccte) {
199: inDvacctc.setDetermineException(dvaccte);
200: }
201: }
202:
203: public void determineClass(DetermineClassConceptTagContext inDcctc) {
204:
205: Class result = StandardDataTypes.getAnyClass();
206: if (!this .castToCtchar.getParentMessageHolder()
207: .isErrorPresent()) {
208: result = StandardDataTypes.getActualClass(this .castToCtchar
209: .getValueAsString(0, inDcctc));
210: }
211:
212: inDcctc.setDetermineClass(result);
213: }
214:
215: public Object createUninitializedSelf() {
216: return new CommonFunctionMapGetValueTag();
217: }
218:
219: }
|