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 (c) 2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 package com.sun.dhcpmgr.cli.dhcpconfig; 29 30 import java.text.MessageFormat; 31 32 import com.sun.dhcpmgr.cli.common.DhcpCliFunction; 33 import com.sun.dhcpmgr.cli.common.DhcpCliPrint; 34 import com.sun.dhcpmgr.data.DhcpdOptions; 35 36 /** 37 * Abstract class implemented by all the dhcpconfig "function" classes. 38 */ 39 public abstract class DhcpCfgFunction 40 extends DhcpCliFunction { 41 42 /** 43 * Returns a localized string for this function 44 * @param key the resource bundle string identifier 45 * @return string from resource bundle. 46 */ 47 public String getString(String key) { 48 49 return ResourceStrings.getString(key); 50 51 } // getString 52 53 /** 54 * Determines whether or not the DHCP service is configured. 55 * @return true if configured, false if not. 56 */ 57 public boolean isServerConfigured() { 58 59 boolean result = false; 60 61 try { 62 DhcpdOptions opts = getSvcMgr().readDefaults(); 63 if (!opts.isRelay()) { 64 result = true; 65 } 66 } catch (Throwable e) { 67 // nothing to do. 68 } 69 70 if (!result) { 71 printErrMessage(getString("dhcpcfg_func_not_configured_error")); 72 } 73 74 return (result); 75 76 } // isServerConfigured 77 78 /** 79 * Prints a message to the console. 80 * @param msg the message to print. 81 */ 82 public void printMessage(String msg) { 83 DhcpCliPrint.printMessage(msg); 84 } // printMessage 85 86 /** 87 * Prints a message to the console.. 88 * @param msg the message to print. 89 */ 90 public void printMessage(String msg, Object [] arguments) { 91 MessageFormat form = new MessageFormat(msg); 92 DhcpCliPrint.printMessage(form.format(arguments)); 93 } // printMessage 94 95 /** 96 * Prints an error message. 97 * @param msg the message to print. 98 */ 99 public void printErrMessage(String msg) { 100 StringBuffer fullmsg = new StringBuffer(DhcpCfg.SIGNATURE); 101 fullmsg.append(msg); 102 DhcpCliPrint.printErrMessage(fullmsg.toString()); 103 } // printErrMessage 104 105 /** 106 * Prints an error message. 107 * @param msg the message to print. 108 */ 109 public void printErrMessage(String msg, Object [] arguments) { 110 StringBuffer fullmsg = new StringBuffer(DhcpCfg.SIGNATURE); 111 fullmsg.append(msg); 112 MessageFormat form = new MessageFormat(fullmsg.toString()); 113 DhcpCliPrint.printErrMessage(form.format(arguments)); 114 } // printErrMessage 115 116 } // DhcpCfgFunction