1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /*********************************************************************
25 * Visualiser.java - this creates and launches the Visualiser Hub *
26 ********************************************************************/
27
28 package zeus.visualiser;
29
30 import java.util.*;
31 import java.io.*;
32
33 import zeus.util.*;
34 import zeus.concepts.*;
35 import zeus.actors.*;
36 import zeus.agents.*;
37
38
39 public class Visualiser extends BasicAgent {
40 public Visualiser(String name, String filename, Vector nameservers,
41 boolean quickflag) {
42 super(SystemProps.getProperty("agent.names.visualiser"),
43 name, nameservers);
44
45 context.set(new OntologyDb(context.GenSym()));
46 context.MailBox().lowerStatus();
47 context.MsgHandler().lowerStatus();
48
49 if ( filename != null ) {
50 OntologyDb db = context.OntologyDb();
51 int status = db.openFile(new File(filename));
52 if ( (status & OntologyDb.ERROR_MASK) != 0 ) {
53 System.err.println("Ontology File I/O Error: " + db.getError());
54 System.exit(0);
55 }
56 else if ( (status & OntologyDb.WARNING_MASK) != 0 )
57 System.err.println("Warning: " + db.getWarning());
58 }
59 new VisualiserHub(context,quickflag);
60 }
61
62 protected static void version() {
63 System.err.println("Visualiser version: " +
64 SystemProps.getProperty("version.id"));
65 System.exit(0);
66 }
67
68 protected static void usage() {
69 System.err.println("Usage: java Visualiser <name> -s <dns_file> " +
70 "[-o ontology_file] [-gui ViewerProg] " +
71 "[-e ExternalProg] [-quick] [-debug] [-h] [-v]");
72 System.exit(0);
73 }
74
75 public static void main(String[] arg){
76
77
78 try {
79 Class c = Class.forName("java.lang.Object");
80 }
81 catch (ClassNotFoundException cnfe) {
82 System.out.println("Java cannot find java.lang.Object.\n This indicates that the rt.jar file is not in your classpath.\n Ensure that $java_install_dir//jre//rt.jar is present in the classpath and then continue");
83 cnfe.printStackTrace();}
84 try {
85
86 Class c = Class.forName("zeus.gui.help.HelpWindow");
87 }
88 catch (ClassNotFoundException cnfe) {
89 System.out.println("Java cannot find a zeus class.\n This indicates that the zeus.jar file is not in your classpath.\n Ensure that zeus_install_dir//lib//zeus.jar is present in the classpath and then continue");
90 cnfe.printStackTrace();}
91
92
93
94
95
96
97
98 Vector nameservers = null;
99 String dns_file = null;
100 String ontology_file = null;
101 String gui = null;
102 boolean quick = false;
103 String external = null;
104
105 if ( arg.length < 3 ) usage();
106 else
107 for( int i = 1; i < arg.length; i++ ) {
108 if ( arg[i].equals("-s") && ++i < arg.length )
109 dns_file = arg[i];
110 else if ( arg[i].equals("-o") && ++i < arg.length )
111 ontology_file = arg[i];
112 else if ( arg[i].equals("-e") && ++i < arg.length )
113 external = arg[i];
114 else if ( arg[i].equals("-gui") && ++i < arg.length )
115 gui = arg[i];
116 else if ( arg[i].equals("-quick") )
117 quick = true;
118 else if ( arg[i].equals("-debug") ) {
119 Core.debug = true;
120 Core.setDebuggerOutputFile(arg[0] + ".log");
121 }
122 else if ( arg[i].equals("-h") )
123 usage();
124 else if ( arg[i].equals("-v") )
125 version();
126 else
127 usage();
128 }
129
130 try {
131 nameservers = ZeusParser.addressList(new FileInputStream(dns_file));
132 if ( nameservers == null || nameservers.isEmpty() )
133 throw new IOException();
134
135 Visualiser f = new Visualiser(arg[0],ontology_file,nameservers,quick);
136
137 Class c;
138 if ( gui != null ) {
139 c = Class.forName(gui);
140 BasicAgentUI ui = (BasicAgentUI) c.newInstance();
141 ui.set(f.getAgentContext());
142 }
143
144 if ( external != null ) {
145 c = Class.forName(external);
146 ZeusExternal user_prog = (ZeusExternal)c.newInstance();
147 user_prog.exec(f.getAgentContext());
148 }
149
150 }
151 catch(Exception e) {
152 e.printStackTrace();
153 System.exit(0);
154 }
155 }
156 }