01: package org.enhydra.shark.test;
02:
03: import java.util.*;
04:
05: import javax.transaction.UserTransaction;
06: import org.enhydra.shark.api.client.wfservice.ExternalPackageInvalid;
07: import org.enhydra.shark.api.client.wfservice.PackageAdministration;
08: import org.enhydra.shark.api.client.wfservice.PackageInvalid;
09: import org.enhydra.shark.api.client.wfservice.SharkConnection;
10: import org.enhydra.shark.client.utilities.SharkInterfaceWrapper;
11: import org.enhydra.shark.utilities.MiscUtilities;
12: import org.enhydra.shark.xpdl.XMLUtil;
13:
14: public class UploadXPDL {
15:
16: static String username = "admin";
17:
18: static String pwd = "enhydra";
19:
20: public static void main(String[] args) throws Exception {
21:
22: String confF = args[0];
23:
24: List xpdlsToLoad = new ArrayList();
25: for (int i = 1; i < args.length; i++) {
26: xpdlsToLoad.add(args[i]);
27: }
28:
29: try {
30: SharkInterfaceWrapper.setProperties(confF, true);
31: SharkInterfaceWrapper.getShark();
32: } catch (Throwable ex) {
33: ex.printStackTrace();
34: return;
35: }
36:
37: UserTransaction ut = SharkInterfaceWrapper.getUserTransaction();
38: ut.begin();
39:
40: SharkConnection sc = SharkInterfaceWrapper.getSharkConnection(
41: username, null);
42: ut.commit();
43:
44: PackageAdministration pa = SharkInterfaceWrapper.getShark()
45: .getPackageAdministration();
46:
47: try {
48: ut.begin();
49:
50: Iterator it = xpdlsToLoad.iterator();
51:
52: while (it.hasNext()) {
53: String nextXPDL = (String) it.next();
54: if (!SharkInterfaceWrapper.getShark()
55: .getPackageAdministration().isPackageOpened(
56: sc.getSessionHandle(),
57: XMLUtil.getIdFromFile(nextXPDL))) {
58:
59: if (SharkInterfaceWrapper.getClientType().equals(
60: SharkInterfaceWrapper.CLIENT_TYPE_POJO)) {
61: pa.openPackage(sc.getSessionHandle(), nextXPDL);
62: } else {
63: byte[] utf8Bytes = MiscUtilities
64: .convertFileToByteArray(nextXPDL);
65: if (utf8Bytes != null) {
66: pa.uploadPackage(sc.getSessionHandle(),
67: utf8Bytes);
68: }
69: }
70: }
71: }
72:
73: ut.commit();
74: } catch (Throwable ex) {
75: try {
76: ut.rollback();
77: } catch (Exception e) {
78: }
79:
80: if (ex instanceof PackageInvalid) {
81: System.out.println("PIERRS="
82: + ((PackageInvalid) ex)
83: .getXPDLValidationErrors());
84: }
85: if (ex instanceof ExternalPackageInvalid) {
86: System.out.println("PIERRS="
87: + ((ExternalPackageInvalid) ex)
88: .getXPDLValidationErrors());
89: }
90: ex.printStackTrace();
91: } finally {
92: System.exit(0);
93: }
94: }
95:
96: }
|