KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Repository > BinBundles


1 /*
2  * BinBundles.java
3  *
4  * Created on 22. listopad 2003, 20:51
5  */

6
7 package SOFA.SOFAnet.Repository;
8
9 import java.io.*;
10
11 /**
12  * Storage of binary bundles.
13  *
14  * @author Ladislav Sobr
15  */

16 public class BinBundles extends StorageBase
17 {
18   
19   /** Creates a new instance of BinBundles */
20   public BinBundles(File baseDir)
21   {
22     super(baseDir, "jar", false);
23     init();
24   }
25   
26   protected StorageItem newItem(String JavaDoc name, File file)
27   {
28     BundleInfo bundleInfo = new BundleInfo();
29     try
30     {
31       bundleInfo.fromFilename(name);
32     }
33     catch (BundleInfo.InvalidBundleNameException e)
34     {
35       return null;
36     }
37     bundleInfo.setFile(file);
38     return bundleInfo;
39   }
40
41   /**
42    * Returns requested memory structure of binary bundle
43    *
44    * @return memory structure representing binary bundle; null if not present
45    */

46   public BundleInfo getBinBundle(String JavaDoc bundleName)
47   {
48     return (BundleInfo)map.get(bundleName);
49   }
50   
51   /**
52    * Deletes binary bundle (including file).
53    *
54    * @param bundleName name of bundle
55    * @return true, if binary bundle was found (and deleted)
56    */

57   public boolean deleteBinBundle(String JavaDoc bundleName)
58   {
59     synchronized (map)
60     {
61       BundleInfo bundleInfo = (BundleInfo)map.remove(bundleName);
62       if (bundleInfo != null)
63       {
64         try
65         {
66           bundleInfo.getFile().delete();
67         }
68         catch (Exception JavaDoc e)
69         {
70         }
71         return true;
72       }
73       else return false;
74     }
75   }
76   
77   /**
78    * Adds (creates) new binary bundle (only the memory structure, not the file itself)
79    *
80    * @param bundleName name of bundle
81    * @return BundleInfo, if binary bundle was added (bundleName was correct and there was not already the one with the same name), null otherwise
82    */

83   public BundleInfo addBinBundle(String JavaDoc bundleName)
84   {
85     synchronized (map)
86     {
87       if (map.get(bundleName) != null) return null;
88
89       BundleInfo bundleInfo = new BundleInfo();
90       try
91       {
92         bundleInfo.fromBundleName(bundleName);
93       }
94       catch (BundleInfo.InvalidBundleNameException e)
95       {
96         return null;
97       }
98       
99       bundleInfo.setFile(new File(baseDir, bundleInfo.getFileName() + ".jar"));
100       map.put(bundleName, bundleInfo);
101       return bundleInfo;
102     }
103   }
104 }
105
Popular Tags