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.pntadm;
29
30 import com.sun.dhcpmgr.cli.common.DhcpCliFunction;
31 import com.sun.dhcpmgr.cli.common.DhcpCliPrint;
32 import com.sun.dhcpmgr.data.DhcpdOptions;
33 import com.sun.dhcpmgr.bridge.BridgeException;
34
35 import java.text.DateFormat;
36 import java.text.SimpleDateFormat;
37
38 /**
39 * Abstract class implemented by all the pntadm "function" classes.
40 */
41 public abstract class PntAdmFunction
42 extends DhcpCliFunction {
43
44 /**
45 * Short date format for printing/parsing lease expiration
46 */
47 DateFormat shortFormat = new SimpleDateFormat("MM/dd/yyyy");
48
49 /**
50 * Verbose date format for printing/parsing lease expiration.
51 */
52 DateFormat verboseFormat =
53 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
54
55 /**
56 * The network on which the functions should "operate"
57 */
58 String networkName = null;
59
60 /**
61 * Sets the networkName.
62 * @param network name of the network
63 */
64 public void setNetworkName(String network) {
65
66 networkName = network;
67
68 } // setNetworkName
69
70 /**
71 * Returns a localized string for this function
72 * @param key the resource bundle string identifier
73 */
74 public String getString(String key) {
75
76 return ResourceStrings.getString(key);
77
78 } // getString
79
80 /**
81 * Returns whether or not hosts table is manageable.
82 * @return whether or not hosts table is manageable.
83 */
84 public boolean isHostsManaged() {
85
86 boolean result = false;
87
88 try {
89 DhcpdOptions opts =
90 getSvcMgr().readDefaults();
91 if (opts.getHostsResource() != null) {
92 result = true;
93 } else {
94 throw new BridgeException();
95 }
96 } catch (BridgeException e) {
97 printErrMessage(getString("no_host_resource_warning"));
98 }
99
100 return result;
101
102 } // isHostsManaged
103
104 /**
105 * Prints an error message.
106 * @param msg the message to print.
107 */
108 public void printErrMessage(String msg) {
109 StringBuffer fullmsg = new StringBuffer(PntAdm.SIGNATURE);
110 fullmsg.append(msg);
111 DhcpCliPrint.printErrMessage(fullmsg.toString());
112 } // printErrMessage
113
114 } // PntAdmFunction