001: package org.enhydra.shark.webclient.business;
002:
003: import java.util.ArrayList;
004: import java.util.Arrays;
005: import java.util.Date;
006: import java.util.HashMap;
007: import java.util.List;
008: import java.util.Map;
009:
010: import org.apache.xerces.impl.dv.util.Base64;
011: import org.enhydra.shark.utilities.MiscUtilities;
012: import org.enhydra.shark.webclient.spec.SharkParamConsts;
013: import org.enhydra.shark.xpil.XPILActivityInstance;
014: import org.enhydra.shark.xpil.XPILDataInstance;
015: import org.enhydra.shark.xpil.XPILExtendedWorkflowFacilityInstanceDocument;
016: import org.enhydra.shark.xpil.XPILWorkflowProcessInstance;
017: import org.enhydra.shark.xpil.XPDLDataFieldDocument.DataField;
018: import org.enhydra.shark.xpil.XPDLExtendedAttributeDocument.ExtendedAttribute;
019: import org.enhydra.shark.xpil.XPDLExtendedAttributesDocument.ExtendedAttributes;
020: import org.enhydra.shark.xpil.XPILBooleanArrayDataInstanceDocument.BooleanArrayDataInstance;
021: import org.enhydra.shark.xpil.XPILBooleanDataInstanceDocument.BooleanDataInstance;
022: import org.enhydra.shark.xpil.XPILBooleanValueDocument.BooleanValue;
023: import org.enhydra.shark.xpil.XPILByteArrayDataInstanceDocument.ByteArrayDataInstance;
024: import org.enhydra.shark.xpil.XPILComplexDataInstanceDocument.ComplexDataInstance;
025: import org.enhydra.shark.xpil.XPILDateArrayDataInstanceDocument.DateArrayDataInstance;
026: import org.enhydra.shark.xpil.XPILDateDataInstanceDocument.DateDataInstance;
027: import org.enhydra.shark.xpil.XPILDateTimeArrayDataInstanceDocument.DateTimeArrayDataInstance;
028: import org.enhydra.shark.xpil.XPILDateTimeDataInstanceDocument.DateTimeDataInstance;
029: import org.enhydra.shark.xpil.XPILDateTimeValueDocument.DateTimeValue;
030: import org.enhydra.shark.xpil.XPILDateValueDocument.DateValue;
031: import org.enhydra.shark.xpil.XPILDoubleArrayDataInstanceDocument.DoubleArrayDataInstance;
032: import org.enhydra.shark.xpil.XPILDoubleDataInstanceDocument.DoubleDataInstance;
033: import org.enhydra.shark.xpil.XPILDoubleValueDocument.DoubleValue;
034: import org.enhydra.shark.xpil.XPILExtendedWorkflowFacilityInstanceDocument.ExtendedWorkflowFacilityInstance;
035: import org.enhydra.shark.xpil.XPILInstanceExtendedAttributeDocument.InstanceExtendedAttribute;
036: import org.enhydra.shark.xpil.XPILInstanceExtendedAttributesDocument.InstanceExtendedAttributes;
037: import org.enhydra.shark.xpil.XPILLongArrayDataInstanceDocument.LongArrayDataInstance;
038: import org.enhydra.shark.xpil.XPILLongDataInstanceDocument.LongDataInstance;
039: import org.enhydra.shark.xpil.XPILLongValueDocument.LongValue;
040: import org.enhydra.shark.xpil.XPILSchemaDataInstanceDocument.SchemaDataInstance;
041: import org.enhydra.shark.xpil.XPILStringArrayDataInstanceDocument.StringArrayDataInstance;
042: import org.enhydra.shark.xpil.XPILStringDataInstanceDocument.StringDataInstance;
043: import org.enhydra.shark.xpil.XPILStringValueDocument.StringValue;
044: import org.enhydra.shark.xpil.XPILTimeArrayDataInstanceDocument.TimeArrayDataInstance;
045: import org.enhydra.shark.xpil.XPILTimeDataInstanceDocument.TimeDataInstance;
046: import org.enhydra.shark.xpil.XPILTimeValueDocument.TimeValue;
047: import org.w3c.dom.Node;
048:
049: public class XPILUtils {
050:
051: public static Map extractProcessInfo(
052: XPILExtendedWorkflowFacilityInstanceDocument xpil)
053: throws Exception {
054:
055: XPILWorkflowProcessInstance[] wpia = xpil
056: .getExtendedWorkflowFacilityInstance()
057: .getMainWorkflowProcessInstanceArray();
058:
059: if (wpia == null || wpia.length == 0) {
060:
061: wpia = xpil.getExtendedWorkflowFacilityInstance()
062: .getSubWorkflowProcessInstanceArray();
063:
064: }
065: XPILWorkflowProcessInstance proXpil = wpia[0];
066: Map m = new HashMap();
067: try {
068: m.put("Id", proXpil.getId());
069: m.put("Name", proXpil.getName());
070: m.put("Description", proXpil.getInstanceDescription());
071: if (proXpil.isSetInstancePriority()) {
072: m.put("Priority", new Integer(proXpil
073: .getInstancePriority()));
074: }
075: } catch (Exception ex) {
076: }
077: return m;
078: }
079:
080: public static Map extractActivityInfo(
081: XPILExtendedWorkflowFacilityInstanceDocument xpil)
082: throws Exception {
083:
084: XPILActivityInstance[] aia = xpil
085: .getExtendedWorkflowFacilityInstance()
086: .getManualActivityInstanceArray();
087: if (aia == null || aia.length == 0) {
088: aia = xpil.getExtendedWorkflowFacilityInstance()
089: .getToolActivityInstanceArray();
090: }
091: if (aia == null || aia.length == 0) {
092: aia = xpil.getExtendedWorkflowFacilityInstance()
093: .getSubFlowActivityInstanceArray();
094: }
095: if (aia == null || aia.length == 0) {
096: aia = xpil.getExtendedWorkflowFacilityInstance()
097: .getBlockActivityInstanceArray();
098: }
099: if (aia == null || aia.length == 0) {
100: aia = xpil.getExtendedWorkflowFacilityInstance()
101: .getRouteActivityInstanceArray();
102: }
103:
104: Map m = new HashMap();
105: try {
106: XPILActivityInstance actXpil = aia[0];
107: m.put("Id", actXpil.getId());
108: m.put("Name", actXpil.getName());
109: m.put("Description", actXpil.getInstanceDescription());
110: if (actXpil.isSetInstancePriority()) {
111: m.put("Priority", new Integer(actXpil
112: .getInstancePriority()));
113: }
114: } catch (Exception ex) {
115: }
116: return m;
117: }
118:
119: public static Map extractVariablesFromXPIL(
120: XPILExtendedWorkflowFacilityInstanceDocument xpil)
121: throws Exception {
122:
123: Map map = new HashMap();
124:
125: ExtendedWorkflowFacilityInstance ins = xpil
126: .getExtendedWorkflowFacilityInstance();
127:
128: StringDataInstance[] sIns = ins.getStringDataInstanceArray();
129: for (int i = 0; i < sIns.length; i++) {
130: StringDataInstance sIn = sIns[i];
131: // if (sIn.getValue() != null) {
132: String v = null;
133: // boolean failed = false;
134: try {
135: v = sIn.xgetValue().getStringValue();
136: } catch (Exception ex) {
137: // failed = true;
138: // System.out.println("STRVAL FAILED FOR "+sIn.getId());
139: }
140: // if (!failed) {
141: map.put(sIn.getId(), v);
142: // }
143: // if (handleEmptyString || !sIn.getValue().equals("")) {
144: // map.put(sIn.getId(), sIn.getValue());
145: // }
146: // }
147: }
148:
149: StringArrayDataInstance[] saIns = ins
150: .getStringArrayDataInstanceArray();
151: for (int i = 0; i < saIns.length; i++) {
152: StringArrayDataInstance sIn = saIns[i];
153: StringValue[] av = sIn.getStringValue1Array();
154: String[] arr = null;
155: if (av != null) {
156: arr = new String[av.length];
157: for (int j = 0; j < av.length; j++) {
158: arr[j] = av[j].getValue();
159: }
160: }
161: map.put(sIn.getId(), arr);
162: }
163:
164: DoubleDataInstance[] dIns = ins.getDoubleDataInstanceArray();
165: for (int i = 0; i < dIns.length; i++) {
166: DoubleDataInstance dIn = dIns[i];
167: double v = -1;
168: boolean failed = false;
169: try {
170: v = dIn.xgetValue().getDoubleValue();
171: } catch (Exception ex) {
172: failed = true;
173: // System.out.println("DBLVAL FAILED FOR "+dIn.getId());
174: }
175: if (!failed) {
176: map.put(dIn.getId(), new Double(v));
177: } else {
178: map.put(dIn.getId(), null);
179: }
180: }
181:
182: DoubleArrayDataInstance[] daIns = ins
183: .getDoubleArrayDataInstanceArray();
184: for (int i = 0; i < daIns.length; i++) {
185: DoubleArrayDataInstance sIn = daIns[i];
186: DoubleValue[] av = sIn.getDoubleValue1Array();
187: Double[] arr = null;
188: if (av != null) {
189: arr = new Double[av.length];
190: for (int j = 0; j < av.length; j++) {
191: arr[j] = new Double(av[j].getValue());
192: }
193: }
194: map.put(sIn.getId(), arr);
195: }
196:
197: BooleanDataInstance[] bIns = ins.getBooleanDataInstanceArray();
198: for (int i = 0; i < bIns.length; i++) {
199: BooleanDataInstance bIn = bIns[i];
200: boolean v = false;
201: boolean failed = false;
202: try {
203: v = bIn.xgetValue().getBooleanValue();
204: } catch (Exception ex) {
205: failed = true;
206: // System.out.println("BOOL FAILED FOR "+bIn.getId());
207: }
208: if (!failed) {
209: map.put(bIn.getId(), new Boolean(v));
210: } else {
211: map.put(bIn.getId(), null);
212: }
213: }
214:
215: BooleanArrayDataInstance[] baIns = ins
216: .getBooleanArrayDataInstanceArray();
217: for (int i = 0; i < baIns.length; i++) {
218: BooleanArrayDataInstance sIn = baIns[i];
219: BooleanValue[] av = sIn.getBooleanValue1Array();
220: Boolean[] arr = null;
221: if (av != null) {
222: arr = new Boolean[av.length];
223: for (int j = 0; j < av.length; j++) {
224: arr[j] = new Boolean(av[j].getValue());
225: }
226: }
227: map.put(sIn.getId(), arr);
228: }
229:
230: LongDataInstance[] lIns = ins.getLongDataInstanceArray();
231: for (int i = 0; i < lIns.length; i++) {
232: LongDataInstance lIn = lIns[i];
233: long v = -1;
234: boolean failed = false;
235: try {
236: v = lIn.xgetValue().getLongValue();
237: } catch (Exception ex) {
238: failed = true;
239: // System.out.println("LNGVAL FAILED FOR "+lIn.getId());
240: }
241: if (!failed) {
242: map.put(lIn.getId(), new Long(v));
243: } else {
244: map.put(lIn.getId(), null);
245: }
246: }
247:
248: LongArrayDataInstance[] laIns = ins
249: .getLongArrayDataInstanceArray();
250: for (int i = 0; i < laIns.length; i++) {
251: LongArrayDataInstance sIn = laIns[i];
252: LongValue[] av = sIn.getLongValue1Array();
253: Long[] arr = null;
254: if (av != null) {
255: arr = new Long[av.length];
256: for (int j = 0; j < av.length; j++) {
257: arr[j] = new Long(av[j].getValue());
258: }
259: }
260: map.put(sIn.getId(), arr);
261: }
262:
263: DateDataInstance[] tIns = ins.getDateDataInstanceArray();
264: for (int i = 0; i < tIns.length; i++) {
265: DateDataInstance tIn = tIns[i];
266: long v = -1;
267: boolean failed = false;
268: try {
269: v = tIn.xgetValue().getCalendarValue()
270: .getTimeInMillis();
271: } catch (Exception ex) {
272: failed = true;
273: // System.out.println("DTEVAL FAILED FOR "+tIn.getId());
274: }
275: if (!failed) {
276: map.put(tIn.getId(), new Date(v));
277: } else {
278: map.put(tIn.getId(), null);
279: }
280: }
281:
282: DateArrayDataInstance[] taIns = ins
283: .getDateArrayDataInstanceArray();
284: for (int i = 0; i < taIns.length; i++) {
285: DateArrayDataInstance sIn = taIns[i];
286: DateValue[] av = sIn.getDateValue1Array();
287: Date[] arr = null;
288: if (av != null) {
289: arr = new Date[av.length];
290: for (int j = 0; j < av.length; j++) {
291: arr[j] = new Date(av[j].getValue()
292: .getTimeInMillis());
293: }
294: }
295: map.put(sIn.getId(), arr);
296: }
297:
298: DateTimeDataInstance[] tdtIns = ins
299: .getDateTimeDataInstanceArray();
300: for (int i = 0; i < tdtIns.length; i++) {
301: DateTimeDataInstance tIn = tdtIns[i];
302: long v = -1;
303: boolean failed = false;
304: try {
305: v = tIn.xgetValue().getCalendarValue()
306: .getTimeInMillis();
307: } catch (Exception ex) {
308: failed = true;
309: // System.out.println("DTEVAL FAILED FOR "+tIn.getId());
310: }
311: if (!failed) {
312: map.put(tIn.getId(), new Date(v));
313: } else {
314: map.put(tIn.getId(), null);
315: }
316: }
317:
318: DateTimeArrayDataInstance[] tdtaIns = ins
319: .getDateTimeArrayDataInstanceArray();
320: for (int i = 0; i < taIns.length; i++) {
321: DateTimeArrayDataInstance sIn = tdtaIns[i];
322: DateTimeValue[] av = sIn.getDateTimeValueArray();
323: Date[] arr = null;
324: if (av != null) {
325: arr = new Date[av.length];
326: for (int j = 0; j < av.length; j++) {
327: arr[j] = new Date(av[j].getValue()
328: .getTimeInMillis());
329: }
330: }
331: map.put(sIn.getId(), arr);
332: }
333:
334: TimeDataInstance[] ttIns = ins.getTimeDataInstanceArray();
335: for (int i = 0; i < ttIns.length; i++) {
336: TimeDataInstance tIn = ttIns[i];
337: long v = -1;
338: boolean failed = false;
339: try {
340: v = tIn.xgetValue().getCalendarValue()
341: .getTimeInMillis();
342: } catch (Exception ex) {
343: failed = true;
344: // System.out.println("DTEVAL FAILED FOR "+tIn.getId());
345: }
346: if (!failed) {
347: map.put(tIn.getId(), new Date(v));
348: } else {
349: map.put(tIn.getId(), null);
350: }
351: }
352:
353: TimeArrayDataInstance[] ttaIns = ins
354: .getTimeArrayDataInstanceArray();
355: for (int i = 0; i < taIns.length; i++) {
356: TimeArrayDataInstance sIn = ttaIns[i];
357: TimeValue[] av = sIn.getTimeValueArray();
358: Date[] arr = null;
359: if (av != null) {
360: arr = new Date[av.length];
361: for (int j = 0; j < av.length; j++) {
362: arr[j] = new Date(av[j].getValue()
363: .getTimeInMillis());
364: }
365: }
366: map.put(sIn.getId(), arr);
367: }
368:
369: ByteArrayDataInstance[] byaIns = ins
370: .getByteArrayDataInstanceArray();
371: for (int i = 0; i < byaIns.length; i++) {
372: ByteArrayDataInstance sIn = byaIns[i];
373: String b64str = sIn.getValue();
374: byte[] arr = null;
375: if (b64str != null) {
376: arr = Base64.decode(b64str);
377: }
378: map.put(sIn.getId(), arr);
379: }
380:
381: SchemaDataInstance[] schIns = ins.getSchemaDataInstanceArray();
382: for (int i = 0; i < schIns.length; i++) {
383: SchemaDataInstance schIn = schIns[i];
384: Node fc = schIn.getValue().getDomNode().getFirstChild();
385: Node sv = null;
386: if (fc != null) {
387: sv = fc.getNextSibling();
388: if (sv == null) {
389: sv = fc;
390: }
391: }
392: map.put(schIn.getId(), sv);
393: }
394:
395: return map;
396:
397: }
398:
399: public static void filterActivityVariables(
400: ExtendedWorkflowFacilityInstance ins,
401: String[][] extAttribs, boolean isDynamicVariableHandling)
402: throws Exception {
403:
404: BooleanDataInstance[] bdisa = ins.getBooleanDataInstanceArray();
405: BooleanArrayDataInstance[] badisa = ins
406: .getBooleanArrayDataInstanceArray();
407: ComplexDataInstance[] cdisa = ins.getComplexDataInstanceArray();
408: DateDataInstance[] dtdisa = ins.getDateDataInstanceArray();
409: DateArrayDataInstance[] dtadisa = ins
410: .getDateArrayDataInstanceArray();
411: DoubleDataInstance[] dbdisa = ins.getDoubleDataInstanceArray();
412: DoubleArrayDataInstance[] dbadisa = ins
413: .getDoubleArrayDataInstanceArray();
414: LongDataInstance[] ldisa = ins.getLongDataInstanceArray();
415: LongArrayDataInstance[] ladisa = ins
416: .getLongArrayDataInstanceArray();
417: SchemaDataInstance[] shdisa = ins.getSchemaDataInstanceArray();
418: StringDataInstance[] strdisa = ins.getStringDataInstanceArray();
419: StringArrayDataInstance[] stradisa = ins
420: .getStringArrayDataInstanceArray();
421: ByteArrayDataInstance[] byadisa = ins
422: .getByteArrayDataInstanceArray();
423:
424: String[] varsToDisp = null;
425: List varIds = null;
426: String[] varNames = null;
427: String[] varMandatories = null;
428: String[] varMaxLengths = null;
429:
430: Map xpilDis = new HashMap();
431: if (bdisa != null) {
432: for (int i = bdisa.length - 1; i >= 0; i--) {
433: xpilDis.put(bdisa[i].getId(), bdisa[i].copy());
434: ins.removeBooleanDataInstance(i);
435: }
436: }
437: if (badisa != null) {
438: for (int i = badisa.length - 1; i >= 0; i--) {
439: xpilDis.put(badisa[i].getId(), badisa[i].copy());
440: ins.removeBooleanArrayDataInstance(i);
441: }
442: }
443: if (cdisa != null) {
444: for (int i = cdisa.length - 1; i >= 0; i--) {
445: xpilDis.put(cdisa[i].getId(), cdisa[i].copy());
446: ins.removeComplexDataInstance(i);
447: }
448: }
449: if (dtdisa != null) {
450: for (int i = dtdisa.length - 1; i >= 0; i--) {
451: xpilDis.put(dtdisa[i].getId(), dtdisa[i].copy());
452: ins.removeDateDataInstance(i);
453: }
454: }
455: if (dtadisa != null) {
456: for (int i = dtadisa.length - 1; i >= 0; i--) {
457: xpilDis.put(dtadisa[i].getId(), dtadisa[i].copy());
458: ins.removeDateArrayDataInstance(i);
459: }
460: }
461: if (dbdisa != null) {
462: for (int i = dbdisa.length - 1; i >= 0; i--) {
463: xpilDis.put(dbdisa[i].getId(), dbdisa[i].copy());
464: ins.removeDoubleDataInstance(i);
465: }
466: }
467: if (dbadisa != null) {
468: for (int i = dbadisa.length - 1; i >= 0; i--) {
469: xpilDis.put(dbadisa[i].getId(), dbadisa[i].copy());
470: ins.removeDoubleArrayDataInstance(i);
471: }
472: }
473: if (ldisa != null) {
474: for (int i = ldisa.length - 1; i >= 0; i--) {
475: xpilDis.put(ldisa[i].getId(), ldisa[i].copy());
476: ins.removeLongDataInstance(i);
477: }
478: }
479: if (ladisa != null) {
480: for (int i = ladisa.length - 1; i >= 0; i--) {
481: xpilDis.put(ladisa[i].getId(), ladisa[i].copy());
482: ins.removeLongArrayDataInstance(i);
483: }
484: }
485: if (shdisa != null) {
486: for (int i = shdisa.length - 1; i >= 0; i--) {
487: xpilDis.put(shdisa[i].getId(), shdisa[i].copy());
488: ins.removeSchemaDataInstance(i);
489: }
490: }
491: if (strdisa != null) {
492: for (int i = strdisa.length - 1; i >= 0; i--) {
493: xpilDis.put(strdisa[i].getId(), strdisa[i].copy());
494: if (isDynamicVariableHandling) {
495: if (strdisa[i]
496: .getId()
497: .equals(
498: SharkParamConsts.DYNAMIC_VARIABLE_DISPLAY_VARIABLE)) {
499: String dispVarStr = strdisa[i].getValue();
500: if (dispVarStr != null) {
501: varsToDisp = MiscUtilities.tokenize(
502: dispVarStr, ",");
503: }
504: }
505: }
506: ins.removeStringDataInstance(i);
507: }
508: }
509: if (stradisa != null) {
510: for (int i = stradisa.length - 1; i >= 0; i--) {
511: xpilDis.put(stradisa[i].getId(), stradisa[i].copy());
512: if (isDynamicVariableHandling) {
513: String[] sa = null;
514: if (stradisa[i]
515: .getId()
516: .equals(
517: SharkParamConsts.DYNAMIC_VARIABLE_IDS_VARIABLE)
518: || stradisa[i]
519: .getId()
520: .equals(
521: SharkParamConsts.DYNAMIC_VARIABLE_NAMES_VARIABLE)
522: || stradisa[i]
523: .getId()
524: .equals(
525: SharkParamConsts.DYNAMIC_VARIABLE_MANDATORIES_VARIABLE)
526: || stradisa[i]
527: .getId()
528: .equals(
529: SharkParamConsts.DYNAMIC_VARIABLE_MAX_LENGTHS_VARIABLE)) {
530: StringValue[] sva = stradisa[i]
531: .getStringValue1Array();
532: if (sva != null) {
533: sa = new String[sva.length];
534: for (int j = 0; j < sva.length; j++) {
535: sa[j] = sva[j].getValue();
536: }
537: }
538: if (stradisa[i]
539: .getId()
540: .equals(
541: SharkParamConsts.DYNAMIC_VARIABLE_IDS_VARIABLE)) {
542: varIds = Arrays.asList(sa);
543: } else if (stradisa[i]
544: .getId()
545: .equals(
546: SharkParamConsts.DYNAMIC_VARIABLE_NAMES_VARIABLE)) {
547: varNames = sa;
548: } else if (stradisa[i]
549: .getId()
550: .equals(
551: SharkParamConsts.DYNAMIC_VARIABLE_MANDATORIES_VARIABLE)) {
552: varMandatories = sa;
553: } else if (stradisa[i]
554: .getId()
555: .equals(
556: SharkParamConsts.DYNAMIC_VARIABLE_MAX_LENGTHS_VARIABLE)) {
557: varMaxLengths = sa;
558: }
559:
560: }
561: }
562: ins.removeStringArrayDataInstance(i);
563: }
564: }
565: if (byadisa != null) {
566: for (int i = byadisa.length - 1; i >= 0; i--) {
567: xpilDis.put(byadisa[i].getId(), byadisa[i].copy());
568: ins.removeByteArrayDataInstance(i);
569: }
570: }
571:
572: if (!isDynamicVariableHandling) {
573: for (int i = 0; i < extAttribs.length; i++) {
574: String eaName = extAttribs[i][0];
575:
576: if (eaName
577: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_UPDATE)
578: || eaName
579: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_VIEW)
580: || eaName
581: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_FETCH)) {
582: String variableId = extAttribs[i][1];
583: String fetchVarId = null;
584: int indOfSC = variableId.indexOf(";");
585: if (indOfSC > 0) {
586: fetchVarId = variableId.substring(indOfSC + 1);
587: variableId = variableId.substring(0, indOfSC);
588: }
589: if (xpilDis.containsKey(variableId)) {
590: XPILDataInstance di = (XPILDataInstance) xpilDis
591: .get(variableId);
592: InstanceExtendedAttributes ieas = di
593: .getInstanceExtendedAttributes();
594: if (ieas == null) {
595: ieas = di
596: .addNewInstanceExtendedAttributes();
597: }
598: InstanceExtendedAttribute iea = ieas
599: .addNewInstanceExtendedAttribute();
600: iea.setName("how_to_handle_marker");
601:
602: if (eaName
603: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_UPDATE)) {
604: iea.setValue("1");
605: } else if (eaName
606: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_VIEW)) {
607: iea.setValue("0");
608: } else if (eaName
609: .equals(SharkParamConsts.EA_VAR_TO_PROCESS_FETCH)) {
610: if (xpilDis.containsKey(fetchVarId)) {
611: iea.setValue("2");
612: iea = ieas
613: .addNewInstanceExtendedAttribute();
614: iea.setName("fetch_marker");
615: iea.setValue(fetchVarId);
616: XPILDataInstance fetchdi = (XPILDataInstance) xpilDis
617: .get(fetchVarId);
618: InstanceExtendedAttributes fetchieas = fetchdi
619: .getInstanceExtendedAttributes();
620: if (fetchieas == null) {
621: fetchieas = fetchdi
622: .addNewInstanceExtendedAttributes();
623: }
624: InstanceExtendedAttribute fetchiea = fetchieas
625: .addNewInstanceExtendedAttribute();
626: fetchiea
627: .setName("how_to_handle_marker");
628: fetchiea.setValue("-1");
629: fillInXPILDataInstance(ins, fetchdi);
630: }
631: }
632: fillInXPILDataInstance(ins, di);
633: }
634:
635: }
636: }
637: } else {
638: if (varsToDisp != null) {
639: for (int i = 0; i < varsToDisp.length; i++) {
640: String variableId = varsToDisp[i];
641: XPILDataInstance di = (XPILDataInstance) xpilDis
642: .get(variableId);
643: if (varIds != null) {
644: int indOf = varIds.indexOf(variableId);
645: if (indOf >= 0) {
646: if (varNames[indOf] != null) {
647: DataField df = di.addNewDataField();
648: df.setId(variableId);
649: df.setName(varNames[indOf]);
650: ExtendedAttributes eas = df
651: .getExtendedAttributes();
652: if (eas == null) {
653: eas = df.addNewExtendedAttributes();
654: }
655: ExtendedAttribute ea = eas
656: .addNewExtendedAttribute();
657: ea.setName("is_mandatory");
658: if (null != varMandatories
659: && varMandatories[indOf]
660: .equals("false")) {
661:
662: ea.setValue("false()");
663:
664: } else {
665: ea.setValue("true()");
666: }
667: ExtendedAttribute ea1 = eas
668: .addNewExtendedAttribute();
669: ea1.setName("max_length");
670: ea1
671: .setValue(null != varMaxLengths ? ("string-length(.) < "
672: + varMaxLengths[indOf] + "+1")
673: : "string-length(.) < 255");
674: }
675: }
676: }
677:
678: InstanceExtendedAttributes ieas = di
679: .getInstanceExtendedAttributes();
680: if (ieas == null) {
681: ieas = di.addNewInstanceExtendedAttributes();
682: }
683: InstanceExtendedAttribute iea = ieas
684: .addNewInstanceExtendedAttribute();
685: iea.setName("how_to_handle_marker");
686: iea.setValue("1");
687: fillInXPILDataInstance(ins, di);
688: }
689: }
690: }
691: }
692:
693: protected static void fillInXPILDataInstance(
694: ExtendedWorkflowFacilityInstance ins, XPILDataInstance dins)
695: throws Exception {
696: if (dins instanceof BooleanDataInstance) {
697: BooleanDataInstance[] dia = ins
698: .getBooleanDataInstanceArray();
699: List l = new ArrayList(Arrays.asList(dia));
700: l.add(dins);
701: dia = new BooleanDataInstance[l.size()];
702: l.toArray(dia);
703: ins.setBooleanDataInstanceArray(dia);
704: } else if (dins instanceof BooleanArrayDataInstance) {
705: BooleanArrayDataInstance[] dia = ins
706: .getBooleanArrayDataInstanceArray();
707: List l = new ArrayList(Arrays.asList(dia));
708: l.add(dins);
709: dia = new BooleanArrayDataInstance[l.size()];
710: l.toArray(dia);
711: ins.setBooleanArrayDataInstanceArray(dia);
712: } else if (dins instanceof ComplexDataInstance) {
713: ComplexDataInstance[] dia = ins
714: .getComplexDataInstanceArray();
715: List l = new ArrayList(Arrays.asList(dia));
716: l.add(dins);
717: dia = new ComplexDataInstance[l.size()];
718: l.toArray(dia);
719: ins.setComplexDataInstanceArray(dia);
720: } else if (dins instanceof DateDataInstance) {
721: DateDataInstance[] dia = ins.getDateDataInstanceArray();
722: List l = new ArrayList(Arrays.asList(dia));
723: l.add(dins);
724: dia = new DateDataInstance[l.size()];
725: l.toArray(dia);
726: ins.setDateDataInstanceArray(dia);
727: } else if (dins instanceof DateArrayDataInstance) {
728: DateArrayDataInstance[] dia = ins
729: .getDateArrayDataInstanceArray();
730: List l = new ArrayList(Arrays.asList(dia));
731: l.add(dins);
732: dia = new DateArrayDataInstance[l.size()];
733: l.toArray(dia);
734: ins.setDateArrayDataInstanceArray(dia);
735: } else if (dins instanceof DoubleDataInstance) {
736: DoubleDataInstance[] dia = ins.getDoubleDataInstanceArray();
737: List l = new ArrayList(Arrays.asList(dia));
738: l.add(dins);
739: dia = new DoubleDataInstance[l.size()];
740: l.toArray(dia);
741: ins.setDoubleDataInstanceArray(dia);
742: } else if (dins instanceof DoubleArrayDataInstance) {
743: DoubleArrayDataInstance[] dia = ins
744: .getDoubleArrayDataInstanceArray();
745: List l = new ArrayList(Arrays.asList(dia));
746: l.add(dins);
747: dia = new DoubleArrayDataInstance[l.size()];
748: l.toArray(dia);
749: ins.setDoubleArrayDataInstanceArray(dia);
750: } else if (dins instanceof LongDataInstance) {
751: LongDataInstance[] dia = ins.getLongDataInstanceArray();
752: List l = new ArrayList(Arrays.asList(dia));
753: l.add(dins);
754: dia = new LongDataInstance[l.size()];
755: l.toArray(dia);
756: ins.setLongDataInstanceArray(dia);
757: } else if (dins instanceof LongArrayDataInstance) {
758: LongArrayDataInstance[] dia = ins
759: .getLongArrayDataInstanceArray();
760: List l = new ArrayList(Arrays.asList(dia));
761: l.add(dins);
762: dia = new LongArrayDataInstance[l.size()];
763: l.toArray(dia);
764: ins.setLongArrayDataInstanceArray(dia);
765: } else if (dins instanceof SchemaDataInstance) {
766: SchemaDataInstance[] dia = ins.getSchemaDataInstanceArray();
767: List l = new ArrayList(Arrays.asList(dia));
768: l.add(dins);
769: dia = new SchemaDataInstance[l.size()];
770: l.toArray(dia);
771: ins.setSchemaDataInstanceArray(dia);
772: } else if (dins instanceof StringDataInstance) {
773: StringDataInstance[] dia = ins.getStringDataInstanceArray();
774: List l = new ArrayList(Arrays.asList(dia));
775: l.add(dins);
776: dia = new StringDataInstance[l.size()];
777: l.toArray(dia);
778: ins.setStringDataInstanceArray(dia);
779: } else if (dins instanceof StringArrayDataInstance) {
780: StringArrayDataInstance[] dia = ins
781: .getStringArrayDataInstanceArray();
782: List l = new ArrayList(Arrays.asList(dia));
783: l.add(dins);
784: dia = new StringArrayDataInstance[l.size()];
785: l.toArray(dia);
786: ins.setStringArrayDataInstanceArray(dia);
787: } else if (dins instanceof ByteArrayDataInstance) {
788: ByteArrayDataInstance[] dia = ins
789: .getByteArrayDataInstanceArray();
790: List l = new ArrayList(Arrays.asList(dia));
791: l.add(dins);
792: dia = new ByteArrayDataInstance[l.size()];
793: l.toArray(dia);
794: ins.setByteArrayDataInstanceArray(dia);
795: }
796:
797: }
798: }
|