001: package hero.client.xpdl;
002:
003: import java.io.BufferedReader;
004: import java.io.File;
005: import java.io.FileNotFoundException;
006: import java.io.IOException;
007: import java.rmi.RemoteException;
008:
009: import javax.ejb.CreateException;
010: import javax.naming.NamingException;
011: import javax.security.auth.login.LoginContext;
012: import javax.security.auth.login.LoginException;
013:
014: import hero.client.test.SimpleCallbackHandler;
015:
016: import hero.interfaces.XPDLSessionImportUtil;
017: import hero.interfaces.XPDLSessionImportHome;
018: import hero.interfaces.XPDLSessionImport;
019:
020: /**
021: * @author Blachon Marc
022: */
023: public class XPDLStartImport {
024:
025: public static void main(String[] args) {
026:
027: String user = "admin";
028: char[] password = { 't', 'o', 't', 'o' };
029: String filename = null;
030:
031: // Get args
032: for (int argn = 0; argn < args.length; argn++) {
033: String arg = args[argn];
034: if (arg.equals("-user")) {
035: argn++;
036: if (argn < args.length) {
037: user = args[argn];
038: }
039: continue;
040: }
041: if (arg.equals("-passwd")) {
042: argn++;
043: if (argn < args.length) {
044: String spwd = args[argn];
045: password = new char[spwd.length()];
046: for (int i = 0; i < spwd.length(); i++) {
047: password[i] = spwd.charAt(i);
048: }
049: }
050: continue;
051: }
052: if (arg.equals("-xpdl")) {
053: argn++;
054: if (argn < args.length) {
055: filename = args[argn];
056: }
057: continue;
058: }
059: }
060:
061: if (filename == null) {
062: System.err
063: .println("Error: The xpdl file name argument is mandatory");
064: System.exit(-1);
065: }
066:
067: XPDLSessionImportHome home = null;
068: XPDLSessionImport xpdl = null;
069:
070: // Admin login
071: SimpleCallbackHandler handler = new SimpleCallbackHandler(user,
072: password);
073: try {
074: LoginContext lc = new LoginContext("TestClient", handler);
075: lc.login();
076: } catch (LoginException he) {
077: System.err.println("Error while login for the client : "
078: + he.getMessage());
079: he.printStackTrace();
080: System.exit(-1);
081: }
082:
083: // Context ctx= new InitialContext();
084: try {
085: home = (XPDLSessionImportHome) XPDLSessionImportUtil
086: .getHome();
087: } catch (NamingException na) {
088: System.err
089: .println("Error obtaining the remote home interface for XPDLSessionImport Bean : "
090: + na.getMessage());
091: na.printStackTrace();
092: System.exit(-1);
093: }
094: try {
095: xpdl = home.create();
096: } catch (CreateException re) {
097: System.err.println("There was the following exception : "
098: + re.getMessage());
099: re.printStackTrace();
100: System.exit(-1);
101: } catch (RemoteException re) {
102: System.err.println("There was the following exception : "
103: + re.getMessage());
104: re.printStackTrace();
105: System.exit(-1);
106: }
107:
108: // Trace Start of the XPDL import
109: System.out
110: .println("******* Start of XPDL import into Bonita Workflow Engine ********");
111: /*
112: * ClassLoader cl = XPDLStartImport.class.getClassLoader();
113: * java.io.InputStreamReader file = new
114: * java.io.InputStreamReader(cl.getResourceAsStream("xpdl-files/Business_Example.xpdl"));
115: * java.io.BufferedReader buff = new java.io.BufferedReader(file);
116: */
117: BufferedReader buff = null;
118:
119: try {
120: buff = new java.io.BufferedReader(new java.io.FileReader(
121: filename));
122: } catch (FileNotFoundException e) {
123: System.err
124: .println("Cannot find the file for the xpdl document : "
125: + e.getMessage());
126: e.printStackTrace();
127: System.exit(-1);
128: }
129: String line, xpdl_file = "";
130: try {
131: line = buff.readLine();
132: while ((line = buff.readLine()) != null)
133: xpdl_file = xpdl_file + line;
134: } catch (IOException e) {
135: System.err.println("Exception while reading lines : "
136: + e.getMessage());
137: e.printStackTrace();
138: System.exit(-1);
139: }
140:
141: try {
142: String absoluteName = (new File(filename))
143: .getAbsolutePath();
144: String repositoryName = (new File(absoluteName))
145: .getParent();
146: String baseName = (new File(absoluteName)).getName();
147: //call with trace debugging
148: String project = xpdl.openMainDocument(repositoryName,
149: baseName, xpdl_file, true);
150:
151: // Trace Start of the XPDL import
152: System.out
153: .println("******* End of XPDL import into Bonita Workflow Engine *******");
154: //xpdl.printHashTables();
155: } catch (Exception e) {
156: System.err.println("Error during XPDL import operation : "
157: + e.getMessage());
158: e.printStackTrace();
159: System.exit(-1);
160: }
161:
162: catch (Throwable exc) {
163:
164: System.err.println("Runtime Exception caught !");
165: exc.printStackTrace();
166: }
167:
168: }
169: }
|