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.data.DhcptabRecord; 32 import com.sun.dhcpmgr.data.Macro; 33 import com.sun.dhcpmgr.data.Option; 34 import com.sun.dhcpmgr.bridge.NoEntryException; 35 36 import java.lang.IllegalArgumentException; 37 38 /** 39 * The main class for the "delete entry" functionality of dhtadm. 40 */ 41 public class DeleteEntry extends DhtAdmFunction { 42 43 /** 44 * The valid options associated with deleting an entry. 45 */ 46 static final int supportedOptions[] = { 47 DhtAdm.MACRONAME, 48 DhtAdm.SYMBOLNAME, 49 DhtAdm.RESOURCE, 50 DhtAdm.RESOURCE_CONFIG, 51 DhtAdm.PATH, 52 DhtAdm.SIGHUP 53 }; 54 55 /** 56 * Constructs a DeleteEntry object. 57 */ 58 public DeleteEntry() { 59 60 validOptions = supportedOptions; 61 62 } // constructor 63 64 /** 65 * Returns the option flag for this function. 66 * @returns the option flag for this function. 67 */ 68 public int getFunctionFlag() { 69 return (DhtAdm.DELETE_ENTRY); 70 } 71 72 /** 73 * Executes the "delete entry" functionality. 74 * @return DhtAdm.SUCCESS, DhtAdm.ENOENT, DhtAdm.WARNING, or 75 * DhtAdm.CRITICAL 76 */ 77 public int execute() 78 throws IllegalArgumentException { 79 80 int returnCode = DhtAdm.SUCCESS; 81 82 // Get macro or symbol name. One and only one should be set. 83 // 84 String macroName = options.valueOf(DhtAdm.MACRONAME); 85 String symbolName = options.valueOf(DhtAdm.SYMBOLNAME); 86 87 if (macroName != null && symbolName != null) { 88 String msg = getString("two_keys_error"); 89 throw new IllegalArgumentException(msg); 90 } 91 92 if (macroName == null && symbolName == null) { 93 String msg = getString("no_keys_error"); 94 throw new IllegalArgumentException(msg); 95 } 96 97 try { 98 // Get the DhcptabRecord. 99 // 100 DhcptabRecord dhcptabRecord = null; 101 if (macroName != null) { 102 dhcptabRecord = new Macro(macroName); 103 } else if (symbolName != null) { 104 dhcptabRecord = new Option(); 105 dhcptabRecord.setKey(symbolName); 106 } else { 107 printErrMessage(getString("internal_error")); 108 returnCode = DhtAdm.CRITICAL; 109 } 110 111 // Delete the entry. 112 // 113 if (returnCode == DhtAdm.SUCCESS) { 114 getDhcptabMgr().deleteRecord(dhcptabRecord, false, 115 getDhcpDatastore()); 116 } 117 118 } catch (NoEntryException e) { 119 printErrMessage(getMessage(e)); 120 returnCode = DhtAdm.ENOENT; 121 } catch (Throwable e) { 122 printErrMessage(getMessage(e)); 123 returnCode = DhtAdm.WARNING; 124 } 125 126 return (returnCode); 127 128 } // execute 129 130 } // DeleteEntry