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.AppraiseConceptTagContext;
014: import org.jfolder.common.tagging.CompoundConceptTagConstraintContext;
015: import org.jfolder.common.tagging.ConceptTagCharacteristic;
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.InitializeConceptTagContext;
024: import org.jfolder.common.tagging.ReturnableConceptTag;
025: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
026: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
027: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
028: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
029: import org.jfolder.common.utils.misc.CommonExpressions;
030:
031: //other classes
032:
033: public class StateWorkflowTemplateTag extends NodeWorkflowTemplateTag {
034:
035: //characteristic
036: private ConceptTagCharacteristic nameCtchar = null;
037: private ConceptTagCharacteristic xCordCtchar = null;
038: private ConceptTagCharacteristic yCordCtchar = null;
039: private ConceptTagCharacteristic waitCtchar = null;
040: private ConceptTagCharacteristic actionCtchar = null;
041:
042: //name details
043: private final static String NAME_CTCON = "name";
044: private final static String NAME_TITLE = "Name";
045: private final static String NAME_SHORT_DESCRIPTION = "Name of this start";
046:
047: //xCord details
048: private final static String X_CORD_CTCON = "x-cord";
049: private final static String X_CORD_TITLE = "X Coordinate";
050: private final static String X_CORD_SHORT_DESCRIPTION = "Distance (in pixels) from the left side"
051: + " of the workflow-template graph";
052:
053: //yCord details
054: private final static String Y_CORD_CTCON = "y-cord";
055: private final static String Y_CORD_TITLE = "Y Coordinate";
056: private final static String Y_CORD_SHORT_DESCRIPTION = "Distance (in pixels) from the top side"
057: + " of the workflow-template graph";
058:
059: //wait details
060: private final static String WAIT_CTCON = "wait";
061: private final static String WAIT_TITLE = "Wait";
062: private final static String WAIT_SHORT_DESCRIPTION = "Do not execute 'Action' section until released";
063:
064: //wait action template
065: private final static String WAIT_CTCON_ACTION_CTCTEMP = "action";
066: private final static String WAIT_CTCON_ACTION_TITLE = "Action";
067: private final static String WAIT_CTCON_ACTION_SHORT_DESCRIPTION = "Actions to perform before waiting";
068:
069: //action details
070: private final static String ACTION_CTCON = "action";
071: private final static String ACTION_TITLE = "Action";
072: private final static String ACTION_SHORT_DESCRIPTION = "Actions to perform while at this state";
073:
074: public void initialize(InitializeConceptTagContext inIctc) {
075:
076: //
077: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
078: .newInstance(inIctc);
079:
080: //constrain "name"
081: ConceptTagConstraint nameCtcon = ConceptTagConstraint
082: .newInstance(NAME_CTCON, rootCtconh);
083: nameCtcon.setTitle(NAME_TITLE);
084: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
085: //
086: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
087: .newInstance(nameCtcon);
088: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
089: //
090: nameSctcc.addDefaultValue("State");
091: //
092: //((InitializeConceptTagContextBean)inItc).registerState(this.nameTc);
093:
094: //constrain "x-cord"
095: ConceptTagConstraint xCordCtcon = ConceptTagConstraint
096: .newInstance(X_CORD_CTCON, rootCtconh);
097: xCordCtcon.setTitle(X_CORD_TITLE);
098: xCordCtcon.setShortDescription(X_CORD_SHORT_DESCRIPTION);
099: //stc2.setDefaultValueAsString(ConceptTagHelper.RESET);
100: //
101: StaticConceptTagConstraintContext xCordSctcc = StaticConceptTagConstraintContext
102: .newInstance(xCordCtcon);
103: xCordSctcc
104: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
105: //
106: xCordSctcc.addDefaultValue("0");
107: //((InitializeConceptTagContextBean)inItc).registerXCord(this.xCordTc);
108: //TO DO: dynamically determine value
109:
110: //constrain "y-cord"
111: ConceptTagConstraint yCordCtcon = ConceptTagConstraint
112: .newInstance(Y_CORD_CTCON, rootCtconh);
113: yCordCtcon.setTitle(Y_CORD_TITLE);
114: yCordCtcon.setShortDescription(Y_CORD_SHORT_DESCRIPTION);
115: //stc3.setDefaultValueAsString(ConceptTagHelper.RESET);
116: //
117: StaticConceptTagConstraintContext yCordSctcc = StaticConceptTagConstraintContext
118: .newInstance(yCordCtcon);
119: yCordSctcc
120: .setRegularExpression(CommonExpressions.POSITIVE_INTEGER);
121: //
122: yCordSctcc.addDefaultValue("0");
123: //((InitializeConceptTagContextBean)inItc).registerYCord(this.yCordTc);
124: //TO DO: dynamically determine value
125:
126: //constrain "wait"
127: ConceptTagConstraint waitCtcon = ConceptTagConstraint
128: .newInstance(WAIT_CTCON, rootCtconh);
129: waitCtcon.setTitle(this .WAIT_TITLE);
130: waitCtcon.setShortDescription(this .WAIT_SHORT_DESCRIPTION);
131: waitCtcon.setMinimumLength(0);
132: waitCtcon.setMaximumLength(1);
133: //
134: CompoundConceptTagConstraintContext waitCctcc = CompoundConceptTagConstraintContext
135: .newInstance(waitCtcon);
136: //
137: //constrain "action" of "wait"
138: ConceptTagConstraintTemplate waitCtconActionCtctemp = ConceptTagConstraintTemplate
139: .newInstance(WAIT_CTCON_ACTION_CTCTEMP, waitCctcc);
140: waitCtconActionCtctemp.setTitle(WAIT_CTCON_ACTION_TITLE);
141: waitCtconActionCtctemp
142: .setShortDescription(WAIT_CTCON_ACTION_SHORT_DESCRIPTION);
143: waitCtconActionCtctemp.setMinimumLength(0);
144: waitCtconActionCtctemp.setLengthUnbounded(true);
145: //
146: DynamicConceptTagConstraintContext waitCtconActionDctcc = DynamicConceptTagConstraintContext
147: .newInstance(waitCtconActionCtctemp);
148: waitCtconActionDctcc.getValidator().allowReturnableOnly();
149: //
150: //waitCtconActionDctcc.addDefaultValue(
151: // PrintToConsoleWorkflowTemplateTag.class);
152:
153: //constrain "action"
154: ConceptTagConstraint actionCtcon = ConceptTagConstraint
155: .newInstance(ACTION_CTCON, rootCtconh);
156: actionCtcon.setTitle(ACTION_TITLE);
157: actionCtcon.setShortDescription(ACTION_SHORT_DESCRIPTION);
158: actionCtcon.setMinimumLength(0);
159: actionCtcon.setLengthUnbounded(true);
160: //
161: DynamicConceptTagConstraintContext actionDctcc = DynamicConceptTagConstraintContext
162: .newInstance(actionCtcon);
163: //msodtc.setClassRestrictions(ReturnableTag.class);
164: //Class rcr[] = new Class[2];
165: //rcr[0] = Object.class;
166: //rcr[1] = Void.TYPE;
167: actionDctcc.getValidator().allowReturnOfAnythingExceptNothing();
168: //
169: //actionDctcc.addDefaultValue(PrintToConsoleWorkflowTemplateTag.class);
170: //msodtc.setReturnClassExclusions(Void.TYPE);
171:
172: super .initializeBase(inIctc);
173: //MiscHelper.println("this.isPreWaitPresent() = "
174: // + this.isPreWaitPresent());
175:
176: //initialize characteristics
177: this .nameCtchar = nameCtcon.getCharacteristic();
178: this .xCordCtchar = xCordCtcon.getCharacteristic();
179: this .yCordCtchar = yCordCtcon.getCharacteristic();
180: this .waitCtchar = waitCtcon.getCharacteristic();
181: this .actionCtchar = actionCtcon.getCharacteristic();
182: }
183:
184: public void appraise(AppraiseConceptTagContext inCtic) {
185: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
186: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
187: sctiic.setInstanceTitle(this .nameCtchar.getValueAsString(0,
188: inCtic));
189: sctiic
190: .setInstanceDescription("Potential intermediary node in a workflow-instance's life");
191: sctiic.setLocalInstanceIcon("state");
192: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
193: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
194: scttic.setTypeTitle("State");
195: scttic
196: .setTypeDescription("Potential intermediary node in a workflow-instance's life");
197: }
198: }
199:
200: public String getName() {
201: return this .nameCtchar.getValueAsString(0, null);
202: }
203:
204: public boolean isPreWaitPresent() {
205: return (this .waitCtchar.getValueLength() > 0);
206: }
207:
208: public void execute(DetermineValueAndClassConceptTagContext inRvacc)
209: throws DetermineValueAndClassConceptTagException {
210: for (int i = 0; i < this .actionCtchar.getValueLength(); i++) {
211: this .actionCtchar.getDetermineValueAndClass(i, inRvacc);
212: }
213: }
214:
215: public boolean isXCordValid() {
216: return isCordValid(this .xCordCtchar);
217: }
218:
219: public boolean isYCordValid() {
220: return isCordValid(this .yCordCtchar);
221: }
222:
223: private boolean isCordValid(ConceptTagCharacteristic inCtchar) {
224:
225: boolean outValue = false;
226:
227: try {
228: if (inCtchar.getValueLength() > 0
229: && inCtchar.isStatic(0, null)) {
230: int value = Integer.parseInt(inCtchar.getValueAsString(
231: 0, null));
232: outValue = (value > 1);
233: }
234: } catch (NumberFormatException nfe) {
235: //do nothing, return false;
236: }
237:
238: return outValue;
239: }
240:
241: public int getXCord() {
242: return Integer.parseInt(this .xCordCtchar.getValueAsString(0,
243: null));
244: }
245:
246: public int getYCord() {
247: return Integer.parseInt(this .yCordCtchar.getValueAsString(0,
248: null));
249: }
250:
251: public void setXCord(String inCord) {
252: this .xCordCtchar.addValue(0, inCord);
253: }
254:
255: public void setYCord(String inCord) {
256: this .yCordCtchar.addValue(0, inCord);
257: }
258: /*
259: public void getTagSummary(TagSummaryDescriptor tsd) {
260: //TO DO: placeholder, put meaningful description
261: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
262: tsd.appendData("<table width=\"100%\">");
263: tsd.appendData("<tr>");
264: tsd.appendData(
265: "<td width=\"30%\" style=\"font-size: 16;
266: // font-family: Arial; color: #000000;\">");
267: tsd.appendData(this.nameAttr[0]);
268: tsd.appendData("</td>");
269: tsd.appendData(
270: "<td width=\"20%\" style=\"font-size: 16;
271: // font-family: Arial; color: #000000;\">");
272: tsd.appendData("X = " + this.xCordAttr[0]);
273: tsd.appendData("</td>");
274: tsd.appendData(
275: "<td width=\"50%\" style=\"font-size: 16;
276: // font-family: Arial; color: #000000;\">");
277: tsd.appendData("Y = " + this.yCordAttr[0]);
278: tsd.appendData("</td>");
279: tsd.appendData("</tr>");
280:
281: //wait
282: if (this.waitTags.size() > 0) {
283: tsd.appendData("<tr >");
284: tsd.appendData("<td width=\"30%\">");
285: tsd.appendData("</td>");
286: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
287: tsd.appendData("<hr/>");
288: tsd.appendData("</td>");
289: tsd.appendData("</tr>");
290:
291: tsd.appendData("<tr>");
292: tsd.appendData("<td width=\"30%\">");
293: tsd.appendData("</td>");
294: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
295: ((Tag)(this.waitTags.get(0))).getTagSummary(tsd);
296: tsd.appendData("</td>");
297: tsd.appendData("</tr>");
298: }
299:
300: //executes
301: if (this.executeTags.size() > 0) {
302: tsd.appendData("<tr >");
303: tsd.appendData("<td width=\"30%\">");
304: tsd.appendData("</td>");
305: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
306: tsd.appendData("<hr/>");
307: tsd.appendData("</td>");
308: tsd.appendData("</tr>");
309:
310: for (int i = 0; i < this.executeTags.size(); i++) {
311: tsd.appendData("<tr>");
312: tsd.appendData("<td width=\"30%\">");
313: tsd.appendData("</td>");
314: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
315: ((Tag)(this.executeTags.get(i))).getTagSummary(tsd);
316: tsd.appendData("</td>");
317: tsd.appendData("</tr>");
318: }
319: }
320:
321: //if transitions
322: if (this.ifTransitionTags.size() > 0
323: || this.transitionTags.size() > 0) {
324: tsd.appendData("<tr >");
325: tsd.appendData("<td width=\"30%\">");
326: tsd.appendData("</td>");
327: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
328: tsd.appendData("<hr/>");
329: tsd.appendData("</td>");
330: tsd.appendData("</tr>");
331:
332: if (this.ifTransitionTags.size() > 0) {
333: for (int i = 0; i < this.ifTransitionTags.size(); i++) {
334: tsd.appendData("<tr>");
335: tsd.appendData("<td width=\"30%\">");
336: tsd.appendData("</td>");
337: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
338: ((Tag)(this.ifTransitionTags.get(i))
339: ).getTagSummary(tsd);
340: tsd.appendData("</td>");
341: tsd.appendData("</tr>");
342: }
343: }
344:
345: //transition
346: if (this.transitionTags.size() > 0) {
347: tsd.appendData("<tr>");
348: tsd.appendData("<td width=\"30%\">");
349: tsd.appendData("</td>");
350: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
351: ((Tag)(this.transitionTags.get(0))).getTagSummary(tsd);
352: tsd.appendData("</td>");
353: tsd.appendData("</tr>");
354: }
355: }
356:
357: //branches
358: if (this.branchTags.size() > 0) {
359: for (int i = 0; i < this.branchTags.size(); i++) {
360: tsd.appendData("<tr >");
361: tsd.appendData("<td width=\"30%\">");
362: tsd.appendData("</td>");
363: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
364: tsd.appendData("<hr/>");
365: tsd.appendData("</td>");
366: tsd.appendData("</tr>");
367:
368: tsd.appendData("<tr>");
369: tsd.appendData("<td width=\"30%\">");
370: tsd.appendData("</td>");
371: tsd.appendData("<td width=\"70%\" colspan=\"2\">");
372: ((Tag)(this.branchTags.get(i))).getTagSummary(tsd);
373: tsd.appendData("</td>");
374: tsd.appendData("</tr>");
375: }
376: }
377:
378: tsd.appendData("</table>");
379: }
380: }
381:
382: */
383: }
|