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.workflow.model.template.v1;
009:
010: //base classes
011:
012: //project specific classes
013: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
014: import org.jfolder.common.tagging.ConceptTagCharacteristic;
015: import org.jfolder.common.tagging.ConceptTagCharacteristicHolder;
016: import org.jfolder.common.tagging.ConceptTagConstraint;
017: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
018: import org.jfolder.common.tagging.ConceptTagConstraintTemplate;
019: import org.jfolder.common.tagging.CoreConceptTag;
020: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
021: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
022: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
023: import org.jfolder.common.tagging.DynamicConceptTagValidator;
024: import org.jfolder.common.tagging.InitializeConceptTagContext;
025: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
026: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
027:
028: //other classes
029:
030: abstract class NodeWorkflowTemplateTag implements CoreConceptTag {
031:
032: //characteristics
033: private ConceptTagCharacteristic ifTransitionCtchar = null;
034: private ConceptTagCharacteristic transitionCtchar = null;
035: private ConceptTagCharacteristic branchCtchar = null;
036:
037: //ifTransition details
038: private final static String IF_TRANSITION_CTCON = "if-transition";
039: private final static String IF_TRANSITION_TITLE = "If Transitions";
040: private final static String IF_TRANSITION_SHORT_DESCRIPTION = "Transition to take if condition is true";
041:
042: //ifTransition condition template
043: private final static String IF_TRANSITION_CTCON_CONDITION_CTCTEMP = "condition";
044: private final static String IF_TRANSITION_CTCON_CONDITION_TITLE = "Condition";
045: private final static String IF_TRANSITION_CTCON_CONDITION_SHORT_DESCRIPTION = "This path will be taken only if this condition evaluates to true";
046:
047: //ifTransition transition template
048: private final static String IF_TRANSITION_CTCON_TRANSITION_CTCTEMP = "transition";
049: private final static String IF_TRANSITION_CTCON_TRANSITION_TITLE = "Transition";
050: private final static String IF_TRANSITION_CTCON_TRANSITION_SHORT_DESCRIPTION = "This path to be taken";
051:
052: //transition details
053: private final static String TRANSITION_CTCON = "transition";
054: private final static String TRANSITION_TITLE = "Default Transition";
055: private final static String TRANSITION_SHORT_DESCRIPTION = "Transition to take if none of the if transition conditions"
056: + " evaluate to true";
057:
058: //branch detail
059: private final static String BRANCH_CTCON = "branch";
060: private final static String BRANCH_TITLE = "Branch";
061: private final static String BRANCH_SHORT_DESCRIPTION = "Simultaneous path to take";
062:
063: //branch ifTransition template
064: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP = "if-transition";
065: private final static String BRANCH_CTCON_IF_TRANSITION_TITLE = "If Transitions";
066: private final static String BRANCH_CTCON_IF_TRANSITION_SHORT_DESCRIPTION = "Transition to take if condition is true";
067: //branch ifTransition template condition template
068: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_CTCTEMP = "condition";
069: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_TITLE = "Condition";
070: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_SHORT_DESCRIPTION = "This path will be taken only if this condition evaluates to true";
071: //branch ifTransition template transition template
072: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_CTCTEMP = "transition";
073: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_TITLE = "Transition";
074: private final static String BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_SHORT_DESCRIPTION = "This path to be taken";
075: //branch transition template
076: private final static String BRANCH_CTCON_TRANSITION_CTCTEMP = "transition";
077: private final static String BRANCH_CTCON_TRANSITION_TITLE = "Default Transition";
078: private final static String BRANCH_CTCON_TRANSITION_SHORT_DESCRIPTION = "Transition to take if none of the if transition conditions"
079: + " evaluate to true";
080:
081: //TO DO: look into duplicate TC names!
082:
083: public void initializeBase(InitializeConceptTagContext inIctc) {
084:
085: //
086: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
087: .newInstance(inIctc);
088:
089: //constrain "if-transition"
090: ConceptTagConstraint ifTransitionCtcon = ConceptTagConstraint
091: .newInstance(IF_TRANSITION_CTCON, rootCtconh);
092: ifTransitionCtcon.setTitle(IF_TRANSITION_TITLE);
093: ifTransitionCtcon
094: .setShortDescription(IF_TRANSITION_SHORT_DESCRIPTION);
095: ifTransitionCtcon.setMinimumLength(0);
096: ifTransitionCtcon.setLengthUnbounded(true);
097: //
098: CompoundConceptTagConstraintContext ifTransitionCctcc = CompoundConceptTagConstraintContext
099: .newInstance(ifTransitionCtcon);
100: //
101: //constrain "condition" of "if-transition"
102: ConceptTagConstraintTemplate ifTransitionCtconConditionCtctemp = ConceptTagConstraintTemplate
103: .newInstance(IF_TRANSITION_CTCON_CONDITION_CTCTEMP,
104: ifTransitionCctcc);
105: ifTransitionCtconConditionCtctemp
106: .setTitle(IF_TRANSITION_CTCON_CONDITION_TITLE);
107: ifTransitionCtconConditionCtctemp
108: .setShortDescription(IF_TRANSITION_CTCON_CONDITION_SHORT_DESCRIPTION);
109: //TO DO: validate static text
110: DynamicConceptTagConstraintContext ifTransitionCtconConditionDctcc = DynamicConceptTagConstraintContext
111: .newInstance(ifTransitionCtconConditionCtctemp);
112: DynamicConceptTagValidator ifTransitionCtconConditionDctccVal = ifTransitionCtconConditionDctcc
113: .getValidator();
114: ifTransitionCtconConditionDctccVal.allowReturnOfOnlyBoolean();
115: //
116: //constrain "transition" of "if-transition"
117: ConceptTagConstraintTemplate ifTransitionCtconTransitionCtctemp = ConceptTagConstraintTemplate
118: .newInstance(IF_TRANSITION_CTCON_TRANSITION_CTCTEMP,
119: ifTransitionCctcc);
120: ifTransitionCtconTransitionCtctemp
121: .setTitle(IF_TRANSITION_CTCON_TRANSITION_TITLE);
122: ifTransitionCtconTransitionCtctemp
123: .setShortDescription(IF_TRANSITION_CTCON_TRANSITION_SHORT_DESCRIPTION);
124: //
125: StaticConceptTagConstraintContext ifTransitionCtconTransitionSctcc = StaticConceptTagConstraintContext
126: .newInstance(ifTransitionCtconTransitionCtctemp);
127: //
128: ifTransitionCtconTransitionSctcc.addDefaultValue("State");
129: //((InitializeConceptTagContextBean)inItc).registerTransitions(stct1);
130: //TO DO: validate static text
131:
132: //constrain "transition"
133: ConceptTagConstraint transitionCtcon = ConceptTagConstraint
134: .newInstance(TRANSITION_CTCON, rootCtconh);
135: transitionCtcon.setTitle(TRANSITION_TITLE);
136: transitionCtcon
137: .setShortDescription(TRANSITION_SHORT_DESCRIPTION);
138: //
139: StaticConceptTagConstraintContext transitionSctcc = StaticConceptTagConstraintContext
140: .newInstance(transitionCtcon);
141: transitionSctcc.addDefaultValue("State");
142: //((InitializeConceptTagContextBean)inItc).registerTransitions(
143: // this.transitionTc);
144: //TO DO: validate static text
145:
146: ////////////////////////////////////////////////////////////////
147:
148: //constrain "branch"
149: ConceptTagConstraint branchCtcon = ConceptTagConstraint
150: .newInstance(BRANCH_CTCON, rootCtconh);
151: branchCtcon.setTitle(BRANCH_TITLE);
152: branchCtcon.setShortDescription(BRANCH_SHORT_DESCRIPTION);
153: branchCtcon.setMinimumLength(0);
154: branchCtcon.setLengthUnbounded(true);
155: //
156: CompoundConceptTagConstraintContext branchCctcc = CompoundConceptTagConstraintContext
157: .newInstance(branchCtcon);
158: //
159: //constrain "if-transition" of "branch"
160: ConceptTagConstraintTemplate branchCtconIfTransitionCtctemp = ConceptTagConstraintTemplate
161: .newInstance(BRANCH_CTCON_IF_TRANSITION_CTCTEMP,
162: branchCctcc);
163: branchCtconIfTransitionCtctemp
164: .setTitle(BRANCH_CTCON_IF_TRANSITION_TITLE);
165: branchCtconIfTransitionCtctemp
166: .setShortDescription(BRANCH_CTCON_IF_TRANSITION_SHORT_DESCRIPTION);
167: branchCtconIfTransitionCtctemp.setMinimumLength(0);
168: branchCtconIfTransitionCtctemp.setLengthUnbounded(true);
169: //
170: CompoundConceptTagConstraintContext branchCtconIfTransitionCctcc = CompoundConceptTagConstraintContext
171: .newInstance(branchCtconIfTransitionCtctemp);
172: //constrain "condition" of "if-transition" of "branch"
173: ConceptTagConstraintTemplate branchCtconIfTransitionCtctempConditionCtctemp = ConceptTagConstraintTemplate
174: .newInstance(
175: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_CTCTEMP,
176: branchCtconIfTransitionCctcc);
177: branchCtconIfTransitionCtctempConditionCtctemp
178: .setTitle(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_TITLE);
179: branchCtconIfTransitionCtctempConditionCtctemp
180: .setShortDescription(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_SHORT_DESCRIPTION);
181: //
182: DynamicConceptTagConstraintContext branchCtconIfTransitionCtctempConditionDctcc = DynamicConceptTagConstraintContext
183: .newInstance(branchCtconIfTransitionCtctempConditionCtctemp);
184: //
185: //constrain "transition" of "if-transition" of "branch"
186: ConceptTagConstraintTemplate branchCtconIfTransitionCtctempTransitionCtctemp = ConceptTagConstraintTemplate
187: .newInstance(
188: BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_CTCTEMP,
189: branchCtconIfTransitionCctcc);
190: branchCtconIfTransitionCtctempTransitionCtctemp
191: .setTitle(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_TITLE);
192: branchCtconIfTransitionCtctempTransitionCtctemp
193: .setShortDescription(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_SHORT_DESCRIPTION);
194: //((InitializeConceptTagContextBean)inItc).registerTransitions(stct2);
195: //
196: StaticConceptTagConstraintContext branchCtconIfTransitionCtctempTransitionSctcc = StaticConceptTagConstraintContext
197: .newInstance(branchCtconIfTransitionCtctempTransitionCtctemp);
198: //
199:
200: ConceptTagConstraintTemplate branchCtconTransitionCtctemp = ConceptTagConstraintTemplate
201: .newInstance(BRANCH_CTCON_TRANSITION_CTCTEMP,
202: branchCctcc);
203: branchCtconTransitionCtctemp
204: .setTitle(BRANCH_CTCON_TRANSITION_TITLE);
205: branchCtconTransitionCtctemp
206: .setShortDescription(BRANCH_CTCON_TRANSITION_SHORT_DESCRIPTION);
207: //
208: StaticConceptTagConstraintContext branchCtconTransitionSctcc = StaticConceptTagConstraintContext
209: .newInstance(branchCtconTransitionCtctemp);
210: //((InitializeConceptTagContextBean)inItc).registerTransitions(stct3);
211:
212: inIctc.initialize();
213:
214: //initialize characteristics
215: this .ifTransitionCtchar = ifTransitionCtcon.getCharacteristic();
216: this .transitionCtchar = transitionCtcon.getCharacteristic();
217: this .branchCtchar = branchCtcon.getCharacteristic();
218: }
219:
220: public String evaluateTransition(
221: DetermineValueAndClassConceptTagContext inRvacc)
222: throws DetermineValueAndClassConceptTagException {
223:
224: String outValue = null;
225:
226: for (int i = 0; i < this .ifTransitionCtchar.getValueLength(); i++) {
227:
228: ConceptTagCharacteristicHolder nextCh = this .ifTransitionCtchar
229: .getValueAsHolder(i, inRvacc);
230:
231: ConceptTagCharacteristic conditionTc = nextCh
232: .getCharacteristic(IF_TRANSITION_CTCON_CONDITION_CTCTEMP);
233:
234: ValueAndClassForConceptTag conditionVac = conditionTc
235: .getDetermineValueAndClass(0, inRvacc);
236:
237: Boolean bValue = (Boolean) conditionVac.getValue();
238:
239: if (bValue.booleanValue()) {
240:
241: ConceptTagCharacteristic transitionNameTc = nextCh
242: .getCharacteristic(this .IF_TRANSITION_CTCON_TRANSITION_CTCTEMP);
243: outValue = transitionNameTc
244: .getValueAsString(0, inRvacc);
245:
246: break;
247: }
248: }
249:
250: if (outValue == null) {
251: outValue = this .transitionCtchar.getValueAsString(0,
252: inRvacc);
253: }
254:
255: return outValue;
256: }
257:
258: public int getIfTransitionCount() {
259: return this .ifTransitionCtchar.getValueLength();
260: }
261:
262: public String getIfTransitionDestination(int inIndex) {
263:
264: ConceptTagCharacteristic outValue = null;
265:
266: ConceptTagCharacteristicHolder nextCh = this .ifTransitionCtchar
267: .getValueAsHolder(inIndex, null);
268: outValue = nextCh
269: .getCharacteristic(this .IF_TRANSITION_CTCON_TRANSITION_CTCTEMP);
270:
271: return outValue.getValueAsString(0, null);
272: }
273:
274: public String getTransitionDestination() {
275: return this .transitionCtchar.getValueAsString(0, null);
276: }
277:
278: public int getBranchIfTransitionCount(int inBranch) {
279:
280: ConceptTagCharacteristic outValue = null;
281:
282: ConceptTagCharacteristicHolder topCh = this .branchCtchar
283: .getValueAsHolder(inBranch, null);
284: outValue = topCh
285: .getCharacteristic(this .BRANCH_CTCON_IF_TRANSITION_CTCTEMP);
286:
287: return outValue.getValueLength();
288: }
289:
290: public String getBranchIfTransitionDestination(int inBranch,
291: int inIndex) {
292:
293: ConceptTagCharacteristic outValue = null;
294:
295: ConceptTagCharacteristicHolder topCh = this .branchCtchar
296: .getValueAsHolder(inBranch, null);
297:
298: ConceptTagCharacteristic topIfTransitionTc = topCh
299: .getCharacteristic(this .BRANCH_CTCON_IF_TRANSITION_CTCTEMP);
300: ConceptTagCharacteristicHolder nextCh = topIfTransitionTc
301: .getValueAsHolder(inIndex, null);
302: outValue = nextCh
303: .getCharacteristic(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_CTCTEMP);
304:
305: return outValue.getValueAsString(0, null);
306: }
307:
308: public String getBranchTransitionDestination(int inBranch) {
309:
310: ConceptTagCharacteristic outValue = null;
311:
312: ConceptTagCharacteristicHolder topCh = this .branchCtchar
313: .getValueAsHolder(inBranch, null);
314: outValue = topCh
315: .getCharacteristic(BRANCH_CTCON_TRANSITION_CTCTEMP);
316:
317: return outValue.getValueAsString(0, null);
318: }
319:
320: public int getBranchCount() {
321: return this .branchCtchar.getValueLength();
322: }
323:
324: public String evaluateBranch(int inIndex,
325: DetermineValueAndClassConceptTagContext inRvacc)
326: throws DetermineValueAndClassConceptTagException {
327:
328: String outValue = null;
329:
330: ConceptTagCharacteristicHolder topCh = this .branchCtchar
331: .getValueAsHolder(inIndex, inRvacc);
332:
333: ConceptTagCharacteristic topIfTransitionTc = topCh
334: .getCharacteristic(this .BRANCH_CTCON_IF_TRANSITION_CTCTEMP);
335:
336: for (int i = 0; i < topIfTransitionTc.getValueLength(); i++) {
337:
338: ConceptTagCharacteristicHolder nextCh = topIfTransitionTc
339: .getValueAsHolder(i, inRvacc);
340:
341: ConceptTagCharacteristic conditionTc = nextCh
342: .getCharacteristic(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_CONDITION_CTCTEMP);
343:
344: ValueAndClassForConceptTag conditionVac = conditionTc
345: .getDetermineValueAndClass(0, inRvacc);
346:
347: Boolean bValue = (Boolean) conditionVac.getValue();
348:
349: if (bValue.booleanValue()) {
350:
351: ConceptTagCharacteristic transitionNameTc = nextCh
352: .getCharacteristic(BRANCH_CTCON_IF_TRANSITION_CTCTEMP_TRANSITION_CTCTEMP);
353: outValue = transitionNameTc
354: .getValueAsString(0, inRvacc);
355:
356: break;
357: }
358: }
359:
360: if (outValue == null) {
361:
362: ConceptTagCharacteristic topTransitionTc = topCh
363: .getCharacteristic(BRANCH_CTCON_TRANSITION_CTCTEMP);
364:
365: outValue = topTransitionTc.getValueAsString(0, inRvacc);
366: }
367: return outValue;
368: }
369:
370: }
|