View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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          // debug classpath problems for lamers. 
77      // added by simon 21/08/00
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          // obscure zeus class picked to try it 
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   /*   try {
92           Class c = Class.forName("gnu.regexp.REException"); 
93      }
94      catch (ClassNotFoundException cnfe) { 
95         System.out.println("Java cannot find a utility object.\n This indicates that the gnu-regexp.jar file is not in your classpath.\n Ensure that $zeus_install_dir//lib//gnu-regexp.jar is present in the classpath and then continue");
96              cnfe.printStackTrace();}*/
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 }