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.pntadm; 29 30 import com.sun.dhcpmgr.data.Network; 31 import com.sun.dhcpmgr.bridge.TableExistsException; 32 33 import java.lang.IllegalArgumentException; 34 35 /** 36 * The main class for the "create network table" functionality 37 * of pntadm. 38 */ 39 public class CreateNetworkTable extends PntAdmFunction { 40 41 /** 42 * The valid options associated with creating a network table. 43 */ 44 static final int supportedOptions[] = { 45 PntAdm.RESOURCE, 46 PntAdm.RESOURCE_CONFIG, 47 PntAdm.PATH 48 }; 49 50 /** 51 * Constructs a CreateNetworkTable object. 52 */ 53 public CreateNetworkTable() { 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 (PntAdm.CREATE_NETWORK_TABLE); 65 } 66 67 /** 68 * Executes the "create network table" functionality. 69 * @return PntAdm.SUCCESS, PntAdm.EXISTS, PntAdm.WARNING, or 70 * PntAdm.CRITICAL 71 */ 72 public int execute() 73 throws IllegalArgumentException { 74 75 int returnCode = PntAdm.SUCCESS; 76 77 // Create a Network object. 78 // 79 try { 80 Network network = getNetMgr().getNetwork(networkName); 81 if (network == null) { 82 printErrMessage(getString("network_name_error")); 83 return (PntAdm.WARNING); 84 } 85 86 getNetMgr().createNetwork(network.toString(), getDhcpDatastore()); 87 } catch (TableExistsException e) { 88 printErrMessage(getMessage(e)); 89 returnCode = PntAdm.EXISTS; 90 } catch (Throwable e) { 91 printErrMessage(getMessage(e)); 92 returnCode = PntAdm.WARNING; 93 } 94 95 return (returnCode); 96 97 } // execute 98 99 } // CreateNetworkTable