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.ConceptTagCharacteristic;
015: import org.jfolder.common.tagging.ConceptTagConstraint;
016: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
017: import org.jfolder.common.tagging.ConceptTagHelper;
018: import org.jfolder.common.tagging.CoreConceptTag;
019: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
020: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
021: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
022: import org.jfolder.common.tagging.InitializeConceptTagContext;
023: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
024: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
025: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
026: import org.jfolder.workflow.model.attributes.AttributeSet;
027:
028: //other classes
029:
030: public class RootV1WorkflowTemplateTag implements CoreConceptTag {
031:
032: //tag characteristics
033: //private ConceptTagCharacteristic nameCtchar = null;
034: //private ConceptTagCharacteristic versionCtchar = null;
035: private ConceptTagCharacteristic attributesCtchar = null;
036: private ConceptTagCharacteristic startsCtchar = null;
037: private ConceptTagCharacteristic statesCtchar = null;
038: private ConceptTagCharacteristic stopsCtchar = null;
039:
040: //name details
041: //private final static String NAME_CTCON = "name";
042: //private final static String NAME_TITLE = "Workflow Template Name";
043: //private final static String NAME_SHORT_DESCRIPTION =
044: // "This contains the entire workflow-template";
045:
046: //version details
047: //private final static String VERSION_CTCON = "version";
048: //private final static String VERSION_TITLE = "Version";
049: //private final static String VERSION_SHORT_DESCRIPTION =
050: // "Number representing the version of this workflow-template";
051:
052: //attribute details
053: private final static String ATTRIBUTES_CTCON = "attribute-set";
054: private final static String ATTRIBUTES_TITLE = "Attributes";
055: private final static String ATTRIBUTES_SHORT_DESCRIPTION = "Variables assigned to the workflow";
056:
057: //starts details
058: private final static String STARTS_CTCON = "starts";
059: private final static String STARTS_TITLE = "Start Nodes";
060: private final static String STARTS_SHORT_DESCRIPTION = "Potential starting points for a workflow-template";
061:
062: //states details
063: private final static String STATES_CTCON = "states";
064: private final static String STATES_TITLE = "State Nodes";
065: private final static String STATES_SHORT_DESCRIPTION = "Intermediary points of the workflow-template";
066:
067: //stops details
068: private final static String STOPS_CTCON = "stops";
069: private final static String STOPS_TITLE = "Stop Nodes";
070: private final static String STOPS_SHORT_DESCRIPTION = "End points of the workflow-template";
071:
072: public void initialize(InitializeConceptTagContext inIctc) {
073:
074: //
075: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
076: .newInstance(inIctc);
077:
078: ////constrain name
079: //StaticTagConstraint stc1 = StaticTagConstraint.newInstance(
080: // this.NAME_TC, this.nameTc, ti);
081: //stc1.setTitle(this.NAME_TITLE);
082: //stc1.setShortDescription(this.NAME_SHORT_DESCRIPTION);
083: //stc1.setDefaultValueAsString("Application1");
084: ////TO DO: set name equal to application name
085: ////stc1.setReadOnly(true);//TO DO: implement this
086: ////stc1.setRegEx();//TO DO: implement this
087:
088: ////constrain version
089: //StaticTagConstraint stc2 = StaticTagConstraint.newInstance(
090: // this.VERSION_TC, this.versionTc, ti);
091: //stc2.setTitle(this.VERSION_TITLE);
092: //stc2.setShortDescription(this.VERSION_SHORT_DESCRIPTION);
093: //stc2.setDefaultValueAsString("1");
094: ////stc2.setReadOnly(true);//TO DO: implement this
095: ////stc2.setRegEx();//TO DO: implement this
096:
097: //constrain attributes
098: ConceptTagConstraint attributesCtcon = ConceptTagConstraint
099: .newInstance(ATTRIBUTES_CTCON, rootCtconh);
100: attributesCtcon.setTitle(ATTRIBUTES_TITLE);
101: attributesCtcon
102: .setShortDescription(ATTRIBUTES_SHORT_DESCRIPTION);
103: attributesCtcon.setMinimumLength(0);
104: attributesCtcon.setLengthUnbounded(true);
105: //
106: DynamicConceptTagConstraintContext attributesDctcc = DynamicConceptTagConstraintContext
107: .newInstance(attributesCtcon);
108: attributesDctcc.getValidator().allowOnlyTheseClasses(
109: AttributeWorkflowTemplateTag.class,
110: "Attribute must be here");
111: //
112: attributesDctcc
113: .addDefaultValue(AttributeWorkflowTemplateTag.class);
114:
115: //constrain starts
116: ConceptTagConstraint startsCtcon = ConceptTagConstraint
117: .newInstance(STARTS_CTCON, rootCtconh);
118: startsCtcon.setTitle(STARTS_TITLE);
119: startsCtcon.setShortDescription(STARTS_SHORT_DESCRIPTION);
120: startsCtcon.setMinimumLength(1);
121: startsCtcon.setLengthUnbounded(true);
122: //
123: DynamicConceptTagConstraintContext startsDctcc = DynamicConceptTagConstraintContext
124: .newInstance(startsCtcon);
125: startsDctcc.getValidator().allowOnlyTheseClasses(
126: StartWorkflowTemplateTag.class, "Start must be here");
127: //
128: startsDctcc.addDefaultValue(StartWorkflowTemplateTag.class);
129:
130: //constrain states
131: ConceptTagConstraint statesCtcon = ConceptTagConstraint
132: .newInstance(STATES_CTCON, rootCtconh);
133: statesCtcon.setTitle(STATES_TITLE);
134: statesCtcon.setShortDescription(STATES_SHORT_DESCRIPTION);
135: statesCtcon.setMinimumLength(1);
136: statesCtcon.setLengthUnbounded(true);
137: //
138: DynamicConceptTagConstraintContext statesDctcc = DynamicConceptTagConstraintContext
139: .newInstance(statesCtcon);
140: statesDctcc.getValidator().allowOnlyTheseClasses(
141: StateWorkflowTemplateTag.class, "State must be here");
142: //
143: statesDctcc.addDefaultValue(StateWorkflowTemplateTag.class);
144:
145: //constrain stops
146: ConceptTagConstraint stopsCtcon = ConceptTagConstraint
147: .newInstance(STOPS_CTCON, rootCtconh);
148: stopsCtcon.setTitle(this .STOPS_TITLE);
149: stopsCtcon.setShortDescription(this .STOPS_SHORT_DESCRIPTION);
150: stopsCtcon.setMinimumLength(1);
151: stopsCtcon.setLengthUnbounded(true);
152: //
153: DynamicConceptTagConstraintContext stopsDctcc = DynamicConceptTagConstraintContext
154: .newInstance(stopsCtcon);
155: stopsDctcc.getValidator().allowOnlyTheseClasses(
156: StopWorkflowTemplateTag.class, "Stop must be here");
157: //
158: stopsDctcc.addDefaultValue(StopWorkflowTemplateTag.class);
159:
160: inIctc.initialize();
161:
162: //initialize characteristics
163: //this.nameTc = TagCharacteristicFactory.newInstance();
164: //this.versionTc = TagCharacteristicFactory.newInstance();
165: this .attributesCtchar = attributesCtcon.getCharacteristic();
166: this .startsCtchar = startsCtcon.getCharacteristic();
167: this .statesCtchar = statesCtcon.getCharacteristic();
168: this .stopsCtchar = stopsCtcon.getCharacteristic();
169:
170: }
171:
172: public void appraise(AppraiseConceptTagContext inCtic) {
173: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
174: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
175: sctiic.setInstanceTitle("Workflow-Template");
176: sctiic
177: .setInstanceDescription("Contains entire Workflow-Template");
178: sctiic.setLocalInstanceIcon("process-map");
179: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
180: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
181: scttic.setTypeTitle("Workflow-Template");
182: scttic
183: .setTypeDescription("Contains entire Workflow-Template");
184: }
185: }
186:
187: //public StartTag getStarts() {
188: // return (StartTag)startsTc.getValueAsTag();
189: //}
190:
191: //public StateTag getStates() {
192: // return (StateTag)statesTc.getValueAsTag();
193: //}
194:
195: //public StopTag getStops() {
196: // return (StopTag)stopsTc.getValueAsTag();
197: //}
198:
199: //public String getName() {
200: // return this.nameTc.getValueAsString();
201: //}
202:
203: //public String getVersion() {
204: // return this.versionTc.getValueAsString();
205: //}
206:
207: public void initializeApplicationAttributeSet(AttributeSet inAs,
208: DetermineValueAndClassConceptTagContext inRvacc)
209: throws DetermineValueAndClassConceptTagException {
210:
211: for (int i = 0; i < this .attributesCtchar.getValueLength(); i++) {
212:
213: Object o = this .attributesCtchar.getValueAsConceptTag(i,
214: inRvacc);
215: AttributeWorkflowTemplateTag at = (AttributeWorkflowTemplateTag) o;
216:
217: ValueAndClassForConceptTag value = at
218: .getInitialValue(inRvacc);
219: String name = at.getAttributeName();
220: Class atClass = at.getAttributeClass();
221: boolean canQuery = at.isAttributePublic();
222:
223: if (canQuery) {
224: //MiscHelper.println("WorkTempScrTag name = " + name);
225: //MiscHelper.println("WorkTempScrTag atClass = " + atClass);
226: //MiscHelper.println("WorkTempScrTag value = " + value);
227: //MiscHelper.println("WorkTempScrTag class = "
228: // + value.getValueClass());
229: //MiscHelper.println("WorkTempScrTag val = "
230: //+ value.getValue());
231: inAs.addPublicAppAttr(name, ConceptTagHelper.castTo(
232: atClass, value));
233: } else {
234: inAs.addPrivateAppAttr(name, ConceptTagHelper.castTo(
235: atClass, value));
236: }
237: }
238: }
239:
240: //START FUNCTIONS
241: public int getStartCount() {
242: return this .startsCtchar.getValueLength();
243: }
244:
245: public StartWorkflowTemplateTag getStart(int inIndex) {
246:
247: StartWorkflowTemplateTag outValue = null;
248:
249: Object o = this .startsCtchar
250: .getValueAsConceptTag(inIndex, null);
251: outValue = (StartWorkflowTemplateTag) o;
252:
253: return outValue;
254: }
255:
256: //STATE FUNCTIONS
257: public boolean isStatePresent(String inStateName) {
258:
259: //TO DO: optimize this
260:
261: boolean outValue = false;
262:
263: for (int i = 0; i < this .statesCtchar.getValueLength(); i++) {
264: Object o = this .statesCtchar.getValueAsConceptTag(i, null);
265: StateWorkflowTemplateTag nextState = (StateWorkflowTemplateTag) o;
266: String nextStateName = nextState.getName();
267: if (inStateName.equals(nextStateName)) {
268: outValue = true;
269: break;
270: }
271: }
272:
273: return outValue;
274: }
275:
276: public StateWorkflowTemplateTag findStateByName(String inStateName) {
277:
278: //TO DO: optimize this
279:
280: StateWorkflowTemplateTag outValue = null;
281:
282: for (int i = 0; i < this .statesCtchar.getValueLength(); i++) {
283: Object o = this .statesCtchar.getValueAsConceptTag(i, null);
284: StateWorkflowTemplateTag nextState = (StateWorkflowTemplateTag) o;
285: String nextStateName = nextState.getName();
286: if (inStateName.equals(nextStateName)) {
287: outValue = nextState;
288: break;
289: }
290: }
291:
292: return outValue;
293: }
294:
295: public int getStateCount() {
296: return this .statesCtchar.getValueLength();
297: }
298:
299: public StateWorkflowTemplateTag getState(int inIndex) {
300:
301: StateWorkflowTemplateTag outValue = null;
302:
303: Object o = this .statesCtchar
304: .getValueAsConceptTag(inIndex, null);
305: outValue = (StateWorkflowTemplateTag) o;
306:
307: return outValue;
308: }
309:
310: //STOP FUNCTIONS
311: public boolean isStopPresent(String inStopName) {
312: //TO DO: optimize this
313:
314: boolean outValue = false;
315:
316: for (int i = 0; i < this .stopsCtchar.getValueLength(); i++) {
317: Object o = this .stopsCtchar.getValueAsConceptTag(i, null);
318: StopWorkflowTemplateTag nextStop = (StopWorkflowTemplateTag) o;
319: String nextStopName = nextStop.getName();
320: if (inStopName.equals(nextStopName)) {
321: outValue = true;
322: break;
323: }
324: }
325:
326: return outValue;
327: }
328:
329: public StopWorkflowTemplateTag findStopByName(String inStopName) {
330:
331: //TO DO: optimize this
332:
333: StopWorkflowTemplateTag outValue = null;
334:
335: for (int i = 0; i < this .stopsCtchar.getValueLength(); i++) {
336: Object o = this .stopsCtchar.getValueAsConceptTag(i, null);
337: StopWorkflowTemplateTag nextStop = (StopWorkflowTemplateTag) o;
338: String nextStopName = nextStop.getName();
339: if (inStopName.equals(nextStopName)) {
340: outValue = nextStop;
341: break;
342: }
343: }
344:
345: return outValue;
346: }
347:
348: public int getStopCount() {
349: return this .stopsCtchar.getValueLength();
350: }
351:
352: public StopWorkflowTemplateTag getStop(int inIndex) {
353:
354: StopWorkflowTemplateTag outValue = null;
355:
356: Object o = this .stopsCtchar.getValueAsConceptTag(inIndex, null);
357: outValue = (StopWorkflowTemplateTag) o;
358:
359: return outValue;
360: }
361:
362: /*
363: //TO DO: add PowerFolder version to script, maybe read from properties file
364: public TagInputDescriptor initialize(Element e, ProcessMapRegistry pmr) {
365:
366: //TO DO: check for null, put this elsewhere?
367: pmr.normalizeElement(e);
368: //TO DO: can this throw exception?
369: //TO DO: try to get rid of below stat
370: this.processMap = pmr.convertElementToString(e);
371:
372: //update pmr here
373: NodeList nl = e.getChildNodes();
374: //MiscHelper.println(
375: "e.getChildNodes().getLength() = "+ nl.getLength());
376: for (int i = 0; i < nl.getLength(); i++) {
377: Node nextNode = (Node)nl.item(i);
378: if (nextNode instanceof Element) {
379: Element nextEle = (Element)nextNode;
380: if (nextEle.getTagName().equals(StartsTag.TAG_NAME)) {
381: NodeList startsNl = nextEle.getChildNodes();
382: for (int j = 0; j < startsNl.getLength(); j++) {
383: Node nextNode2 = (Node)startsNl.item(j);
384: if (nextNode2 instanceof Element) {
385: Element nextEle2 = (Element)nextNode2;
386: if (nextEle2.getTagName().equals(
387: StartTag.TAG_NAME)) {
388: if (nextEle2.hasAttribute(StartTag.ATTR_NAME)) {
389: String name = nextEle2.getAttribute(
390: StartTag.ATTR_NAME);
391:
392: String xPoint = nextEle2.getAttribute(
393: StartTag.ATTR_X_CORD);
394: String yPoint = nextEle2.getAttribute(
395: StartTag.ATTR_Y_CORD);
396: pmr.registerStart(name);
397: pmr.registerGraphPoint(xPoint, yPoint);
398: }
399: }
400: }
401: }
402: }
403: else if (nextEle.getTagName().equals(StatesTag.TAG_NAME)) {
404: NodeList statesNl = nextEle.getChildNodes();
405: for (int j = 0; j < statesNl.getLength(); j++) {
406: Node nextNode2 = (Node)statesNl.item(j);
407: if (nextNode2 instanceof Element) {
408: Element nextEle2 = (Element)nextNode2;
409: if (nextEle2.getTagName().equals(
410: StateTag.TAG_NAME)) {
411: if (nextEle2.hasAttribute(StateTag.ATTR_NAME)) {
412: String name = nextEle2.getAttribute(
413: StateTag.ATTR_NAME);
414:
415: String xPoint = nextEle2.getAttribute(
416: StateTag.ATTR_X_CORD);
417: String yPoint = nextEle2.getAttribute(
418: StateTag.ATTR_Y_CORD);
419: pmr.registerState(name);
420: pmr.registerGraphPoint(xPoint, yPoint);
421: }
422: }
423: }
424: }
425: }
426: else if (nextEle.getTagName().equals(StopsTag.TAG_NAME)) {
427: NodeList stopsNl = nextEle.getChildNodes();
428: for (int j = 0; j < stopsNl.getLength(); j++) {
429: Node nextNode2 = (Node)stopsNl.item(j);
430: if (nextNode2 instanceof Element) {
431: Element nextEle2 = (Element)nextNode2;
432: if (nextEle2.getTagName().equals(
433: StopTag.TAG_NAME)) {
434: if (nextEle2.hasAttribute(StopTag.ATTR_NAME)) {
435: String name = nextEle2.getAttribute(
436: StopTag.ATTR_NAME);
437:
438: String xPoint = nextEle2.getAttribute(
439: StopTag.ATTR_X_CORD);
440: String yPoint = nextEle2.getAttribute(
441: StopTag.ATTR_Y_CORD);
442: pmr.registerStop(name);
443: pmr.registerGraphPoint(xPoint, yPoint);
444: }
445: }
446: }
447: }
448: }
449: }
450: }
451:
452: this.xMax = pmr.getHighXPoint();
453: this.yMax = pmr.getHighYPoint();
454:
455: TagInputDescriptor tid = this.getTagInputDescriptor();
456: //MiscHelper.println("About to initialize ProcessMapTag - "
457: // + (new Timestamp(System.currentTimeMillis())));
458: tid.initialize(e, pmr);
459: tid.setTagShortSummary(this.nameAttr[0] + " (v" + this.versionAttr[0]
460: + ")");
461:
462: //MiscHelper.println("Finished initializing ProcessMapTag - "
463: // + (new Timestamp(System.currentTimeMillis())));
464: return tid;
465:
466: }
467:
468: ////attribute set
469: //TO DO: should the return be changed?
470: public AttributeSet getApplicationAttributeSet(AttributeSet as, Trigger t,
471: TagHelper th) throws PFException {
472:
473: AttributeSetTag ast = this.getAttributeSet();
474: ArrayList attributes = ast.getAttributes();
475:
476: for (int i = 0; i < attributes.size(); i++) {
477: Object nextAttr = attributes.get(i);
478: if (nextAttr instanceof PublicAttributeTag) {
479: PublicAttributeTag pat = (PublicAttributeTag)nextAttr;
480: String name = pat.getName();
481: Object o = pat.getInitialValue(as, t, th);
482: Class oClass = th.getClassByName(pat.getClassName());
483: as.addPublicAppAttr(name, th.createValueAndClass(o, oClass));
484: }
485: else {
486: PrivateAttributeTag pat = (PrivateAttributeTag)nextAttr;
487: String name = pat.getName();
488: Object o = pat.getInitialValue(as, t, th);
489: Class oClass = th.getClassByName(pat.getClassName());
490: as.addPrivateAppAttr(name, th.createValueAndClass(o, oClass));
491: }
492: //TO DO: should above be else-if, and have else throw exception?
493: }
494:
495: return as;
496: }
497:
498:
499: public void getTagSummary(TagSummaryDescriptor tsd) {
500: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
501: //tsd.appendData("Process Map<br/>");
502: tsd.appendData("<table width=\"100%\">");
503: //header
504: tsd.appendData("<tr><td style=\"font-size: 24;
505: // font-family: Arial; color: #000000;\">");
506: tsd.appendData("Process " + this.nameAttr[0] + " (version "
507: + this.versionAttr[0] + ")");
508: tsd.appendData("</td></tr>");
509:
510: //attribute set
511: if (this.attributeSetsTags.size() > 0) {
512: tsd.appendData("<tr><td>");
513: tsd.appendData("<hr/>");
514: tsd.appendData("</td></tr>");
515:
516: tsd.appendData("<tr><td>");
517: ((Tag)(this.attributeSetsTags.get(0))).getTagSummary(tsd);
518: tsd.appendData("</td></tr>");
519: }
520:
521: //starts
522: if (this.startsTags.size() > 0) {
523: tsd.appendData("<tr><td>");
524: tsd.appendData("<hr/>");
525: tsd.appendData("</td></tr>");
526:
527: tsd.appendData("<tr><td>");
528: ((Tag)(this.startsTags.get(0))).getTagSummary(tsd);
529: tsd.appendData("</td></tr>");
530: }
531:
532: //states
533: if (this.statesTags.size() > 0) {
534: tsd.appendData("<tr><td>");
535: tsd.appendData("<hr/>");
536: tsd.appendData("</td></tr>");
537:
538: tsd.appendData("<tr><td>");
539: ((Tag)(this.statesTags.get(0))).getTagSummary(tsd);
540: tsd.appendData("</td></tr>");
541: }
542:
543: //stops
544: if (this.stopsTags.size() > 0) {
545: tsd.appendData("<tr><td>");
546: tsd.appendData("<hr/>");
547: tsd.appendData("</td></tr>");
548:
549: tsd.appendData("<tr><td>");
550: ((Tag)(this.stopsTags.get(0))).getTagSummary(tsd);
551: tsd.appendData("</td></tr>");
552: }
553:
554: tsd.appendData("</table>");
555: }
556: else if (tsd.getMimeType().equals(TagSummaryMimeType.IMAGE_JPEG)) {
557: //MiscHelper.println("xMax = " + this.xMax);
558: //MiscHelper.println("yMax = " + this.yMax);
559: tsd.initializeDataGraphics2D(this.xMax, this.yMax);
560: Graphics2D big = tsd.getDataAsGraphics2D();
561: this.renderProcessMap(big);
562: }
563: //TO DO: what about other mime types?
564: }
565: */
566: }
|