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 2002 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 package com.sun.dhcpmgr.data.qualifier;
  30 
  31 import java.util.Map;
  32 import java.util.HashMap;
  33 
  34 /**
  35  * Super class for qualifier. Provides common methods and fields.
  36  */
  37 public class QualifierImpl implements Qualifier {
  38 
  39     /**
  40      * Map of qualifier attributes to values.
  41      */
  42     protected Map attributes;
  43 
  44     /**
  45      * Construct an empty qualifier.
  46      */
  47     public QualifierImpl() {
  48     }
  49 
  50     /**
  51      * Construct a qualifier, assigning all the required fields.
  52      *
  53      * @param keyword
  54      *   The name of the parameter that the qualifier is associated with.
  55      * @param readOnly
  56      *   Inidicate whether the parameter is to be treated as read only.
  57      * @param hidden
  58      *   Inidicate whether the parameter is hidden.
  59      * @param type
  60      *   The parameter value type.
  61      */
  62     public QualifierImpl(String keyword,
  63                          boolean readOnly,
  64                          boolean hidden,
  65                          QualifierType type) {
  66 
  67         attributes = new HashMap();
  68         attributes.put(KEYWORD, keyword);
  69         attributes.put(READONLY, new Boolean(readOnly));
  70         attributes.put(HIDDEN, new Boolean(hidden));
  71         attributes.put(TYPE, type);
  72     }
  73 
  74     public synchronized Object getAttribute(String attribute) {
  75         return attributes.get(attribute);
  76     }
  77 
  78     public synchronized void setAttribute(String attribute, Object value) {
  79         if (value == null) {
  80             if (attributes.containsKey(attribute)) {
  81                 attributes.remove(attribute);
  82             }
  83         } else {
  84             attributes.put(attribute, value);
  85         }
  86     }
  87 
  88     public String getKeyword() {
  89         return (String)attributes.get(KEYWORD);
  90     }
  91 
  92     public boolean isReadOnly() {
  93         return ((Boolean)attributes.get(READONLY)).booleanValue();
  94     }
  95 
  96     public boolean isHidden() {
  97         return ((Boolean)attributes.get(HIDDEN)).booleanValue();
  98     }
  99 
 100     public QualifierType getType() {
 101         return (QualifierType)attributes.get(TYPE);
 102     }
 103 
 104     public String toString() {
 105         return attributes.toString();
 106     }
 107 }