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  package zeus.generator.code;
25  
26  import zeus.util.*;
27  /*** 
28    * used to generate the script that runs the facilitator
29    * Change log 
30    * ----------
31    * 26/06/01 removed java from command line
32    */
33  public class FacilitatorInfo extends GenerationInfo {
34     protected static int count = 0;
35     static final String DEFAULT_PERIOD =
36        SystemProps.getProperty("facilitator.period.default");
37  
38     public boolean has_gui = false;
39     public String zeus_external = null;
40     public String period = DEFAULT_PERIOD;
41     public String dns_file = NameserverInfo.DEFAULT_DNS;
42     public String ontology_file = null;
43  
44     public FacilitatorInfo(String file) {
45        name = FACILITATOR + (count++);
46        ontology_file = file;
47     }
48     public FacilitatorInfo(String name, String file) {
49        this.name = name;
50        ontology_file = file;
51     }
52  
53     public String[] summarize() {
54        String[] out = new String[4];
55        out[NAME] = name;
56        out[TYPE] = FACILITATOR;
57        out[ID]   = id;
58  
59        out[COMMAND] = "zeus.agents.Facilitator " + name +
60                       " -o " + ontology_file + " -s " + dns_file +
61  		     " -t " + period;
62        if ( has_gui )
63           out[COMMAND] += " -gui zeus.agentviewer.BasicViewer";
64        if ( zeus_external != null )
65           out[COMMAND] += " -e " + zeus_external;
66  
67        return out;
68     }
69     public String isValid() {
70        String error = null;
71        if ( dns_file == null )
72           error = "Facilitator " + name + ": domain nameserver file not specified\n";
73  
74        return error;
75     }
76  
77     public String toString() {
78        double p = (Double.valueOf(period)).doubleValue();
79        String p_str = Misc.decimalPlaces(p,2);
80  
81        String s = "";
82        s += "(:name " + name;
83        s += " :period " + p_str;
84        s += " :has_gui " + has_gui;
85        if ( host != null && !host.equals(LOCALHOST) )
86           s += " :host \"" + Misc.escape(host) + "\"";
87        if ( zeus_external != null )
88           s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"";
89        if ( dns_file != null )
90           s += " :dns_file \"" + Misc.escape(dns_file) + "\"";
91        s += ")";
92        return s;
93     }
94  
95     public String pprint(int sp) {
96        String tabs = Misc.spaces(sp);
97        String eol  = "\n" + tabs;
98        double p = (Double.valueOf(period)).doubleValue();
99        String p_str = Misc.decimalPlaces(p,2);
100 
101       String s = tabs;
102       s += "(:name " + name + eol;
103       s += " :period " + p_str + eol;
104       s += " :has_gui " + has_gui + eol;
105       if ( host != null && !host.equals(LOCALHOST) )
106          s += " :host \"" + Misc.escape(host) + "\"" + eol;
107       if ( zeus_external != null )
108          s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"" + eol;
109       if ( dns_file != null )
110          s += " :dns_file \"" + Misc.escape(dns_file) + "\"" + eol;
111       s += ")";
112       return s;
113    }
114 }