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  public class DbProxyInfo extends GenerationInfo {
29     protected static int count = 0;
30  
31     public boolean has_gui = false;
32     public String zeus_external = null;
33     public String path = null;
34     public String dns_file = NameserverInfo.DEFAULT_DNS;
35  
36     public DbProxyInfo() {
37        name = DBPROXY + (count++);
38     }
39     public DbProxyInfo(String name) {
40        this.name = name;
41     }
42  
43     public String[] summarize() {
44        String[] out = new String[4];
45        out[NAME] = name;
46        out[TYPE] = DBPROXY;
47        out[ID]   = id;
48  
49        out[COMMAND] = "java zeus.agents.DbProxy " + name +
50                       " -p " + path + " -s " + dns_file;
51        if ( has_gui )
52           out[COMMAND] += " -gui zeus.agentviewer.BasicViewer";
53        if ( zeus_external != null )
54           out[COMMAND] += " -e " + zeus_external;
55  
56        return out;
57     }
58     public String isValid() {
59        String error = "";
60        if ( path == null )
61           error += "DbProxy " + name + ": path not specified\n";
62        if ( dns_file == null )
63           error += "DbProxy " + name + ": domain nameserver file not specified\n";
64  
65        if ( error.equals("") ) return null;
66        return error;
67     }
68  
69     public String toString() {
70        String s = "";
71        s += "(:name " + name;
72        s += " :has_gui " + has_gui;
73        if ( host != null && !host.equals(LOCALHOST) )
74           s += " :host \"" + Misc.escape(host) + "\"";
75        if ( zeus_external != null )
76           s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"";
77        if ( dns_file != null )
78           s += " :dns_file \"" + Misc.escape(dns_file) + "\"";
79        if ( path != null )
80           s += " :path \"" + Misc.escape(path) + "\"";
81        s += ")";
82        return s;
83     }
84  
85     public String pprint(int sp) {
86        String tabs = Misc.spaces(sp);
87        String eol  = "\n" + tabs;
88  
89        String s = tabs;
90        s += "(:name " + name + eol;
91        s += " :has_gui " + has_gui + eol;
92        if ( host != null && !host.equals(LOCALHOST) )
93           s += " :host \"" + Misc.escape(host) + "\"" + eol;
94        if ( zeus_external != null )
95           s += " :zeus_external \"" + Misc.escape(zeus_external) + "\"" + eol;
96        if ( dns_file != null )
97           s += " :dns_file \"" + Misc.escape(dns_file) + "\"" + eol;
98        if ( path != null )
99           s += " :path \"" + Misc.escape(path) + "\"" + eol;
100       s += ")";
101       return s;
102    }
103 }