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.function.BaseCommonFunctionCompatibilityTag;
016: import org.jfolder.common.function.WebPageTagInstanceViewContext;
017: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
018: import org.jfolder.common.tagging.AppraiseConceptTagContext;
019: import org.jfolder.common.tagging.ConceptTagCharacteristic;
020: import org.jfolder.common.tagging.ConceptTagConstraint;
021: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
022: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
023: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
024: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
025: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
026: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
027: import org.jfolder.common.tagging.InitializeConceptTagContext;
028: import org.jfolder.common.tagging.ReturnableConceptTag;
029: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
030: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
031: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
032: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
033: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
034: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
035: import org.jfolder.common.utils.misc.CommonExpressions;
036:
037: //other classes
038:
039: public class CommonFunctionLangNullTag extends
040: BaseCommonFunctionCompatibilityTag implements
041: SelfArgumentlessConstructor {
042:
043: //characteristics
044: private ConceptTagCharacteristic typeCtchar = null;
045:
046: //type details
047: private final static String TYPE_CTCON = "type";
048: private final static String TYPE_TITLE = "Type";
049: private final static String TYPE_SHORT_DESCRIPTION = "Type of the null value";
050:
051: public void initialize(InitializeConceptTagContext inIctc) {
052:
053: //
054: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
055: .newInstance(inIctc);
056: //
057: //rootCtconh.getAttributes().setStudioVisibleOnlyOnError(true);
058: //rootCtconh.getStyles().setStudioVisibleOnlyOnError(true);
059:
060: //constrain "type"
061: ConceptTagConstraint typeCtcon = ConceptTagConstraint
062: .newInstance(TYPE_CTCON, rootCtconh);
063: typeCtcon.setTitle(TYPE_TITLE);
064: typeCtcon.setShortDescription(TYPE_SHORT_DESCRIPTION);
065: //
066: StaticConceptTagConstraintContext typeSctcc = StaticConceptTagConstraintContext
067: .newInstance(typeCtcon);
068: typeSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
069: //TO DO: correct this regular expression
070: //TO DO: check if class exists after initialization
071: //
072: typeSctcc.addDefaultValue("java.lang.Object");
073: //TO DO: should I ensure that type is not primitive?
074:
075: //constrain undefined
076: ConceptTagConstraint unconstrainedCtcon = rootCtconh
077: .getUndefinedConstraint();
078: //unconstrainedCtcon.setStudioVisibleOnlyOnError(true);
079:
080: //
081: ConceptTagFlagsHelper
082: .pushNonIterativeCommonFunctionDepth(inIctc);
083: inIctc.initialize();
084: ConceptTagFlagsHelper
085: .popNonIterativeCommonFunctionDepth(inIctc);
086:
087: //initialize characteristics
088: this .typeCtchar = typeCtcon.getCharacteristic();
089:
090: }
091:
092: public void appraise(AppraiseConceptTagContext inActc) {
093:
094: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
095:
096: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
097:
098: if (this .typeCtchar.getValueLength() > 0
099: && this .typeCtchar.isStatic(0, inActc)) {
100:
101: sctiic.setInstanceTitle("("
102: + this .typeCtchar.getValueAsString(0, inActc)
103: + ")null");
104: sctiic.setInstanceDescription("("
105: + this .typeCtchar.getValueAsString(0, inActc)
106: + ")null");
107: } else {
108: sctiic.setInstanceTitle("(Unknown)");
109: sctiic
110: .setInstanceDescription("Incorrect value specified");
111: }
112: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
113:
114: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
115:
116: scttic.setTypeTitle("Null");
117: scttic.setTypeDescription("Represents a null value");
118: } else if (inActc instanceof WebPageTagInstanceViewContext) {
119:
120: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
121:
122: WebPageTagInstanceViewContextInfo info = wptivc
123: .getInfoAsNonHtml();
124: info.setNonHtmlContent("Null - Not Impl");
125: //wptivc.getInfo().setStartContent("");
126: //wptivc.getInfo().setEndContent("");
127: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
128:
129: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
130:
131: scfrct.canReturnAnythingExceptNothing();
132: scfrct.declareFormatAsPlain();
133: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
134:
135: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
136: }
137: }
138:
139: public void determineValueAndClass(
140: DetermineValueAndClassConceptTagContext inDvacctc) {
141:
142: try {
143:
144: ValueAndClassForConceptTag vacfct = null;
145:
146: Class vClass = Class.forName(this .typeCtchar
147: .getValueAsString(0, inDvacctc));
148: vacfct = ValueAndClassForConceptTag.newInstance(null,
149: vClass);
150:
151: inDvacctc.setDetermineValueAndClass(vacfct);
152: } catch (ClassNotFoundException cnfe) {
153: inDvacctc.setDetermineException(cnfe);
154: }
155: }
156:
157: public void determineClass(DetermineClassConceptTagContext inDcctc) {
158:
159: try {
160: String s = this .typeCtchar.getValueAsString(0, inDcctc);
161: inDcctc.setDetermineClass(Class.forName(s));
162: } catch (ClassNotFoundException cnfe) {
163: inDcctc.setDetermineException(cnfe);
164: }
165: }
166:
167: public Object createUninitializedSelf() {
168: return new CommonFunctionLangNullTag();
169: }
170: }
|