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];
22
23 String registryFileName = registryName + ".reg";
24 String registryInitialName = registryName + ".initial";
25
26
27
28
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
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
50
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
62
63
64 for (int loop = 0; loop < inputLines.size(); loop++)
65 {
66
67
68
69
70 String containerName = (String)inputLines.get(loop);
71
72
73
74 itemRec = new DataItemRecord(containerName,
75 loop+1, "none", "sysadmin", creation, creation, 0,
76 DataItemRecord.CON, "permissions");
77
78
79
80
81 reg.addDataItemRecord(itemRec);
82 }
83
84
85
86
87 reg.rewriteRegistryFile();
88
89
90
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 }