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.client; 29 30 import java.awt.*; 31 import java.util.*; 32 import javax.swing.event.EventListenerList; 33 34 /** 35 * This class provides a skeletal implementation of the data store module 36 * management interface to minimize the effort required to implement a 37 * data store management class. 38 */ 39 public abstract class DSModule { 40 41 /** 42 * Listeners registered with the DSModule. 43 */ 44 private EventListenerList DSMListeners = new EventListenerList(); 45 46 /** 47 * Attribute that signifies whether or not the data store has been 48 * configured well enough to allow the data store to be managed. 49 */ 50 private boolean forwardEnabled = false; 51 52 /** 53 * Returns the path that is used by the data store (i.e., the PATH value 54 * in the DHCP config file). 55 * @return the path that is used by the data store (i.e., the PATH value 56 * in the DHCP config file) or null if not set. 57 */ 58 public abstract String getPath(); 59 60 /** 61 * Returns additional datastore specific information (i.e., the 62 * RESOURCE_CONFIG value in the DHCP config file). 63 * @return additional datastore specific information (i.e., the 64 * RESOURCE_CONFIG value in the DHCP config file) or null if not set. 65 */ 66 public abstract String getAdditionalInfo(); 67 68 /** 69 * Returns the description that will be used by the DHCP configuration 70 * wizard when adding the data store to the list of data store radio 71 * buttons. 72 * @return the description that will be used by the DHCP configuration 73 * wizard when adding the data store to the list of data store radio 74 * buttons. 75 */ 76 public abstract String getDescription(); 77 78 /** 79 * Returns the component that will be used by the DHCP configuration 80 * wizard to manage obtaining the data store parameters. 81 * @return the component that will be used by the DHCP configuration 82 * wizard to manage obtaining the data store parameters. 83 */ 84 public abstract Component getComponent(); 85 86 /** 87 * Adds a listener to the DSModule listener list. 88 * @param l the listener. 89 */ 90 public void addDSMListener(DSModuleListener l) { 91 DSMListeners.add(DSModuleListener.class, l); 92 } // addDSMListener 93 94 /** 95 * Removes a listener from the DSModule listener list. 96 * @param l the listener. 97 */ 98 public void removeDSMListener(DSModuleListener l) { 99 DSMListeners.remove(DSModuleListener.class, l); 100 } // removeDSMListener 101 102 /** 103 * Fires a DSModuleEvent to all DSModule listeners on the listener list. 104 * @param e the DSModuleEvent to be fired. 105 */ 106 private void fireDSMEvent(DSModuleEvent e) { 107 // Guaranteed to return a non-null array 108 Object[] listeners = DSMListeners.getListenerList(); 109 110 // Process the listeners last to first, notifying 111 // those that are interested in this event 112 for (int i = listeners.length - 2; i >= 0; i -= 2) { 113 if (listeners[i] == DSModuleListener.class) { 114 ((DSModuleListener)listeners[i + 1]).stateChanged(e); 115 } 116 } 117 } // fireDSMEvent 118 119 /** 120 * Returns the modules readiness state (i.e., can the DHCP config wizard 121 * continue forward if the user wishes). 122 * @return the modules readiness state 123 */ 124 public final boolean getForwardEnabled() { 125 return forwardEnabled; 126 } // getForwardEnabled 127 128 /** 129 * Sets the forwardEnabled attribute and fires a DSModuleEvent to the DHCP 130 * configuration wizard to let it know that the module's state has changed. 131 * @param enable value to which forwardEnabled should be set. 132 */ 133 public final void setForwardEnabled(boolean enable) { 134 135 forwardEnabled = enable; 136 137 int state = DSModuleEvent.DATA_VALID; 138 if (!enable) { 139 state = DSModuleEvent.DATA_INVALID; 140 } 141 142 fireDSMEvent(new DSModuleEvent(this, state)); 143 } // setForwardEnabled 144 145 } // DSModule