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.util.HashMap;
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.tagging.AppraiseConceptTagContext;
020: import org.jfolder.common.tagging.ConceptTagCharacteristic;
021: import org.jfolder.common.tagging.ConceptTagConstraint;
022: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
023: import org.jfolder.common.tagging.ConceptTagConstraintOrTemplate;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
026: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
027: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
028: import org.jfolder.common.tagging.DynamicConceptTagValidator;
029: import org.jfolder.common.tagging.InitializeConceptTagContext;
030: import org.jfolder.common.tagging.PostValidatorForConceptTagConstraint;
031: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
032: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
033: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
034: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
035: import org.jfolder.common.utils.misc.CommonExpressions;
036: import org.jfolder.platforms.stores.base.ApplicationDataSourceResolver;
037: import org.jfolder.services.config.ApplicationStoreSet;
038: import org.jfolder.services.config.ConfigService;
039: import org.jfolder.services.config.ConfigServiceCallerFactory;
040:
041: //other classes
042:
043: public class PostConstraintValidatorForDataSource implements
044: PostValidatorForConceptTagConstraint {
045: //
046:
047: //
048: private PostConstraintValidatorForDataSource() {
049: //
050: }
051:
052: //
053: public final static PostConstraintValidatorForDataSource newInstance() {
054: //
055: PostConstraintValidatorForDataSource outValue = new PostConstraintValidatorForDataSource();
056:
057: return outValue;
058: }
059:
060: //
061: public void postValidate(InitializeConceptTagContext inIctc,
062: ConceptTagConstraint inCtcon) {
063: //
064: ConceptTagCharacteristic dataSourceCtchar = inCtcon
065: .getCharacteristic();
066: if (!inCtcon.isParentErrorPresent()
067: && dataSourceCtchar.getValueLength() > 0) {
068: //
069: String dataSource = dataSourceCtchar.getValueAsString(0,
070: inIctc);
071: if (!ConceptTagFlagsHelper
072: .isCurrentDataSourcePresent(inIctc)) {
073: ConceptTagFlagsHelper.createCurrentDataSource(inIctc,
074: dataSource);
075: } else {
076: inCtcon
077: .registerError("Another data source named '"
078: + ConceptTagFlagsHelper
079: .getCurrentDataSource(inIctc)
080: + "' is already registered, so data source '"
081: + dataSource
082: + "' cannot be declared (even if it is the same)");
083: }
084: }
085: }
086:
087: public final static void initializeDataSourceCtcon(
088: ConceptTagConstraint inDataSourceCtcon,
089: InitializeConceptTagContext inIctc) {
090: //
091: //
092: //
093: StaticConceptTagConstraintContext dataSourceSctcc = StaticConceptTagConstraintContext
094: .newInstance(inDataSourceCtcon);
095: //
096: if (!ConceptTagFlagsHelper.isCurrentDataSourcePresent(inIctc)) {
097: inDataSourceCtcon.setMinimumLength(1);
098: inDataSourceCtcon.setMaximumLength(1);
099: //
100: inDataSourceCtcon
101: .registerPostValidator(PostConstraintValidatorForDataSource
102: .newInstance());
103: } else {
104: inDataSourceCtcon.setMinimumLength(0);
105: inDataSourceCtcon.setMaximumLength(0);
106: }
107: //
108: //
109: ConfigService cs = ConfigServiceCallerFactory
110: .getConfigService();
111: ApplicationStoreSet ass = ApplicationStoreSet.newInstance(cs);
112: if (ass.getDataSourceCount() > 0) {
113: dataSourceSctcc.setEntrySetExclusive(true);
114: for (int i = 0; i < ass.getDataSourceCount(); i++) {
115: if (i == 0) {
116: dataSourceSctcc.addDefaultValue(ass
117: .getActualName(i));
118: }
119: dataSourceSctcc.registerEntry(ass.getDisplayName(i),
120: ass.getActualName(i));
121: }
122: } else {
123: dataSourceSctcc.addDefaultValue("DataSource");
124: }
125: }
126:
127: public final static void closeDataSource(
128: ConceptTagConstraint inDataSourceCtcon,
129: InitializeConceptTagContext inIctc) {
130: //
131: ConceptTagCharacteristic localDsCtchar = inDataSourceCtcon
132: .getCharacteristic();
133: //
134: if (!inDataSourceCtcon.isParentErrorPresent()
135: && localDsCtchar.getValueLength() > 0) {
136: //
137: ConceptTagFlagsHelper.removeCurrentDataSource(inIctc);
138: }
139: }
140:
141: public final static void initializeActionCtcon(
142: ConceptTagConstraint inActionCtcon,
143: InitializeConceptTagContext inIctc) {
144: //
145: initializeActionCtcon(inActionCtcon, inIctc, true);
146: }
147:
148: public final static void initializeActionCtcon(
149: ConceptTagConstraint inActionCtcon,
150: InitializeConceptTagContext inIctc, boolean inIncludeText) {
151: //
152: if (inIncludeText) {
153: StaticConceptTagConstraintContext actionSctcc = StaticConceptTagConstraintContext
154: .newInstance(inActionCtcon);
155: }
156: //
157: DynamicConceptTagConstraintContext actionDctcc = DynamicConceptTagConstraintContext
158: .newInstance(inActionCtcon);
159: DynamicConceptTagValidator actionDctv = actionDctcc
160: .getValidator();
161: actionDctv.allowReturnOfAnythingIncludingNothing();
162: actionDctv.filterDirectChildOfRootAndHtml();
163: //
164: inActionCtcon.setMinimumLength(0);
165: inActionCtcon.setLengthUnbounded(true);
166: }
167: }
|