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.ConceptTag;
022: import org.jfolder.common.tagging.ConceptTagCallContext;
023: import org.jfolder.common.tagging.ConceptTagCharacteristic;
024: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
025: import org.jfolder.common.tagging.ConceptTagConstraint;
026: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
027: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
028: import org.jfolder.common.tagging.ConceptTagMessageHolder;
029: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
030: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
031: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
032: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
033: import org.jfolder.common.tagging.InitializeConceptTagContext;
034: import org.jfolder.common.tagging.ReturnableConceptTag;
035: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
036: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
037: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
038: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
039: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
040: import org.jfolder.common.tagging.TemplateParameterForConceptTag;
041: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
042: import org.jfolder.common.utils.misc.CommonExpressions;
043: import org.jfolder.common.utils.misc.MiscHelper;
044: import org.jfolder.common.utils.xml.XMLHelper;
045:
046: //other classes
047:
048: public class CommonFunctionMacroDeclareTempIntTag extends
049: BaseCommonFunctionCompatibilityTag implements
050: SelfArgumentlessConstructor, TemplateParameterForConceptTag {
051:
052: //characteristics
053: private ConceptTagCharacteristic nameCtchar = null;
054: private ConceptTagCharacteristic descriptionCtchar = null;
055:
056: //name details
057: public final static String NAME_CTCON = "name";
058: private final static String NAME_TITLE = "Name";
059: private final static String NAME_SHORT_DESCRIPTION = "Name";
060:
061: //description details
062: public final static String DESCRIPTION_CTCON = "description";
063: private final static String DESCRIPTION_TITLE = "Description";
064: private final static String DESCRIPTION_SHORT_DESCRIPTION = "Description";
065:
066: public void initialize(InitializeConceptTagContext inIctc) {
067:
068: //
069: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
070: .newInstance(inIctc);
071:
072: //constrain "name"
073: ConceptTagConstraint nameCtcon = ConceptTagConstraint
074: .newInstance(NAME_CTCON, rootCtconh);
075: //
076: nameCtcon.setTitle(NAME_TITLE);
077: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
078: //
079: nameCtcon.setMinimumLength(1);
080: nameCtcon.setMaximumLength(1);
081: //
082: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
083: .newInstance(nameCtcon);
084: nameSctcc.setMultiLine(false);
085:
086: //constrain "description"
087: ConceptTagConstraint descriptionCtcon = ConceptTagConstraint
088: .newInstance(DESCRIPTION_CTCON, rootCtconh);
089: //
090: descriptionCtcon.setTitle(DESCRIPTION_TITLE);
091: descriptionCtcon
092: .setShortDescription(DESCRIPTION_SHORT_DESCRIPTION);
093: //
094: descriptionCtcon.setMinimumLength(1);
095: descriptionCtcon.setMaximumLength(1);
096: //
097: StaticConceptTagConstraintContext descriptionSctcc = StaticConceptTagConstraintContext
098: .newInstance(descriptionCtcon);
099:
100: //
101: ConceptTagFlagsHelper
102: .pushNonIterativeCommonFunctionDepth(inIctc);
103: inIctc.initialize();
104: ConceptTagFlagsHelper
105: .popNonIterativeCommonFunctionDepth(inIctc);
106:
107: //initialize characteristics
108: this .nameCtchar = nameCtcon.getCharacteristic();
109: this .descriptionCtchar = descriptionCtcon.getCharacteristic();
110:
111: //
112: if (this .nameCtchar.getValueLength() > 0
113: && this .nameCtchar.isStatic(0, inIctc)) {
114: //
115:
116: String declaredName = this .nameCtchar.getValueAsString(0,
117: inIctc);
118: //
119: if (!ConceptTagFlagsHelper
120: .isVariableNameValid(declaredName)) {
121: nameCtcon
122: .registerError("Cannot declare template interface name '"
123: + declaredName
124: + "' because it must start with a letter,"
125: + " and each other character must be a letter, digit,"
126: + " or underscore");
127: }
128: //
129: if (ConceptTagFlagsHelper.isTemplateInterfacePresent(
130: inIctc, declaredName)) {
131: //
132: nameCtcon
133: .registerError("Another template interface shares the name '"
134: + declaredName + "'");
135: }
136:
137: ConceptTagMessageHolder nameCtmh = this .nameCtchar
138: .getParentMessageHolder();
139: ConceptTagMessageHolder descriptionCtmh = this .descriptionCtchar
140: .getParentMessageHolder();
141: //
142: if (!nameCtmh.isErrorPresent()
143: && !descriptionCtmh.isErrorPresent()) {
144: //
145: String declaredDescription = this .descriptionCtchar
146: .getValueAsString(0, inIctc);
147: //
148: ConceptTagCharacteristicHolder ctcharh = rootCtconh
149: .getCharacteristicHolder();
150: int ctcharhIndex = ctcharh
151: .getParentCharacteristicIndex();
152: //
153: if (rootCtconh.isParentConstraintPresent()) {
154: ConceptTagConstraint parentCtcon = rootCtconh
155: .getParentConstraint();
156: //
157: ConceptTagFlagsHelper.registerTemplateInterface(
158: inIctc, declaredName, declaredDescription,
159: parentCtcon, ctcharhIndex);
160: }
161:
162: }
163: }
164: //
165: }
166:
167: public void appraise(AppraiseConceptTagContext inActc) {
168:
169: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
170:
171: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
172:
173: sctiic.setInstanceTitle("Template Interface");
174: sctiic.setInstanceDescription("Template Interface");
175: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
176:
177: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
178:
179: scttic.setTypeTitle("Template Interface");
180: scttic.setTypeDescription("Template Interface");
181: } else if (inActc instanceof WebPageTagInstanceViewContext) {
182:
183: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
184: //
185: WebPageTagInstanceViewContextInfo info = wptivc
186: .getInfoAsNonHtml();
187: //
188: WebPageTagInstanceViewContextInfo firstSubInfo = info
189: .createNonHtmlInfo();
190: WebPageTagInstanceViewContextInfo secondSubInfo = info
191: .createNonHtmlInfo();
192: //
193: //
194: firstSubInfo.setNonHtmlContent("templateInterface(", ")");
195: WebPageTagInstanceViewContext.displayView(this .nameCtchar,
196: firstSubInfo, wptivc, "???");
197: //firstSubInfo.setEndContent(")");
198: //
199: //
200: secondSubInfo.setNonHtmlContent(" withDescription(", ")");
201: WebPageTagInstanceViewContext.displayView(
202: this .descriptionCtchar, secondSubInfo, wptivc,
203: "???");
204: //secondSubInfo.setEndContent(")");
205: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
206:
207: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
208:
209: //scfrct.canReturnAnythingIncludingNothing();
210: scfrct.setAutoValidateForTemplateInterface(true);
211: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
212:
213: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
214: }
215: }
216:
217: public void determineValueAndClass(
218: DetermineValueAndClassConceptTagContext inDvacctc) {
219:
220: //
221: inDvacctc
222: .setDetermineException(new DetermineValueAndClassConceptTagException(
223: "This should not be called ("
224: + this .nameCtchar.getValueAsString(0,
225: inDvacctc) + ")"));
226: }
227:
228: public void determineClass(DetermineClassConceptTagContext inDcctc) {
229: inDcctc.setDetermineClass(StandardDataTypes.getAnyClass());
230: }
231:
232: public Object createUninitializedSelf() {
233: return new CommonFunctionMacroDeclareTempIntTag();
234: }
235:
236: //
237: //
238: //
239: //
240: //
241: public boolean isTemplateParameterActive(
242: ConceptTagCallContext inCtcc) {
243: return (getParameterCharacteristic(inCtcc) != null);
244: }
245:
246: //
247: //
248: public boolean isStatic(ConceptTagCallContext inCtcc) {
249:
250: boolean outValue = false;
251:
252: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
253:
254: if (localCtchar != null) {
255: outValue = (localCtchar.getValueLength() > 0 && localCtchar
256: .isStatic(0, inCtcc));
257: } else {
258: outValue = false;
259: }
260:
261: return outValue;
262: }
263:
264: public boolean isHolderWithConceptTag(ConceptTagCallContext inCtcc) {
265:
266: boolean outValue = false;
267:
268: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
269:
270: if (localCtchar != null) {
271: outValue = (localCtchar.getValueLength() > 0 && localCtchar
272: .isHolderWithConceptTag(0, inCtcc));
273: } else {
274: outValue = true;
275: }
276:
277: return outValue;
278: }
279:
280: public boolean isHolderWithoutConceptTag(
281: ConceptTagCallContext inCtcc) {
282:
283: boolean outValue = false;
284:
285: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
286:
287: if (localCtchar != null) {
288: outValue = (localCtchar.getValueLength() > 0 && localCtchar
289: .isHolderWithoutConceptTag(0, inCtcc));
290: } else {
291: outValue = false;
292: }
293:
294: return outValue;
295: }
296:
297: public boolean isHolder(ConceptTagCallContext inCtcc) {
298:
299: boolean outValue = false;
300:
301: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
302:
303: if (localCtchar != null) {
304: outValue = (localCtchar.getValueLength() > 0 && localCtchar
305: .isHolderWithConceptTag(0, inCtcc));
306: } else {
307: outValue = true;
308: }
309:
310: return outValue;
311: }
312:
313: //
314: public String getValueAsString(ConceptTagCallContext inCtcc) {
315:
316: String outValue = null;
317:
318: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
319:
320: if (localCtchar != null) {
321: outValue = localCtchar.getValueAsString(0, inCtcc);
322: } else {
323: throw UnexpectedSystemException.unknownState();
324: }
325:
326: return outValue;
327: }
328:
329: public ConceptTagCharacteristicHolder getValueAsHolder(
330: ConceptTagCallContext inCtcc) {
331: //
332:
333: ConceptTagCharacteristicHolder outValue = null;
334:
335: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
336:
337: if (localCtchar != null) {
338: outValue = localCtchar.getValueAsHolder(0, inCtcc);
339: } else {
340: throw UnexpectedSystemException.unknownState();
341: }
342:
343: return outValue;
344: }
345:
346: public ConceptTag getValueAsConceptTag(ConceptTagCallContext inCtcc) {
347: //
348:
349: ConceptTag outValue = null;
350:
351: ConceptTagCharacteristic localCtchar = getParameterCharacteristic(inCtcc);
352:
353: if (localCtchar != null) {
354: outValue = localCtchar.getValueAsConceptTag(0, inCtcc);
355: } else {
356: throw UnexpectedSystemException.unknownState();
357: }
358:
359: return outValue;
360: }
361:
362: //
363: //
364: //
365: private ConceptTagCharacteristic getParameterCharacteristic(
366: ConceptTagCallContext inCtcc) {
367: //
368: ConceptTagCharacteristic outValue = null;
369:
370: if (inCtcc != null && this .nameCtchar != null) {
371: if (this .nameCtchar.getValueLength() > 0
372: && this .nameCtchar.isStatic(0, inCtcc)) {
373: //
374: String declaredName = this .nameCtchar.getValueAsString(
375: 0, inCtcc);
376: if (ConceptTagFlagsHelper
377: .isTemplateCallParameterPresent(inCtcc,
378: declaredName)) {
379: //
380: outValue = ConceptTagFlagsHelper
381: .getTemplateCallParameter(inCtcc,
382: declaredName);
383: }
384: }
385: }
386:
387: return outValue;
388: }
389: }
|