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 list all the entries in a MySpace registry to standard
10 * output.
11 *
12 * @author A C Davenhall (Edinburgh)
13 * @version Iteration 2.
14 */
15
16 class ListRegistry
17 { public static void main (String argv[])
18 { if (argv.length == 1)
19 {
20
21
22
23
24
25 String registryName = argv[0];
26
27 String registryFileName = registryName + ".reg";
28
29
30
31
32 try
33 { File registryFile = new File(registryFileName);
34 FileInputStream ris = new FileInputStream(registryFile);
35 ObjectInputStream ois = new ObjectInputStream(ris);
36
37
38
39
40 boolean more = true;
41 int count = 0;
42
43 while (more == true)
44 { try
45 { DataItemRecord itemRec = (DataItemRecord)ois.readObject();
46 count = count + 1;
47
48 System.out.println("["
49 + itemRec.getDataItemID() + "] "
50 + itemRec.toString() );
51 }
52 catch (IOException e)
53 { more = false;
54 }
55 catch (ClassNotFoundException cnfe)
56 { more = false;
57 System.out.println("Illegal object in registry file.");
58 }
59 }
60
61 System.out.println(" ");
62 System.out.println("Number of entries = " + count);
63
64
65
66
67 ois.close();
68 }
69 catch (IOException e)
70 { System.out.println("Failure reading the registry file.");
71 }
72 }
73 else
74 { System.out.println("Usage:-");
75 System.out.println(" java ListRegistry registryName");
76 }
77 }
78 }