home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / CookieDictionary.java < prev    next >
Text File  |  1997-10-25  |  5KB  |  159 lines

  1. /*  ********************************************************************************
  2.     CookieDictionary.java **********************************************************
  3.     ********************************************************************************  */
  4.  
  5. package aspcomp;
  6.  
  7. import com.ms.com.*;
  8. import com.ms.asp.*;
  9. import java.util.*;
  10.  
  11. /**
  12.  * Allows lookups in cookie collections.
  13.  */
  14.  
  15. public class CookieDictionary 
  16.     extends java.util.Dictionary
  17.     implements aspcomp.Enumerator
  18. {
  19.  
  20. /*  ********************************************************************************
  21.     Constructor ********************************************************************
  22.     ********************************************************************************  */
  23.  
  24.     public CookieDictionary(IRequestDictionary reqDict) 
  25.     {
  26.         m_reqDict = reqDict;
  27.  
  28.         ve = new VariantEnumerator((IEnumVariant) m_reqDict.get_NewEnum());
  29.     }
  30.  
  31.  
  32. /*  ********************************************************************************
  33.     Internal (Private) Variables ***************************************************
  34.     ********************************************************************************  */
  35.  
  36.     private IRequestDictionary m_reqDict;
  37.     private VariantEnumerator ve;
  38.     
  39.  
  40. /*  ********************************************************************************
  41.     Internal (Private) Method ******************************************************
  42.     ********************************************************************************  */
  43.  
  44.     private Variant getItem(String name)
  45.     {
  46.         return m_reqDict.getItem(new Variant(name));
  47.     }
  48.  
  49.  
  50. /*  ********************************************************************************
  51.     External (Public) Methods ******************************************************
  52.     ********************************************************************************  */
  53.  
  54.     public int getCount() 
  55.     { 
  56.         return m_reqDict.getCount();
  57.     }
  58.     
  59.     public Cookie getCookie(String name) 
  60.         throws ClassCastException 
  61.     {
  62.         Variant v = getItem(name);
  63.  
  64.         if (v.getvt() == v.VariantDispatch) {
  65.             IReadCookie readCookie = (IReadCookie)v.getDispatch();
  66.             return new Cookie(readCookie);
  67.         }
  68.  
  69.         throw new ClassCastException();
  70.     }
  71.  
  72.     
  73. /*  ********************************************************************************
  74.     External (Public) aspcomp.Enumerator Interface Methods *************************
  75.     ********************************************************************************  */
  76.  
  77.     public void reset() 
  78.     {
  79.         ve.reset();
  80.     }
  81.  
  82.  
  83. /*  ********************************************************************************
  84.     External (Public) java.util.Enumeration Interface Methods **********************
  85.     ********************************************************************************  */
  86.  
  87.     public boolean hasMoreElements() 
  88.     {
  89.         return ve.hasMoreElements();
  90.     }
  91.  
  92.     public Object nextElement() 
  93.         throws NoSuchElementException,
  94.                ClassCastException 
  95.     {
  96.         return ve.nextElement();
  97.     }
  98.  
  99.  
  100. /*  ********************************************************************************
  101.     External (Public) java.lang.Cloneable Interface Methods ************************
  102.     ********************************************************************************  */
  103.  
  104.     public Object clone() {
  105.         return ve.clone();
  106.     }
  107.  
  108.  
  109. /*  ********************************************************************************
  110.     External (Public) java.util.Dictionary Class Methods ***************************
  111.     ********************************************************************************  */
  112.  
  113.     public int size()
  114.     {
  115.         return getCount();
  116.     }
  117.  
  118.     public boolean isEmpty()
  119.     {
  120.         return (getCount() == 0);
  121.     }
  122.  
  123.     public Enumeration keys()
  124.     {
  125.         return new VariantEnumerator((IEnumVariant) m_reqDict.get_NewEnum());
  126.     }
  127.  
  128.     public Enumeration elements()
  129.     {
  130.         return new CookieEnumerator((IEnumVariant) m_reqDict.get_NewEnum(), this);
  131.     }
  132.  
  133.     public Object get(Object key)
  134.     {
  135.         if (key instanceof String) {
  136.             return getItem((String) key);
  137.         }
  138.         else if (key instanceof Variant) {
  139.             Variant v = (Variant) key;
  140.             if (v.getvt() == Variant.VariantString) {
  141.                 return getItem(v.getString());
  142.             }
  143.         }
  144.  
  145.         throw new AspComponentException(AspLocalizedStrings.ASP_E_NON_STRING_DICT_KEY);
  146.     }
  147.  
  148.     public Object put(Object key, Object value)
  149.     {
  150.         throw new AspComponentException(AspLocalizedStrings.ASP_E_COOKIE_PUT);
  151.     }
  152.  
  153.     public Object remove(Object key)
  154.     {
  155.         throw new AspComponentException(AspLocalizedStrings.ASP_E_DICT_REMOVE);
  156.     }
  157. }
  158.  
  159.