KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CompBundleMap.java
3  *
4  * Created on 23. listopad 2003, 19:44
5  */

6
7 package SOFA.SOFAnet.Repository;
8
9 import java.util.*;
10 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl;
11
12 /**
13  * Map between names of components and names of bundles.
14  * It maintain the information which component belongs to which bundle.
15  * It is used to quick look up of the bundle (or bundle offer) that contains concrete component
16  *
17  * @author Ladislav Sobr
18  */

19 public class CompBundleMap
20 {
21   public Map map;
22   
23   /** Creates a new instance of CompBundleMap */
24   public CompBundleMap()
25   {
26     map = Collections.synchronizedMap(new HashMap());
27   }
28   
29   /**
30    * Returns name of bundle that contains specified component
31    * @param componentFullName full name of component in format name[version]
32    * @return name of bundle or null if no bundle found
33    */

34   public String JavaDoc findBundle(String JavaDoc componentFullName)
35   {
36     return (String JavaDoc)map.get(componentFullName);
37   }
38   
39   /**
40    * Adds records to the map - components of one bundle/
41    * @param components list of components (ComponentInfoImpl class)
42    * @param bundleName name of bundle
43    */

44   public void addComponents(List components, String JavaDoc bundleName)
45   {
46     synchronized (map)
47     {
48       synchronized (components)
49       {
50         Iterator it = components.iterator();
51         while (it.hasNext())
52         {
53           String JavaDoc componentName = ((ComponentInfoImpl)it.next()).toString();
54           map.put(componentName, bundleName);
55         }
56       }
57     }
58   }
59
60   /**
61    * Adds records to the map - they are taken from bundle content
62    * @param bundleContent content of the bundle to add
63    */

64   public void addBundleContent(BundleContent bundleContent)
65   {
66     List components = bundleContent.getComponents();
67     String JavaDoc bundleName = bundleContent.getName();
68     addComponents(components, bundleName);
69   }
70   
71   /**
72    * Adds records to the map - they are taken from bundle offer
73    * @param bundleOffer bundle offer to add
74    */

75   public void addBundleOffer(BundleOffer bundleOffer)
76   {
77     List components = bundleOffer.getComponents();
78     String JavaDoc bundleName = bundleOffer.getName();
79     addComponents(components, bundleName);
80   }
81   
82   /**
83    * Removes all records from the map that are connected with this name of bundle.
84    * In fact it removes content of such bundle
85    * @param bundleName name of bundle to delete
86    */

87   public void deleteBundle(String JavaDoc bundleName)
88   {
89     synchronized (map)
90     {
91       Iterator it = map.values().iterator();
92       while (it.hasNext())
93       {
94         String JavaDoc name = (String JavaDoc)it.next();
95         if (name.compareTo(bundleName) == 0) it.remove();
96       }
97     }
98   }
99   
100 }
101
Popular Tags