001: package org.enhydra.jawe.base.xpdlobjectfactory;
002:
003: import java.lang.reflect.Method;
004: import java.util.HashSet;
005:
006: import org.enhydra.jawe.JaWEComponent;
007: import org.enhydra.jawe.JaWEConstants;
008: import org.enhydra.jawe.JaWEEAHandler;
009: import org.enhydra.jawe.JaWEManager;
010: import org.enhydra.jawe.ResourceManager;
011: import org.enhydra.jawe.Utils;
012: import org.enhydra.jawe.base.controller.JaWETypes;
013: import org.enhydra.jawe.base.xpdlhandler.XPDLHandler;
014: import org.enhydra.shark.xpdl.XMLCollection;
015: import org.enhydra.shark.xpdl.XMLCollectionElement;
016: import org.enhydra.shark.xpdl.XMLElement;
017: import org.enhydra.shark.xpdl.XMLUtil;
018: import org.enhydra.shark.xpdl.elements.Activities;
019: import org.enhydra.shark.xpdl.elements.Activity;
020: import org.enhydra.shark.xpdl.elements.ActivitySet;
021: import org.enhydra.shark.xpdl.elements.ActivitySets;
022: import org.enhydra.shark.xpdl.elements.ActualParameter;
023: import org.enhydra.shark.xpdl.elements.ActualParameters;
024: import org.enhydra.shark.xpdl.elements.Application;
025: import org.enhydra.shark.xpdl.elements.Applications;
026: import org.enhydra.shark.xpdl.elements.DataField;
027: import org.enhydra.shark.xpdl.elements.DataFields;
028: import org.enhydra.shark.xpdl.elements.Deadline;
029: import org.enhydra.shark.xpdl.elements.Deadlines;
030: import org.enhydra.shark.xpdl.elements.EnumerationType;
031: import org.enhydra.shark.xpdl.elements.EnumerationValue;
032: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
033: import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
034: import org.enhydra.shark.xpdl.elements.ExternalPackage;
035: import org.enhydra.shark.xpdl.elements.ExternalPackages;
036: import org.enhydra.shark.xpdl.elements.FormalParameter;
037: import org.enhydra.shark.xpdl.elements.FormalParameters;
038: import org.enhydra.shark.xpdl.elements.Member;
039: import org.enhydra.shark.xpdl.elements.Namespace;
040: import org.enhydra.shark.xpdl.elements.Namespaces;
041: import org.enhydra.shark.xpdl.elements.Package;
042: import org.enhydra.shark.xpdl.elements.PackageHeader;
043: import org.enhydra.shark.xpdl.elements.Participant;
044: import org.enhydra.shark.xpdl.elements.Participants;
045: import org.enhydra.shark.xpdl.elements.RecordType;
046: import org.enhydra.shark.xpdl.elements.Responsible;
047: import org.enhydra.shark.xpdl.elements.Responsibles;
048: import org.enhydra.shark.xpdl.elements.Tool;
049: import org.enhydra.shark.xpdl.elements.Tools;
050: import org.enhydra.shark.xpdl.elements.Transition;
051: import org.enhydra.shark.xpdl.elements.TransitionRef;
052: import org.enhydra.shark.xpdl.elements.TransitionRefs;
053: import org.enhydra.shark.xpdl.elements.TransitionRestriction;
054: import org.enhydra.shark.xpdl.elements.TransitionRestrictions;
055: import org.enhydra.shark.xpdl.elements.Transitions;
056: import org.enhydra.shark.xpdl.elements.TypeDeclaration;
057: import org.enhydra.shark.xpdl.elements.TypeDeclarations;
058: import org.enhydra.shark.xpdl.elements.UnionType;
059: import org.enhydra.shark.xpdl.elements.WorkflowProcess;
060: import org.enhydra.shark.xpdl.elements.WorkflowProcesses;
061:
062: /**
063: * Factory for generating XPDL objects.
064: *
065: * @author Sasa Bojanic
066: */
067: public class XPDLObjectFactory {
068:
069: protected XPDLObjectFactorySettings settings;
070:
071: public XPDLObjectFactory() {
072: settings = new XPDLObjectFactorySettings();
073: settings.init((JaWEComponent) null);
074: }
075:
076: public XPDLObjectFactory(XPDLObjectFactorySettings settings) {
077: this .settings = settings;
078: this .settings.init((JaWEComponent) null);
079: }
080:
081: public Package createPackage(String type) {
082: Package pkg = new Package();
083: adjustType(pkg, type);
084: XPDLHandler xpdlhandler = JaWEManager.getInstance()
085: .getXPDLHandler();
086: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
087: .getJaWETypes();
088: boolean hasTemplate = jts.hasTemplateId(type);
089: if (hasTemplate) {
090: jts.fillFromTemplate(pkg, type);
091: }
092: String id = pkg.getId();
093: if (!hasTemplate || id.equals("")
094: || xpdlhandler.getPackageById(id) != null) {
095: int i = 0;
096: while (id.equals("")
097: || xpdlhandler.getPackageById(id) != null) {
098: id = "newpkg" + String.valueOf(++i);
099: }
100: pkg.setId(id);
101: }
102: if (!hasTemplate || pkg.getName().equals("")) {
103: pkg.setName(id);
104: }
105: PackageHeader ph = pkg.getPackageHeader();
106: if (!hasTemplate) {
107: ph.setXPDLVersion("1.0");
108: ph.setVendor("Together");
109: }
110: ph.setCreated(Utils.getCurrentDateAndTime());
111:
112: Namespaces nss = pkg.getNamespaces();
113: Namespace ns = createXPDLObject(nss, "", true);
114: ns.setName("xpdl");
115: ns.setLocation("http://www.wfmc.org/2002/XPDL1.0");
116: adjustXPDLObject(pkg, type);
117:
118: return pkg;
119: }
120:
121: public ActivitySet createXPDLObject(ActivitySets ass, String type,
122: boolean addToCollection) {
123: ActivitySet as = (ActivitySet) ass.generateNewElement();
124: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
125: .getJaWETypes();
126: boolean hasTemplate = jts.hasTemplateId(type);
127: adjustType(as, type);
128: if (hasTemplate) {
129: jts.fillFromTemplate(as, type);
130: }
131: String id = as.getId();
132: if (!hasTemplate || id.equals("")
133: || ass.getActivitySet(id) != null) {
134: if (id.equals("")) {
135: id = JaWEManager.getInstance().getIdFactory()
136: .generateUniqueId(ass);
137: } else {
138: id = JaWEManager.getInstance().getIdFactory()
139: .generateSimilarOrIdenticalUniqueId(ass,
140: new HashSet(), id);
141: }
142: int i = 0;
143: while (ass.getActivitySet(id) != null) {
144: id = id + String.valueOf(++i);
145: }
146: as.setId(id);
147: }
148:
149: adjustXPDLObject(as, type);
150:
151: if (addToCollection) {
152: ass.add(as);
153: }
154: return as;
155: }
156:
157: public Activity createXPDLObject(Activities acts, String type,
158: boolean addToCollection) {
159: Activity act = null;
160: if (type == null || type.equals("")) {
161: type = JaWEConstants.ACTIVITY_TYPE_TOOL;
162: }
163: if (type.equals(JaWEConstants.ACTIVITY_TYPE_BLOCK)
164: || type.equals(JaWEConstants.ACTIVITY_TYPE_NO)
165: || type.equals(JaWEConstants.ACTIVITY_TYPE_ROUTE)
166: || type.equals(JaWEConstants.ACTIVITY_TYPE_SUBFLOW)
167: || type.equals(JaWEConstants.ACTIVITY_TYPE_TOOL)) {
168: act = createStandardActivity(acts, type);
169: } else {
170: act = createSpecialActivity(acts, type);
171: }
172:
173: adjustXPDLObject(act, type);
174:
175: if (addToCollection) {
176: acts.add(act);
177: }
178: return act;
179: }
180:
181: protected Activity createStandardActivity(Activities acts,
182: String type) {
183: Activity act = createXPDLActivity(acts, type);
184: if (type.equals(JaWEConstants.ACTIVITY_TYPE_BLOCK)) {
185: act.getActivityTypes().setBlockActivity();
186: } else if (type.equals(JaWEConstants.ACTIVITY_TYPE_ROUTE)) {
187: act.getActivityTypes().setRoute();
188: } else if (type.equals(JaWEConstants.ACTIVITY_TYPE_SUBFLOW)) {
189: act.getActivityTypes().setImplementation();
190: act.getActivityTypes().getImplementation()
191: .getImplementationTypes().setSubFlow();
192: } else if (type.equals(JaWEConstants.ACTIVITY_TYPE_TOOL)) {
193: act.getActivityTypes().setImplementation();
194: act.getActivityTypes().getImplementation()
195: .getImplementationTypes().setTools();
196: } else if (type.equals(JaWEConstants.ACTIVITY_TYPE_NO)) {
197: act.getActivityTypes().setImplementation();
198: act.getActivityTypes().getImplementation()
199: .getImplementationTypes().setNo();
200: }
201: return act;
202: }
203:
204: protected Activity createSpecialActivity(Activities acts,
205: String type) {
206: Activity act = createXPDLActivity(acts, type);
207: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
208: .getJaWETypes();
209: boolean hasTemplate = jts.hasTemplateId(type);
210:
211: if (!hasTemplate) {
212: act.getActivityTypes().getImplementation()
213: .getImplementationTypes().setTools();
214: act.getActivityTypes().setImplementation();
215: // JaWEEAHandler.setActivityType(act, type);
216: }
217: return act;
218: }
219:
220: protected Activity createXPDLActivity(Activities acts, String type) {
221: Activity act = (Activity) acts.generateNewElement();
222: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
223: .getJaWETypes();
224: boolean hasTemplate = jts.hasTemplateId(type);
225: if (hasTemplate) {
226: jts.fillFromTemplate(act, type);
227: }
228: String id = act.getId();
229: if (!hasTemplate || id.equals("")
230: || acts.getActivity(id) != null) {
231: if (id.equals("")) {
232: id = JaWEManager.getInstance().getIdFactory()
233: .generateUniqueId(acts);
234: } else {
235: id = JaWEManager.getInstance().getIdFactory()
236: .generateSimilarOrIdenticalUniqueId(acts,
237: new HashSet(), id);
238: }
239: int i = 0;
240: while (acts.getActivity(id) != null) {
241: id = id + String.valueOf(++i);
242: }
243: act.setId(id);
244: }
245: return act;
246: }
247:
248: public ActualParameter createXPDLObject(ActualParameters aps,
249: String type, boolean addToCollection) {
250: ActualParameter ap = (ActualParameter) aps.generateNewElement();
251: adjustType(ap, type);
252:
253: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
254: .getJaWETypes();
255: boolean hasTemplate = jts.hasTemplateId(type);
256: if (hasTemplate) {
257: jts.fillFromTemplate(ap, type);
258: }
259:
260: adjustXPDLObject(ap, type);
261:
262: if (addToCollection) {
263: aps.add(ap);
264: }
265: return ap;
266: }
267:
268: public Application createXPDLObject(Applications apps, String type,
269: boolean addToCollection) {
270: Application app = (Application) apps.generateNewElement();
271: adjustType(app, type);
272:
273: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
274: .getJaWETypes();
275: boolean hasTemplate = jts.hasTemplateId(type);
276: if (hasTemplate) {
277: jts.fillFromTemplate(app, type);
278: }
279: String id = app.getId();
280: if (!hasTemplate || id.equals("")
281: || apps.getApplication(id) != null) {
282: if (id.equals("")) {
283: id = JaWEManager.getInstance().getIdFactory()
284: .generateUniqueId(apps);
285: } else {
286: id = JaWEManager.getInstance().getIdFactory()
287: .generateSimilarOrIdenticalUniqueId(apps,
288: new HashSet(), id);
289: }
290: int i = 0;
291: while (apps.getApplication(id) != null) {
292: id = id + String.valueOf(++i);
293: }
294: app.setId(id);
295: }
296:
297: adjustXPDLObject(app, type);
298:
299: if (addToCollection) {
300: apps.add(app);
301: }
302: return app;
303: }
304:
305: public DataField createXPDLObject(DataFields dfs, String type,
306: boolean addToCollection) {
307: DataField df = (DataField) dfs.generateNewElement();
308: adjustType(df, type);
309:
310: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
311: .getJaWETypes();
312: boolean hasTemplate = jts.hasTemplateId(type);
313: if (hasTemplate) {
314: jts.fillFromTemplate(df, type);
315: }
316: String id = df.getId();
317: if (!hasTemplate || id.equals("")
318: || dfs.getDataField(id) != null) {
319: if (id.equals("")) {
320: id = JaWEManager.getInstance().getIdFactory()
321: .generateUniqueId(dfs);
322: } else {
323: id = JaWEManager.getInstance().getIdFactory()
324: .generateSimilarOrIdenticalUniqueId(dfs,
325: new HashSet(), id);
326: }
327: int i = 0;
328: while (dfs.getDataField(id) != null) {
329: id = id + String.valueOf(++i);
330: }
331: df.setId(id);
332: }
333:
334: adjustXPDLObject(df, type);
335:
336: if (addToCollection) {
337: dfs.add(df);
338: }
339: return df;
340: }
341:
342: public Deadline createXPDLObject(Deadlines dls, String type,
343: boolean addToCollection) {
344: Deadline dl = (Deadline) dls.generateNewElement();
345: adjustType(dl, type);
346:
347: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
348: .getJaWETypes();
349: boolean hasTemplate = jts.hasTemplateId(type);
350: if (hasTemplate) {
351: jts.fillFromTemplate(dl, type);
352: }
353:
354: adjustXPDLObject(dl, type);
355:
356: if (addToCollection) {
357: dls.add(dl);
358: }
359: return dl;
360: }
361:
362: public EnumerationValue createXPDLObject(EnumerationType et,
363: String type, boolean addToCollection) {
364: EnumerationValue ev = (EnumerationValue) et
365: .generateNewElement();
366: adjustType(ev, type);
367:
368: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
369: .getJaWETypes();
370: boolean hasTemplate = jts.hasTemplateId(type);
371: if (hasTemplate) {
372: jts.fillFromTemplate(ev, type);
373: }
374:
375: adjustXPDLObject(ev, type);
376:
377: if (addToCollection) {
378: et.add(ev);
379: }
380: return ev;
381: }
382:
383: public ExtendedAttribute createXPDLObject(ExtendedAttributes eas,
384: String type, boolean addToCollection) {
385: ExtendedAttribute ea = (ExtendedAttribute) eas
386: .generateNewElement();
387: adjustType(ea, type);
388:
389: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
390: .getJaWETypes();
391: boolean hasTemplate = jts.hasTemplateId(type);
392: if (hasTemplate) {
393: jts.fillFromTemplate(ea, type);
394: }
395:
396: adjustXPDLObject(ea, type);
397:
398: if (addToCollection) {
399: eas.add(ea);
400: }
401: return ea;
402: }
403:
404: public ExternalPackage createXPDLObject(ExternalPackages eps,
405: String type, boolean addToCollection) {
406: ExternalPackage ep = (ExternalPackage) eps.generateNewElement();
407: adjustType(ep, type);
408:
409: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
410: .getJaWETypes();
411: boolean hasTemplate = jts.hasTemplateId(type);
412: if (hasTemplate) {
413: jts.fillFromTemplate(ep, type);
414: }
415:
416: adjustXPDLObject(ep, type);
417:
418: if (addToCollection) {
419: eps.add(ep);
420: }
421: return ep;
422: }
423:
424: public FormalParameter createXPDLObject(FormalParameters fps,
425: String type, boolean addToCollection) {
426: FormalParameter fp = (FormalParameter) fps.generateNewElement();
427: adjustType(fp, type);
428:
429: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
430: .getJaWETypes();
431: boolean hasTemplate = jts.hasTemplateId(type);
432: if (hasTemplate) {
433: jts.fillFromTemplate(fp, type);
434: }
435: String id = fp.getId();
436: if (!hasTemplate || id.equals("")
437: || fps.getFormalParameter(id) != null) {
438: if (id.equals("")) {
439: id = JaWEManager.getInstance().getIdFactory()
440: .generateUniqueId(fps);
441: } else {
442: id = JaWEManager.getInstance().getIdFactory()
443: .generateSimilarOrIdenticalUniqueId(fps,
444: new HashSet(), id);
445: }
446: int i = 0;
447: while (fps.getFormalParameter(id) != null) {
448: id = id + String.valueOf(++i);
449: }
450: fp.setId(id);
451: }
452:
453: adjustXPDLObject(fp, type);
454:
455: if (addToCollection) {
456: fps.add(fp);
457: }
458: return fp;
459: }
460:
461: public Namespace createXPDLObject(Namespaces nss, String type,
462: boolean addToCollection) {
463: Namespace ns = (Namespace) nss.generateNewElement();
464: adjustType(ns, type);
465:
466: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
467: .getJaWETypes();
468: boolean hasTemplate = jts.hasTemplateId(type);
469: if (hasTemplate) {
470: jts.fillFromTemplate(ns, type);
471: }
472:
473: adjustXPDLObject(ns, type);
474:
475: if (addToCollection) {
476: nss.add(ns);
477: }
478: return ns;
479: }
480:
481: public Participant createXPDLObject(Participants ps, String type,
482: boolean addToCollection) {
483: Participant par = (Participant) ps.generateNewElement();
484: adjustType(par, type);
485:
486: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
487: .getJaWETypes();
488: boolean hasTemplate = jts.hasTemplateId(type);
489: if (hasTemplate) {
490: jts.fillFromTemplate(par, type);
491: }
492: String id = par.getId();
493: if (!hasTemplate || id.equals("")
494: || ps.getParticipant(id) != null) {
495: if (id.equals("")) {
496: id = JaWEManager.getInstance().getIdFactory()
497: .generateUniqueId(ps);
498: } else {
499: id = JaWEManager.getInstance().getIdFactory()
500: .generateSimilarOrIdenticalUniqueId(ps,
501: new HashSet(), id);
502: }
503: int i = 0;
504: while (ps.getParticipant(id) != null) {
505: id = id + String.valueOf(++i);
506: }
507: par.setId(id);
508: }
509:
510: if (type == null || type.equals(""))
511: type = JaWEConstants.PARTICIPANT_TYPE_ROLE;
512:
513: if (type.equals(JaWEConstants.PARTICIPANT_TYPE_HUMAN)) {
514: par.getParticipantType().setTypeHUMAN();
515: } else if (type.equals(JaWEConstants.PARTICIPANT_TYPE_ROLE)) {
516: par.getParticipantType().setTypeROLE();
517: } else if (type
518: .equals(JaWEConstants.PARTICIPANT_TYPE_ORGANIZATIONAL_UNIT)) {
519: par.getParticipantType().setTypeORGANIZATIONAL_UNIT();
520: } else if (type.equals(JaWEConstants.PARTICIPANT_TYPE_RESOURCE)) {
521: par.getParticipantType().setTypeRESOURCE();
522: } else if (type
523: .equals(JaWEConstants.PARTICIPANT_TYPE_RESOURCE_SET)) {
524: par.getParticipantType().setTypeRESOURCE_SET();
525: } else if (type.equals(JaWEConstants.PARTICIPANT_TYPE_SYSTEM)) {
526: par.getParticipantType().setTypeSYSTEM();
527: }
528:
529: adjustXPDLObject(par, type);
530:
531: if (addToCollection) {
532: ps.add(par);
533: }
534: return par;
535: }
536:
537: public Member createXPDLObject(RecordType rt, String type,
538: boolean addToCollection) {
539: Member m = (Member) rt.generateNewElement();
540: adjustType(m, type);
541:
542: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
543: .getJaWETypes();
544: boolean hasTemplate = jts.hasTemplateId(type);
545: if (hasTemplate) {
546: jts.fillFromTemplate(m, type);
547: }
548:
549: adjustXPDLObject(m, type);
550:
551: if (addToCollection) {
552: rt.add(m);
553: }
554: return m;
555: }
556:
557: public Responsible createXPDLObject(Responsibles rs, String type,
558: boolean addToCollection) {
559: Responsible r = (Responsible) rs.generateNewElement();
560: adjustType(r, type);
561:
562: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
563: .getJaWETypes();
564: boolean hasTemplate = jts.hasTemplateId(type);
565: if (hasTemplate) {
566: jts.fillFromTemplate(r, type);
567: }
568: // Map m=Utils.getPossibleResponsibles(rs,null);
569: // String parId="";
570: // if (m.size()>0) {
571: // parId=(String)m.keySet().iterator().next();
572: //
573: // }
574: // r.setValue(parId);
575:
576: adjustXPDLObject(r, type);
577:
578: if (addToCollection) {
579: rs.add(r);
580: }
581: return r;
582: }
583:
584: public Tool createXPDLObject(Tools ts, String type,
585: boolean addToCollection) {
586: Tool t = (Tool) ts.generateNewElement();
587: adjustType(t, type);
588:
589: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
590: .getJaWETypes();
591: boolean hasTemplate = jts.hasTemplateId(type);
592: if (hasTemplate) {
593: jts.fillFromTemplate(t, type);
594: }
595: // Map m=XMLUtil.getPossibleApplications(XMLUtil.getWorkflowProcess(ts),
596: // JaWEManager.getInstance().getXPDLHandler());
597: // String toolRef="";
598: // if (m.size()>0) {
599: // toolRef=(String)m.keySet().iterator().next();
600: // }
601: // t.setId(toolRef);
602:
603: adjustXPDLObject(t, type);
604:
605: if (addToCollection) {
606: ts.add(t);
607: }
608: return t;
609: }
610:
611: public Transition createXPDLObject(Transitions tras, String type,
612: boolean addToCollection) {
613: if (type == null || type.equals(""))
614: type = JaWEConstants.TRANSITION_TYPE_UNCONDITIONAL;
615:
616: Transition tra = createXPDLTransition(tras, type);
617: // if (type.equals(JaWEConstants.TRANSITION_TYPE_UNCONDITIONAL))
618: // do nothing
619: // else
620: if (type.equals(JaWEConstants.TRANSITION_TYPE_CONDITIONAL))
621: tra.getCondition().setTypeCONDITION();
622: else if (type.equals(JaWEConstants.TRANSITION_TYPE_OTHERWISE))
623: tra.getCondition().setTypeOTHERWISE();
624: else if (type.equals(JaWEConstants.TRANSITION_TYPE_EXCEPTION))
625: tra.getCondition().setTypeEXCEPTION();
626: else if (type
627: .equals(JaWEConstants.TRANSITION_TYPE_DEFAULTEXCEPTION))
628: tra.getCondition().setTypeDEFAULTEXCEPTION();
629:
630: adjustXPDLObject(tra, type);
631:
632: if (addToCollection) {
633: tras.add(tra);
634: }
635: return tra;
636: }
637:
638: protected Transition createXPDLTransition(Transitions tras,
639: String type) {
640: Transition tra = (Transition) tras.generateNewElement();
641: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
642: .getJaWETypes();
643: boolean hasTemplate = jts.hasTemplateId(type);
644: if (hasTemplate) {
645: jts.fillFromTemplate(tra, type);
646: }
647: String id = tra.getId();
648: if (!hasTemplate || id.equals("")
649: || tras.getTransition(id) != null) {
650: if (id.equals("")) {
651: id = JaWEManager.getInstance().getIdFactory()
652: .generateUniqueId(tras);
653: } else {
654: id = JaWEManager.getInstance().getIdFactory()
655: .generateSimilarOrIdenticalUniqueId(tras,
656: new HashSet(), id);
657: }
658: int i = 0;
659: while (tras.getTransition(id) != null) {
660: id = id + String.valueOf(++i);
661: }
662: tra.setId(id);
663: }
664: return tra;
665: }
666:
667: public TransitionRef createXPDLObject(TransitionRefs trs,
668: String type, boolean addToCollection) {
669: TransitionRef tr = (TransitionRef) trs.generateNewElement();
670: adjustType(tr, type);
671:
672: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
673: .getJaWETypes();
674: boolean hasTemplate = jts.hasTemplateId(type);
675: if (hasTemplate) {
676: jts.fillFromTemplate(tr, type);
677: }
678:
679: adjustXPDLObject(tr, type);
680:
681: if (addToCollection) {
682: trs.add(tr);
683: }
684: return tr;
685: }
686:
687: public TransitionRestriction createXPDLObject(
688: TransitionRestrictions trests, String type,
689: boolean addToCollection) {
690: TransitionRestriction tres = (TransitionRestriction) trests
691: .generateNewElement();
692: adjustType(tres, type);
693:
694: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
695: .getJaWETypes();
696: boolean hasTemplate = jts.hasTemplateId(type);
697: if (hasTemplate) {
698: jts.fillFromTemplate(tres, type);
699: }
700:
701: adjustXPDLObject(tres, type);
702:
703: if (addToCollection) {
704: trests.add(tres);
705: }
706: return tres;
707: }
708:
709: public TypeDeclaration createXPDLObject(TypeDeclarations tds,
710: String type, boolean addToCollection) {
711: TypeDeclaration td = (TypeDeclaration) tds.generateNewElement();
712: adjustType(td, type);
713:
714: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
715: .getJaWETypes();
716: boolean hasTemplate = jts.hasTemplateId(type);
717: if (hasTemplate) {
718: jts.fillFromTemplate(td, type);
719: }
720: String id = td.getId();
721: if (!hasTemplate || id.equals("")
722: || tds.getTypeDeclaration(id) != null) {
723: if (id.equals("")) {
724: id = JaWEManager.getInstance().getIdFactory()
725: .generateUniqueId(tds);
726: } else {
727: id = JaWEManager.getInstance().getIdFactory()
728: .generateSimilarOrIdenticalUniqueId(tds,
729: new HashSet(), id);
730: }
731: int i = 0;
732: while (tds.getTypeDeclaration(id) != null) {
733: id = id + String.valueOf(++i);
734: }
735: td.setId(id);
736: }
737:
738: adjustXPDLObject(td, type);
739:
740: if (addToCollection) {
741: tds.add(td);
742: }
743: return td;
744: }
745:
746: public Member createXPDLObject(UnionType ut, String type,
747: boolean addToCollection) {
748: Member m = (Member) ut.generateNewElement();
749: adjustType(m, type);
750:
751: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
752: .getJaWETypes();
753: boolean hasTemplate = jts.hasTemplateId(type);
754: if (hasTemplate) {
755: jts.fillFromTemplate(m, type);
756: }
757:
758: adjustXPDLObject(m, type);
759:
760: if (addToCollection) {
761: ut.add(m);
762: }
763: return m;
764: }
765:
766: public WorkflowProcess createXPDLObject(WorkflowProcesses wps,
767: String type, boolean addToCollection) {
768: WorkflowProcess wp = (WorkflowProcess) wps.generateNewElement();
769: adjustType(wp, type);
770:
771: JaWETypes jts = JaWEManager.getInstance().getJaWEController()
772: .getJaWETypes();
773: boolean hasTemplate = jts.hasTemplateId(type);
774: if (hasTemplate) {
775: jts.fillFromTemplate(wp, type);
776: }
777: String id = wp.getId();
778: if (!hasTemplate || id.equals("")
779: || wps.getWorkflowProcess(id) != null) {
780: if (id.equals("")) {
781: id = JaWEManager.getInstance().getIdFactory()
782: .generateUniqueId(wps);
783: } else {
784: id = JaWEManager.getInstance().getIdFactory()
785: .generateSimilarOrIdenticalUniqueId(wps,
786: new HashSet(), id);
787: }
788: int i = 0;
789: while (wps.getWorkflowProcess(id) != null) {
790: id = id + String.valueOf(++i);
791: }
792: wp.setId(id);
793: }
794:
795: if (!hasTemplate || wp.getName().equals("")) {
796: wp.setName(id);
797: }
798: wp.getProcessHeader().setCreated(Utils.getCurrentDateAndTime());
799: wp.getRedefinableHeader().setAuthor(
800: XMLUtil.getPackage(wps).getRedefinableHeader()
801: .getAuthor());
802:
803: adjustXPDLObject(wp, type);
804:
805: if (addToCollection) {
806: wps.add(wp);
807: }
808: return wp;
809: }
810:
811: public void adjustXPDLObject(XMLElement el, String type) {
812: if (type != null && !type.equals("")) {
813: JaWEEAHandler.setJaWEType(el, type);
814: }
815: }
816:
817: public XMLElement createXPDLObject(XMLCollection col, String type,
818: boolean addToCollection) {
819: try {
820: Class cl = col.getClass();
821: Method m = null;
822: try {
823: m = this .getClass()
824: .getMethod(
825: "createXPDLObject",
826: new Class[] { cl, String.class,
827: boolean.class });
828: } catch (Exception ex) {
829: if (!(cl == XMLCollection.class)) {
830: if (XMLCollection.class.isAssignableFrom(cl)) {
831: cl = XMLCollection.class;
832: }
833: }
834: }
835: m = this .getClass().getMethod("createXPDLObject",
836: new Class[] { cl, String.class, boolean.class });
837: // System.err.println("calling "+m.toString());
838: return (XMLElement) m.invoke(this , new Object[] { col,
839: type, new Boolean(addToCollection) });
840: } catch (Throwable e) {
841: e.printStackTrace();
842: return null;
843: }
844:
845: }
846:
847: public XMLElement duplicateXPDLObject(XMLCollection col,
848: XMLElement el) {
849: XMLElement dup = col.generateNewElement();
850: dup.makeAs(el);
851: if (dup instanceof XMLCollectionElement) {
852: if (!(dup instanceof Tool)) {
853: ((XMLCollectionElement) dup).setId(JaWEManager
854: .getInstance().getIdFactory().generateUniqueId(
855: (XMLCollection) dup.getParent()));
856: }
857: XMLElement name = ((XMLCollectionElement) el).get("Name");
858: if (name != null && name.toValue().length() > 0) {
859: ((XMLCollectionElement) dup)
860: .set(
861: "Name",
862: ResourceManager
863: .getLanguageDependentString("CopyOfKey")
864: + " " + name.toValue());
865: }
866: }
867: return dup;
868: }
869:
870: public XMLElement makeIdenticalXPDLObject(XMLCollection col,
871: XMLElement el) {
872: XMLElement dup = col.generateNewElement();
873: dup.makeAs(el);
874: return dup;
875: }
876:
877: protected String adjustType(XMLElement el, String type) {
878: if (type == null || type.equals("")) {
879: type = JaWEManager.getInstance().getJaWEController()
880: .getJaWETypes().getDefaultType(el);
881: }
882: return type;
883: }
884: }
|