1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * ident "%Z%%M% %I% %E% SMI"
24 *
25 * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28 package com.sun.dhcpmgr.cli.dhtadm;
29
30 import com.sun.dhcpmgr.cli.common.DhcpCliFunction;
31 import com.sun.dhcpmgr.cli.common.Format;
32 import com.sun.dhcpmgr.data.Macro;
33 import com.sun.dhcpmgr.data.Option;
34 import com.sun.dhcpmgr.bridge.NoTableException;
35
36 import java.lang.IllegalArgumentException;
37
38 /**
39 * The main class for the "display table" functionality of dhtadm.
40 */
41 public class DisplayTable extends DhtAdmFunction {
42
43 /**
44 * The valid options associated with displaying the table.
45 */
46 static final int supportedOptions[] = {
47 DhtAdm.RESOURCE,
48 DhtAdm.RESOURCE_CONFIG,
49 DhtAdm.PATH,
50 DhtAdm.SIGHUP
51 };
52
53 /**
54 * Constructs a DisplayTable object.
55 */
56 public DisplayTable() {
57
58 validOptions = supportedOptions;
59
60 } // constructor
61
62 /**
63 * Returns the option flag for this function.
64 * @returns the option flag for this function.
65 */
66 public int getFunctionFlag() {
67 return (DhtAdm.DISPLAY_TABLE);
68 }
69
70 /**
71 * Executes the "display table" functionality.
72 * @return DhtAdm.SUCCESS, DhtAdm.ENOENT, DhtAdm.WARNING, or
73 * DhtAdm.CRITICAL
74 */
75 public int execute()
76 throws IllegalArgumentException {
77
78 int returnCode = DhtAdm.SUCCESS;
79
80 // Retrieve the table contents. Table consists of macros
81 // and options ... go get them.
82 //
83 Macro [] macros = null;
84 Option [] options = null;
85 try {
86 macros = getDhcptabMgr().getMacros(getDhcpDatastore());
87 options = getDhcptabMgr().getOptions(getDhcpDatastore());
88 } catch (NoTableException e) {
89 printErrMessage(getMessage(e));
90 returnCode = DhtAdm.ENOENT;
91 } catch (Throwable e) {
92 printErrMessage(getMessage(e));
93 returnCode = DhtAdm.WARNING;
94 }
95
96 if (returnCode == DhtAdm.SUCCESS) {
97 Format.print(System.out, "%-20s\t", getString("Name"));
98 Format.print(System.out, "%-8s\t", getString("Type"));
99 Format.print(System.out, "%s\n", getString("Value"));
100 Format.print(System.out, "%s\n",
101 "==================================================");
102
103 for (int i = 0; macros != null && i < macros.length; i++) {
104 Macro macro = macros[i];
105 Format.print(System.out, "%-20s\t", macro.getKey());
106 Format.print(System.out, "%-8s\t", getString("Macro"));
107 Format.print(System.out, "%s\n", macro.getValue());
108 }
109
110 for (int i = 0; options != null && i < options.length; i++) {
111 Option option = options[i];
112 Format.print(System.out, "%-20s\t", option.getKey());
113 Format.print(System.out, "%-8s\t", getString("Symbol"));
114 Format.print(System.out, "%s\n", option.getValue());
115 }
116 }
117
118 return (returnCode);
119
120 } // execute
121
122 } // DisplayTable