KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Repository


1 /*
2  * Repository.java
3  *
4  * Created on 19. bøezen 2004, 21:12
5  */

6
7 package SOFA.SOFAnet.Repository;
8
9 import java.io.*;
10 import SOFA.SOFAnet.Core.Reporter;
11
12 /**
13  * Repository of node of SOFAnet.
14  *
15  * @author Ladislav Sobr
16  */

17 public class Repository
18 {
19   private final File infoBaseDir;
20   
21   private BinBundles binBundles;
22   private BundleContents installedBundleContents;
23   private InputTriggers inputTriggers;
24   private OutputTriggers outputTriggers;
25   private Contracts contracts;
26   private LocalInfos localInfos;
27   private Licences licences;
28   private BundleOffers bundleOffers;
29   private BinBundles shareClientCache;
30   private BundleContents sharedBundleContents;
31   
32   //REMARK: Do not change the order of the repository-members.
33
//The order is important to prevent deadlock,
34
//because everybody must lock the repository-members in this order!
35

36   
37   /**
38    * Creates a new instance of Repository
39    *
40    * @param infoBaseDir directory for general information (must exist)
41    * @param binBundlesDir directory for binary bundles (must exist)
42    * @param shareClientCacheDir directory for binary bundles in cache of share client (must exist)
43    */

44   public Repository(File infoBaseDir, File binBundlesDir, File shareClientCacheDir)
45   {
46     this.infoBaseDir = infoBaseDir;
47     
48     File installedBundlesDir = new File(infoBaseDir, "installed_bundles");
49     File inputTriggersDir = new File(infoBaseDir, "input_triggers");
50     File outputTriggersDir = new File(infoBaseDir, "output_triggers");
51     File contractsDir = new File(infoBaseDir, "contracts");
52     File localInfosDir = new File(infoBaseDir, "local_infos");
53     File licencesDir = new File(infoBaseDir, "licences");
54     File bundleOffersDir = new File(infoBaseDir, "bundle_offers");
55     File sharedBundlesDir = new File(infoBaseDir, "shared_bundles");
56     
57     if (infoBaseDir.exists() && infoBaseDir.isDirectory())
58     {
59       if (!installedBundlesDir.exists()) installedBundlesDir.mkdir();
60       if (!inputTriggersDir.exists()) inputTriggersDir.mkdir();
61       if (!outputTriggersDir.exists()) outputTriggersDir.mkdir();
62       if (!contractsDir.exists()) contractsDir.mkdir();
63       if (!localInfosDir.exists()) localInfosDir.mkdir();
64       if (!licencesDir.exists()) licencesDir.mkdir();
65       if (!bundleOffersDir.exists()) bundleOffersDir.mkdir();
66       if (!sharedBundlesDir.exists()) sharedBundlesDir.mkdir();
67     }
68     else
69     {
70       Reporter.error("Cannot open directory '" + infoBaseDir);
71     }
72     
73     binBundles = new BinBundles(binBundlesDir);
74     installedBundleContents = new BundleContents(installedBundlesDir);
75     inputTriggers = new InputTriggers(inputTriggersDir);
76     outputTriggers = new OutputTriggers(outputTriggersDir);
77     contracts = new Contracts(contractsDir);
78     localInfos = new LocalInfos(localInfosDir);
79     licences = new Licences(licencesDir);
80     bundleOffers = new BundleOffers(bundleOffersDir);
81     shareClientCache = new BinBundles(shareClientCacheDir);
82     sharedBundleContents = new BundleContents(sharedBundlesDir);
83   }
84   
85   public File getInfoBaseDir()
86   {
87     return infoBaseDir;
88   }
89     
90   public BinBundles getBinBundles()
91   {
92     return binBundles;
93   }
94
95   public BundleContents getInstalledBundleContents()
96   {
97     return installedBundleContents;
98   }
99   
100   public InputTriggers getInputTriggers()
101   {
102     return inputTriggers;
103   }
104   
105   public OutputTriggers getOutputTriggers()
106   {
107     return outputTriggers;
108   }
109   
110   public Contracts getContracts()
111   {
112     return contracts;
113   }
114   
115   public LocalInfos getLocalInfos()
116   {
117     return localInfos;
118   }
119   
120   public Licences getLicences()
121   {
122     return licences;
123   }
124   
125   public BundleOffers getBundleOffers()
126   {
127     return bundleOffers;
128   }
129   
130   public BinBundles getShareClientCache()
131   {
132     return shareClientCache;
133   }
134
135   public BundleContents getSharedBundleContents()
136   {
137     return sharedBundleContents;
138   }
139   
140 }
141
Popular Tags