Package xml.config

Source Code of xml.config.XMLConfig

package xml.config;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import xml.config.exceptions.ConfigTagAlreadyExistsException;

public class XMLConfig {
  // ** ATTRIBUTES ** //
  // **************** //
  private List<String> tagNames;
  private Hashtable<String,String> table;
 
  // ** CONSTRUCTORS ** //
  // ****************** //
  XMLConfig(List<String> tagNames, Hashtable<String, String> table){
    this.tagNames = tagNames;
    this.table = table;
  }
 
  // ** METHODS ** //
  // ************* //
  public void add(String key, String value) throws ConfigTagAlreadyExistsException{
    if(table.get(key)!=null)
      throw new ConfigTagAlreadyExistsException();
   
    tagNames.add(key);
    table.put(key,value);
  }
 
  public void del(String key){
    tagNames.remove(key);
    table.remove(key);
  }
 
  /**
   *
   * @param key the key whose associated value is to be returned
   * @return the value to which the specified key is mapped,
   * or null if this map contains no mapping for the key
   */
  public String get(String key){
    return table.get(key);
  }
 
  public void set(String key, String value){
    table.put(key, value);
  }
 
  public int size(){
    return tagNames.size();
  }
 
  public String[] list(){
    String list[] = new String[tagNames.size()];
    Iterator<String> tags = tagNames.iterator();
   
    int i = 0;
    while(tags.hasNext()){
      list[i] = tags.next();
      i++;
    }
   
    return list;
  }

  // ** PACKAGE-LEVEL GETTERS n SETTERS ** //
  // ************************************* //
  List<String> getTagNames() {
    return tagNames;
  }

  void setTagNames(List<String> tagNames) {
    this.tagNames = tagNames;
  }

  Hashtable<String, String> getTable() {
    return table;
  }

  void setTable(Hashtable<String, String> table) {
    this.table = table;
  }
 
}
TOP

Related Classes of xml.config.XMLConfig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.