View Javadoc

1   package org.astrogrid.mySpace.mySpaceDemo;
2   
3   import java.io.*;
4   import java.util.*;
5   
6   import org.astrogrid.mySpace.mySpaceManager.*;
7   
8   /***
9    * Program to create a new MySpace registry.  The registry is
10   * initialised with top-level user containers and second-level
11   * containers for all the servers which each user can access.
12   * The full names for these containers are read from a file.
13   *
14   * @author A C Davenhall (Edinburgh)
15   * @version Iteration 2.
16   */
17  
18  class CreateRegistry
19  {  public static void main (String argv[])
20     {  if (argv.length == 1)
21        {  String registryName = argv[0]; //argv[0] is "example"
22  
23           String registryFileName = registryName + ".reg";
24           String registryInitialName = registryName + ".initial";
25  
26  //
27  //      Attempt to open the input file from which the initial list
28  //      of top- and second-level containers are to be read.
29  
30           try
31           {  File registryInitialFile = new File(registryInitialName);
32              FileReader in = new FileReader(registryInitialFile);
33              char c[] = new char[(int)registryInitialFile.length()];
34              in.read(c);
35              String s = new String(c);
36  
37  //
38  //         Convert the input file into a vector of individual lines.
39  
40              Vector inputLines = new Vector();
41  
42              StringTokenizer token = new StringTokenizer(s, "\n");
43  
44              while(token.hasMoreTokens())
45              {  inputLines.add(token.nextToken());
46              }
47  
48  //
49  //         Create a registry manager to which the new entries will be
50  //         written.
51  
52              RegistryManager reg = new RegistryManager(registryName,
53                "new");
54  
55              DataItemRecord itemRec = new DataItemRecord();
56  
57              Date creation = new Date();
58              creation = Calendar.getInstance().getTime();
59  
60  //
61  //         Loop through the lines read from the input file creating an
62  //         entry in the registry for each one.
63  
64              for (int loop = 0; loop < inputLines.size(); loop++)
65              {
66  
67  //
68  //            Create an entry for the current entry.
69  
70                 String containerName = (String)inputLines.get(loop);
71  //               System.out.println("loop, containerName: "
72  //                 + loop + " " + containerName);
73  
74                 itemRec = new DataItemRecord(containerName,
75                   loop+1, "none", "sysadmin", creation, creation, 0,
76                   DataItemRecord.CON, "permissions");
77  
78  //
79  //            Add the entry to the registry.
80  
81                 reg.addDataItemRecord(itemRec);
82              }
83  
84  //
85  //         Write the registry file to disk.
86  
87              reg.rewriteRegistryFile();
88  
89  //
90  //         Close the input file.
91  
92              in.close();
93           }
94           catch (java.io.IOException ex)
95           {  System.out.println(
96                "Failed to read registry initialisation file " +
97                registryInitialName);
98  
99              ex.printStackTrace();
100          }
101       }
102       else
103       {  System.out.println("Usage:-");
104          System.out.println("  java CreateRegistry registryName");
105       }
106    }
107 }