HeaderDictionary.java

00001 /*
00002  * Copyright (c) 2003-2006, KNOPFLERFISH project
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following
00007  * conditions are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  *
00012  * - Redistributions in binary form must reproduce the above
00013  *   copyright notice, this list of conditions and the following
00014  *   disclaimer in the documentation and/or other materials
00015  *   provided with the distribution.
00016  *
00017  * - Neither the name of the KNOPFLERFISH project nor the names of its
00018  *   contributors may be used to endorse or promote products derived
00019  *   from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00027  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00030  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00032  * OF THE POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 package org.knopflerfish.framework;
00036 
00037 import java.util.Map;
00038 import java.util.Iterator;
00039 import java.util.Dictionary;
00040 import java.util.Enumeration;
00041 import java.util.Hashtable;
00042 
00043 import java.util.jar.*;
00044 
00050 public class HeaderDictionary extends Dictionary implements Cloneable
00051 {
00052   private Hashtable headers;
00053 
00057   public HeaderDictionary(Attributes in) {
00058     headers = new Hashtable();
00059     for (Iterator i = in.entrySet().iterator(); i.hasNext();) {
00060       Map.Entry e = (Map.Entry)i.next();
00061       headers.put(e.getKey(), e.getValue());
00062     }
00063   }
00064 
00065 
00069   public HeaderDictionary(Hashtable t) {
00070     headers = t;
00071   }
00072 
00073 
00077   public Enumeration elements() {
00078     return headers.elements();
00079   }
00080 
00081 
00085   public Object get(Object key) {
00086     return headers.get(new Attributes.Name((String)key));
00087   }
00088 
00089 
00093   public boolean isEmpty() {
00094     return headers.isEmpty();
00095   }
00096 
00097 
00101   public Enumeration keys() {
00102     final Enumeration keys = headers.keys();
00103     return new Enumeration() {
00104       public boolean hasMoreElements() {
00105         return keys.hasMoreElements();
00106       }
00107       public Object nextElement() {
00108         return keys.nextElement().toString();
00109       }
00110     };
00111   }
00112 
00113 
00117   public Object put(Object key, Object value) {
00118     return headers.put(new Attributes.Name((String)key), value);
00119   }
00120 
00121 
00125   public Object remove(Object key) {
00126     return headers.remove(new Attributes.Name((String)key));
00127   }
00128 
00129   
00133   public int size() {
00134     return headers.size();
00135   }
00136 
00140   public Object clone() {
00141     return new HeaderDictionary((Hashtable)headers.clone());
00142   }
00143 
00144 
00145   public String toString() {
00146     return headers.toString();
00147   }
00148 }

Generated on Mon Jan 11 21:19:15 2010 for OpenMobileIS by  doxygen 1.5.4