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.tagging;
009:
010: //base classes
011: import java.util.ArrayList;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015: import org.jfolder.common.utils.misc.MiscHelper;
016:
017: //other classes
018:
019: public abstract class ConceptTagConstraintOrTemplate extends
020: ConceptTagConstraintType {
021:
022: //quantitative
023: private int minLength = 0;
024: private int maxLength = 0;
025: private boolean noMaxLength = false;
026: //private int defaultLength = 0;
027: //qualitative
028: private String name = null;
029: //
030: private CompoundConceptTagConstraintContext cctcc = null;
031: private DynamicConceptTagConstraintContext dctcc = null;
032: private StaticConceptTagConstraintContext sctcc = null;
033: //
034: private ArrayList defaultList = null;
035: //
036: private ArrayList preVfctcList = null;
037: private ArrayList postVfctcList = null;
038: //
039: private ArrayList preIterVfctcList = null;
040: private ArrayList postIterVfctcList = null;
041: //
042: private boolean displayAsBranch = false;
043: //
044: private boolean mergeAdjacentTextNodes = false;
045:
046: protected ConceptTagConstraintOrTemplate(String inName,
047: ConceptTagPreferences inCtp) {
048:
049: super (inCtp);
050:
051: this .name = inName;
052: //
053: this .minLength = 0;
054: this .maxLength = 0;
055: this .noMaxLength = true;
056: //this.defaultLength = 1;
057: //
058: this .defaultList = new ArrayList();
059: //
060: this .preVfctcList = new ArrayList();
061: this .postVfctcList = new ArrayList();
062: //
063: this .preIterVfctcList = new ArrayList();
064: this .postIterVfctcList = new ArrayList();
065: //
066: this .displayAsBranch = true;
067: }
068:
069: //
070: //
071: protected void initializeBaseMembers(
072: ConceptTagConstraintOrTemplate inCtcot) {
073: //
074: inCtcot.setTitle(getTitle());
075: inCtcot.setShortDescription(getShortDescription());
076: inCtcot.setLongDescription(getLongDescription());
077: inCtcot.setIcon(getIcon());
078: //inCtcon.setStudioVisibleOnlyOnError(isStudioVisibleOnlyOnError());
079: //
080: inCtcot.setMinimumLength(getMinimumLength());
081: inCtcot.setMaximumLength(getMaximumLength());
082: inCtcot.setLengthUnbounded(isLengthUnbounded());
083: //
084: inCtcot.setValidationFlags(getValidationFlags());
085: //
086: //TO DO: try to use some kind of 'clone' feature below
087: if (isStaticContextPresent()) {
088: inCtcot
089: .registerConstraintContext(getStaticConstraintContext());
090: }
091: if (isDynamicContextPresent()) {
092: inCtcot
093: .registerConstraintContext(getDynamicConstraintContext());
094: }
095: if (isCompoundContextPresent()) {
096: inCtcot
097: .registerConstraintContext(getCompoundConstraintContext());
098: }
099: //
100: inCtcot.setDefaultList(((ArrayList) getDefaultList().clone()));
101: //
102: inCtcot
103: .setPostValidatorList(((ArrayList) getPostValidatorList()
104: .clone()));
105: //
106: inCtcot.setPreValidatorList(((ArrayList) getPreValidatorList()
107: .clone()));
108: //
109: inCtcot
110: .setPreIterativeValidatorList(((ArrayList) getPreIterativeValidatorList()
111: .clone()));
112: //
113: inCtcot
114: .setPostIterativeValidatorList(((ArrayList) getPostIterativeValidatorList()
115: .clone()));
116: //
117: inCtcot.setDisplayAsBranch(isDisplayAsBranch());
118: //
119: inCtcot.setMergeAdjacentTextNodes(isMergeAdjacentTextNodes());
120: }
121:
122: public void inheritFromParent(InitializeConceptTagContext inIctc) {
123: //
124: inIctc.getParentConstraint().initializeBaseMembers(this );
125: }
126:
127: //
128: //
129: //
130: public boolean isDisplayAsBranch() {
131: return this .displayAsBranch;
132: }
133:
134: public void setDisplayAsBranch(boolean inDisplayAsBranch) {
135: this .displayAsBranch = inDisplayAsBranch;
136: }
137:
138: //
139: public boolean isMergeAdjacentTextNodes() {
140: return this .mergeAdjacentTextNodes;
141: }
142:
143: public void setMergeAdjacentTextNodes(
144: boolean inMergeAdjacentTextNodes) {
145: this .mergeAdjacentTextNodes = inMergeAdjacentTextNodes;
146: }
147:
148: //
149: //
150: //
151: //
152: //
153: public void registerPostValidator(
154: PostValidatorForConceptTagConstraint inPvfctc) {
155: //
156: this .postVfctcList.add(inPvfctc);
157: }
158:
159: public int getPostValidatorCount() {
160: return this .postVfctcList.size();
161: }
162:
163: public PostValidatorForConceptTagConstraint getPostValidator(
164: int inIndex) {
165:
166: PostValidatorForConceptTagConstraint outValue = null;
167:
168: Object o = this .postVfctcList.get(inIndex);
169: outValue = ((PostValidatorForConceptTagConstraint) o);
170:
171: return outValue;
172: }
173:
174: protected ArrayList getPostValidatorList() {
175: return this .postVfctcList;
176: }
177:
178: protected void setPostValidatorList(ArrayList inList) {
179: this .postVfctcList = inList;
180: }
181:
182: //
183: //
184: //
185: //
186: //
187: public void registerPostIterativeValidator(
188: PostIterValidatorForConceptTagConstraint inPvfctc) {
189: //
190: this .postIterVfctcList.add(inPvfctc);
191: }
192:
193: public int getPostIterativeValidatorCount() {
194: return this .postIterVfctcList.size();
195: }
196:
197: public PostIterValidatorForConceptTagConstraint getPostIterativeValidator(
198: int inIndex) {
199:
200: PostIterValidatorForConceptTagConstraint outValue = null;
201:
202: Object o = this .postIterVfctcList.get(inIndex);
203: outValue = ((PostIterValidatorForConceptTagConstraint) o);
204:
205: return outValue;
206: }
207:
208: protected ArrayList getPostIterativeValidatorList() {
209: return this .postIterVfctcList;
210: }
211:
212: protected void setPostIterativeValidatorList(ArrayList inList) {
213: this .postIterVfctcList = inList;
214: }
215:
216: //
217: //
218: //
219: //
220: //
221: public void registerPreIterativeValidator(
222: PreIterValidatorForConceptTagConstraint inPvfctc) {
223: //
224: this .preIterVfctcList.add(inPvfctc);
225: }
226:
227: public int getPreIterativeValidatorCount() {
228: return this .preIterVfctcList.size();
229: }
230:
231: public PreIterValidatorForConceptTagConstraint getPreIterativeValidator(
232: int inIndex) {
233:
234: PreIterValidatorForConceptTagConstraint outValue = null;
235:
236: Object o = this .preIterVfctcList.get(inIndex);
237: outValue = ((PreIterValidatorForConceptTagConstraint) o);
238:
239: return outValue;
240: }
241:
242: protected ArrayList getPreIterativeValidatorList() {
243: return this .preIterVfctcList;
244: }
245:
246: protected void setPreIterativeValidatorList(ArrayList inList) {
247: this .preIterVfctcList = inList;
248: }
249:
250: //
251: //
252: //
253: //
254: //
255: public void registerPreValidator(
256: PreValidatorForConceptTagConstraint inPvfctc) {
257: //
258: this .preVfctcList.add(inPvfctc);
259: }
260:
261: public int getPreValidatorCount() {
262: return this .preVfctcList.size();
263: }
264:
265: public PreValidatorForConceptTagConstraint getPreValidator(
266: int inIndex) {
267:
268: PreValidatorForConceptTagConstraint outValue = null;
269:
270: Object o = this .preVfctcList.get(inIndex);
271: outValue = ((PreValidatorForConceptTagConstraint) o);
272:
273: return outValue;
274: }
275:
276: protected ArrayList getPreValidatorList() {
277: return this .preVfctcList;
278: }
279:
280: protected void setPreValidatorList(ArrayList inList) {
281: this .preVfctcList = inList;
282: }
283:
284: //
285: public void setLengthUnbounded(boolean inLengthUnbounded) {
286: this .noMaxLength = inLengthUnbounded;
287: }
288:
289: public boolean isLengthUnbounded() {
290: return this .noMaxLength;
291: }
292:
293: //
294: public void setMinimumLength(int inMinLength) {
295: this .minLength = inMinLength;
296: }
297:
298: public int getMinimumLength() {
299: return this .minLength;
300: }
301:
302: //
303: public void setMaximumLength(int inMaxLength) {
304: setLengthUnbounded(false);
305: this .maxLength = inMaxLength;
306: }
307:
308: public int getMaximumLength() {
309: return this .maxLength;
310: }
311:
312: public String getName() {
313: return this .name;
314: }
315:
316: //
317: public boolean isStaticContextPresent() {
318: return (this .sctcc != null);
319: }
320:
321: public StaticConceptTagConstraintContext getStaticConstraintContext() {
322: StaticConceptTagConstraintContext outValue = this .sctcc;
323: if (this .sctcc == null) {
324: throw new UnexpectedSystemException("Value not available");
325: }
326: return outValue;
327: }
328:
329: public boolean isDynamicContextPresent() {
330: return (this .dctcc != null);
331: }
332:
333: public DynamicConceptTagConstraintContext getDynamicConstraintContext() {
334: DynamicConceptTagConstraintContext outValue = this .dctcc;
335: if (this .dctcc == null) {
336: throw new UnexpectedSystemException("Value not available");
337: }
338: return outValue;
339: }
340:
341: public boolean isCompoundContextPresent() {
342: return (this .cctcc != null);
343: }
344:
345: public CompoundConceptTagConstraintContext getCompoundConstraintContext() {
346: CompoundConceptTagConstraintContext outValue = this .cctcc;
347: if (this .cctcc == null) {
348: throw new UnexpectedSystemException("Value not available");
349: }
350: return outValue;
351: }
352:
353: //////////////
354: public void registerConstraintContext(
355: AbstractConceptTagConstraintContext inActcc) {
356:
357: if (inActcc instanceof CompoundConceptTagConstraintContext) {
358: CompoundConceptTagConstraintContext cctcc = (CompoundConceptTagConstraintContext) inActcc;
359: registerConstraintContext(cctcc);
360: } else if (inActcc instanceof DynamicConceptTagConstraintContext) {
361: DynamicConceptTagConstraintContext dctcc = (DynamicConceptTagConstraintContext) inActcc;
362: registerConstraintContext(dctcc);
363: } else if (inActcc instanceof StaticConceptTagConstraintContext) {
364: StaticConceptTagConstraintContext sctcc = (StaticConceptTagConstraintContext) inActcc;
365: registerConstraintContext(sctcc);
366: } else {
367: throw new UnexpectedSystemException("Unknown type");
368: }
369: }
370:
371: private void registerConstraintContext(
372: CompoundConceptTagConstraintContext inCctcc) {
373: if (inCctcc == null) {
374: throw new UnexpectedSystemException("Invalid arguement");
375: } else if (this .cctcc == null) {
376: this .cctcc = inCctcc;
377: } else {
378: throw new UnexpectedSystemException("Already registered");
379: }
380: }
381:
382: private void registerConstraintContext(
383: DynamicConceptTagConstraintContext inDctcc) {
384: if (inDctcc == null) {
385: throw new UnexpectedSystemException("Invalid arguement");
386: } else if (this .dctcc == null) {
387: this .dctcc = inDctcc;
388: } else {
389: throw new UnexpectedSystemException("Already registered");
390: }
391: }
392:
393: //private Exception sctccException = null;
394: private void registerConstraintContext(
395: StaticConceptTagConstraintContext inSctcc) {
396: if (inSctcc == null) {
397: throw new UnexpectedSystemException("Invalid arguement");
398: } else if (this .sctcc == null) {
399: //MiscHelper.println("ConTagConOrTemp remove regConCon");
400: //this.sctccException = new Exception();
401: this .sctcc = inSctcc;
402: } else {
403: //MiscHelper.println("ConTagConOrTemp regConCon");
404: //MiscHelper.writeMessage(this, this.sctccException);
405: throw new UnexpectedSystemException("Already registered");
406: }
407: }
408:
409: //
410: public void unregisterStaticConstraintContext() {
411: if (this .sctcc != null) {
412: this .sctcc = null;
413: } else {
414: throw new UnexpectedSystemException("Not registered");
415: }
416: }
417:
418: public void unregisterDynamicConstraintContext() {
419: if (this .dctcc != null) {
420: this .dctcc = null;
421: } else {
422: throw new UnexpectedSystemException("Not registered");
423: }
424: }
425:
426: public void unregisterCompoundConstraintContext() {
427: if (this .cctcc != null) {
428: this .cctcc = null;
429: } else {
430: throw new UnexpectedSystemException("Not registered");
431: }
432: }
433:
434: protected ArrayList getDefaultList() {
435: return this .defaultList;
436: }
437:
438: protected void setDefaultList(ArrayList inList) {
439: this .defaultList = inList;
440: }
441:
442: protected void addDefaultValue(Object inValue) {
443: getDefaultList().add(inValue);
444: }
445:
446: }
|