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 */
28package com.sun.dhcpmgr.cli.dhtadm;
29
30import com.sun.dhcpmgr.cli.common.DhcpCliFunction;
31import com.sun.dhcpmgr.bridge.NoTableException;
32
33import java.lang.IllegalArgumentException;
34
35/**
36 * The main class for the "remove table" functionality of dhtadm.
37 */
38public class RemoveTable extends DhtAdmFunction {
39
40    /**
41     * The valid options associated with removing the table.
42     */
43    static final int supportedOptions[] = {
44	DhtAdm.RESOURCE,
45	DhtAdm.RESOURCE_CONFIG,
46	DhtAdm.PATH,
47	DhtAdm.SIGHUP
48    };
49
50    /**
51     * Constructs a RemoveTable object.
52     */
53    public RemoveTable() {
54
55	validOptions = supportedOptions;
56
57    } // constructor
58
59    /**
60     * Returns the option flag for this function.
61     * @returns the option flag for this function.
62     */
63    public int getFunctionFlag() {
64	return (DhtAdm.REMOVE_TABLE);
65    }
66
67    /**
68     * Executes the "remove table" functionality.
69     * @return DhtAdm.SUCCESS, DhtAdm.ENOENT, DhtAdm.WARNING, or
70     * DhtAdm.CRITICAL
71     */
72    public int execute()
73	throws IllegalArgumentException {
74
75	int returnCode = DhtAdm.SUCCESS;
76
77	// Remove the table.
78	//
79	try {
80	    getDhcptabMgr().deleteDhcptab(getDhcpDatastore());
81	} catch (NoTableException e) {
82	    printErrMessage(getMessage(e));
83	    returnCode = DhtAdm.ENOENT;
84	} catch (Throwable e) {
85	    printErrMessage(getMessage(e));
86	    returnCode = DhtAdm.WARNING;
87	}
88
89	return (returnCode);
90
91    } // execute
92
93} // RemoveTable
94