KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > repository > actions > UploadPackage


1 package org.enhydra.shark.swingclient.workflowadmin.repository.actions;
2
3
4
5 import org.enhydra.shark.api.client.wfservice.*;
6
7 import java.awt.event.*;
8 import javax.swing.*;
9 import java.io.*;
10 import java.util.*;
11
12 import org.enhydra.shark.swingclient.*;
13 import org.enhydra.shark.swingclient.workflowadmin.*;
14 import org.enhydra.shark.swingclient.workflowadmin.repository.*;
15 import org.enhydra.jawe.xml.XMLUtil;
16
17 /**
18  * Uploads the package the wanted location into engine repository.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class UploadPackage extends ActionBase {
24
25    public UploadPackage (RepositoryManagement rpm) {
26       super(rpm);
27    }
28
29    public void actionPerformed(ActionEvent e) {
30       RepositoryManagement rpm=(RepositoryManagement)actionPanel;
31       SharkAdmin workflowAdmin=rpm.getWorkflowAdmin();
32       String JavaDoc pkgToUpload=XMLUtil.dialog(workflowAdmin.getFrame(),
33             ResourceManager.getLanguageDependentString("MessageChoosePackageFileToUpload")
34             ,0,0,"");
35       if (pkgToUpload==null) return;
36       String JavaDoc errMsg=null;
37       String JavaDoc xpdlReport=null;
38       boolean invalidPackage=false;
39
40       try {
41          File pkgFile=new File(pkgToUpload);
42          RandomAccessFile raf=new RandomAccessFile(pkgFile,"r");
43          byte[] utf8Bytes=null;
44          long noOfBytes=raf.length();
45          if (noOfBytes>0) {
46             utf8Bytes=new byte[(int)noOfBytes];
47             raf.seek(0);
48             raf.readFully(utf8Bytes);
49          }
50          if (utf8Bytes!=null) {
51             UploadedPackageRelativePath uprp=new UploadedPackageRelativePath(
52                   workflowAdmin.getFrame(),pkgFile.getName());
53             uprp.showDialog();
54             String JavaDoc rPath=uprp.getRelativeFilePath();
55             if (rPath==null) {
56                return;
57             } else {
58                SharkAdmin.getRepositoryManager().uploadPackage(utf8Bytes,rPath);
59             }
60
61             rpm.refresh(true);
62          }
63       } catch (RepositoryInvalid ri) {
64          invalidPackage=true;
65          xpdlReport=ri.getXPDLValidationErrors();
66          errMsg=ResourceManager.getLanguageDependentString("ErrorThePackageIsInvalid");
67       } catch (Exception JavaDoc ex) {
68          errMsg=ResourceManager.getLanguageDependentString("ErrorCannotUploadSelectedPackageFileAtTheMoment");
69       }
70
71       if (errMsg!=null) {
72          JOptionPane.showMessageDialog(workflowAdmin.getFrame(),errMsg,
73                workflowAdmin.getAppTitle(),JOptionPane.ERROR_MESSAGE);
74       }
75
76       if (invalidPackage) {
77          workflowAdmin.showXPDLErrorsReport(xpdlReport);
78       }
79
80    }
81
82 }
83
Popular Tags