KickJava   Java API By Example, From Geeks To Geeks.

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


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

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