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  /*** 
29    *  this class is used to generate the script for the agent nameserver
30    *  Change Log
31    *  ----------
32    *  26/6/01 - removed the "java" bit as this is now done by the scriptwriter
33      */
34  public class NameserverInfo extends GenerationInfo {
35     protected static int count = 0;
36     static final String DEFAULT_DNS =
37        SystemProps.getProperty("nameserver.dns.default");
38     static final String DEFAULT_PERIOD =
39        SystemProps.getProperty("nameserver.period.default");
40  
41     public boolean is_root;
42     public boolean has_gui;
43     public String zeus_external = null;
44     public String address_output_file;
45     public String time_grain;
46     public String dns_file;
47  
48     public NameserverInfo() {
49        this(NAMESERVER + (count++));
50     }
51  
52     public NameserverInfo(String name) {
53        this.name = name;
54        is_root = (count == 1);
55        has_gui = false;
56        zeus_external = null;
57        if ( is_root ) {
58           address_output_file = DEFAULT_DNS;
59           time_grain = DEFAULT_PERIOD;
60           dns_file = null;
61        }
62        else {
63           address_output_file = null;
64           time_grain = null;
65           dns_file = DEFAULT_DNS;
66        }
67     }
68     public NameserverInfo(String name, boolean is_root) {
69        this.name = name;
70        this.is_root = is_root;
71        has_gui = false;
72        zeus_external = null;
73        if ( is_root ) {
74           address_output_file = DEFAULT_DNS;
75           time_grain = DEFAULT_PERIOD;
76           dns_file = null;
77        }
78        else {
79           address_output_file = null;
80           time_grain = null;
81           dns_file = DEFAULT_DNS;
82        }
83     }
84  
85  
86     public String[] summarize() {
87        String[] out = new String[4];
88        out[NAME] = name;
89        out[TYPE] = NAMESERVER;
90        out[ID]   = id;
91          // simon removed java 26/6/01
92        out[COMMAND] = "zeus.agents.ANServer " + name;
93  
94        if ( dns_file != null )
95           out[COMMAND] += " -s " + dns_file;
96        if ( is_root )
97           out[COMMAND] += " -t " + time_grain;
98        if ( address_output_file != null )
99           out[COMMAND] += " -f " + address_output_file;
100       if ( has_gui )
101          out[COMMAND] += " -gui zeus.agentviewer.BasicViewer";
102       if ( zeus_external != null )
103          out[COMMAND] += " -e " + zeus_external;
104 
105       return out;
106    }
107    public String isValid() {
108       String error = null;
109       if ( !is_root && dns_file == null )
110          error = "Nameserver " + name + ": (not root) and domain nameserver file not specified\n";
111 
112       return error;
113    }
114 
115    public String toString() {
116       String s = "";
117       s += "(:name " + name;
118       s += " :is_root " + is_root;
119       s += " :has_gui " + has_gui;
120       if ( host != null && !host.equals(LOCALHOST) )
121          s += " :host \"" + Misc.escape(host) + "\"";
122       if ( zeus_external != null )
123          s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"";
124       if ( dns_file != null )
125          s += " :dns_file \"" + Misc.escape(dns_file) + "\"";
126       if ( address_output_file != null )
127          s += " :address_output_file \"" + Misc.escape(address_output_file) + "\"";
128       if ( time_grain != null )
129          s += " :time_grain " + time_grain;
130       s += ")";
131       return s;
132    }
133 
134    public String pprint(int sp) {
135       String tabs = Misc.spaces(sp);
136       String eol  = "\n" + tabs;
137 
138       String s = tabs;
139       s += "(:name " + name + eol;
140       s += " :is_root " + is_root + eol;
141       s += " :has_gui " + has_gui + eol;
142       if ( host != null && !host.equals(LOCALHOST) )
143          s += " :host \"" + Misc.escape(host) + "\"" + eol;
144       if ( zeus_external != null )
145          s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"" + eol;
146       if ( dns_file != null )
147          s += " :dns_file \"" + Misc.escape(dns_file) + "\"" + eol;
148       if ( address_output_file != null )
149          s += " :address_output_file \"" + Misc.escape(address_output_file) + "\"" + eol;
150       if ( time_grain != null )
151          s += " :time_grain " + time_grain + eol;
152       s += ")";
153       return s;
154    }
155 }