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

  1. /*  ********************************************************************************
  2.     ObjectDictionary.java **********************************************************
  3.     ********************************************************************************  */
  4.  
  5. package aspcomp;
  6.  
  7. import com.ms.asp.*;
  8. import com.ms.com.*;
  9. import java.util.*;
  10.  
  11. /**
  12.  * Supports lookup of items in a collection of variants. 
  13.  * Used by Session and Applcation. 
  14.  */
  15.  
  16. public class ObjectDictionary 
  17.     extends java.util.Dictionary
  18.     implements aspcomp.Enumerator, aspcomp.Map
  19. {
  20.  
  21. /*  ********************************************************************************
  22.     Constructor ********************************************************************
  23.     ********************************************************************************  */
  24.  
  25.     public ObjectDictionary(IVariantDictionary ivd)
  26.     {
  27.         m_ivdDict = ivd;
  28.         enum = new VariantEnumerator((IEnumVariant)m_ivdDict.get_NewEnum());
  29.     }
  30.  
  31.  
  32. /*  ********************************************************************************
  33.     Internal (Private) Variables ***************************************************
  34.     ********************************************************************************  */
  35.  
  36.     private IVariantDictionary m_ivdDict;
  37.     private VariantEnumerator enum;
  38.  
  39.  
  40. /*  ********************************************************************************
  41.     Internal (Private) Methods *****************************************************
  42.     ********************************************************************************  */
  43.  
  44.     private Variant getItem(String name) 
  45.     {
  46.         Variant vr = m_ivdDict.getItem(new Variant(name));
  47.         return vr;
  48.     }
  49.  
  50.     private void putItem(String name, Variant value) 
  51.     {
  52.         m_ivdDict.putItem(new Variant(name), value);
  53.     }
  54.  
  55.  
  56. /*  ********************************************************************************
  57.     External (Public) Methods ******************************************************
  58.     ********************************************************************************  */
  59.  
  60.     public int getCount() 
  61.     {
  62.         return m_ivdDict.getCount();
  63.     }
  64.  
  65.  
  66. /*  ********************************************************************************
  67.     External (Public) java.util.Dictionary Class Methods ***************************
  68.     ********************************************************************************  */
  69.  
  70.     public Object get(Object key) throws AspComponentException 
  71.     {
  72.         if (key instanceof String) {
  73.             return getItem((String) key);
  74.         }
  75.         else if (key instanceof Variant) {
  76.             Variant v = (Variant) key;
  77.             if (v.getvt() == Variant.VariantString) {
  78.                 return getItem(v.getString());
  79.             }
  80.         }
  81.         throw new AspComponentException(AspLocalizedStrings.ASP_E_NON_STRING_DICT_KEY);
  82.     }
  83.  
  84.     public Object put(Object key, Object value) throws AspComponentException 
  85.     {
  86.         String strKey = null;
  87.         if (key instanceof String) {
  88.             strKey = (String) key;
  89.         }
  90.         else if (key instanceof Variant) {
  91.             Variant v = (Variant) key;
  92.             if (v.getvt() == Variant.VariantString) {
  93.                 strKey = v.getString();
  94.             }
  95.         }
  96.         else throw new AspComponentException(AspLocalizedStrings.ASP_E_NON_STRING_DICT_KEY);
  97.         
  98.         Object objPrevious = getObject(strKey);
  99.         setObject(strKey, value);
  100.         return objPrevious;
  101.     }
  102.  
  103.     public int size() 
  104.     {
  105.         return m_ivdDict.getCount();
  106.     }
  107.  
  108.     public boolean isEmpty() 
  109.     {
  110.         if (m_ivdDict.getCount() == 0) return true;
  111.         else return false;
  112.     }
  113.  
  114.     public Enumeration keys() 
  115.     {
  116.         return new VariantEnumerator((IEnumVariant) m_ivdDict.get_NewEnum());
  117.     }
  118.     
  119.     public Enumeration elements() 
  120.     {
  121.         return new ObjectEnumerator((IEnumVariant) m_ivdDict.get_NewEnum(), this);
  122.     }
  123.  
  124.     public Object remove(Object key) throws AspComponentException 
  125.     {
  126.         throw new AspComponentException(AspLocalizedStrings.ASP_E_DICT_REMOVE);
  127.     }
  128.  
  129.  
  130. /*  ********************************************************************************
  131.     External (Public) aspcomp.Map Interface Methods ********************************
  132.     ********************************************************************************  */
  133.  
  134.     public int getType(String name) 
  135.     {
  136.         Variant v = getItem(name);
  137.         return v.getvt();
  138.     }
  139.     
  140.     public boolean getBoolean(String name)        
  141.         throws ClassCastException 
  142.     {
  143.         return VariantToJava.getBoolean(getItem(name));
  144.     }
  145.  
  146.     public byte getByte(String name)            
  147.         throws ClassCastException 
  148.     {
  149.         return VariantToJava.getByte(getItem(name));
  150.     }
  151.  
  152.     public short getShort(String name)            
  153.         throws ClassCastException 
  154.     {
  155.         return VariantToJava.getShort(getItem(name));
  156.     }
  157.  
  158.     public char getChar(String name)            
  159.         throws ClassCastException 
  160.     {
  161.         return VariantToJava.getChar(getItem(name));
  162.     }
  163.  
  164.     public int getInt(String name)                
  165.         throws ClassCastException 
  166.     {
  167.         return VariantToJava.getInt(getItem(name));
  168.     }
  169.  
  170.     public long getLong(String name)            
  171.         throws ClassCastException 
  172.     {
  173.         return VariantToJava.getLong(getItem(name));
  174.     }
  175.  
  176.     public float getFloat(String name)            
  177.         throws ClassCastException 
  178.     {
  179.         return VariantToJava.getFloat(getItem(name));
  180.     }
  181.  
  182.     public double getDouble(String name)        
  183.         throws ClassCastException 
  184.     {
  185.         return VariantToJava.getDouble(getItem(name));
  186.     }
  187.  
  188.     public String getString(String name)        
  189.         throws ClassCastException 
  190.     {
  191.         return VariantToJava.getString(getItem(name));
  192.     }
  193.  
  194.     public Date getDate(String name)            
  195.         throws ClassCastException 
  196.     {
  197.         return VariantToJava.getDate(getItem(name));
  198.     }
  199.  
  200.     public Object getObject(String name)        
  201.         throws ClassCastException 
  202.     {
  203.         return VariantToJava.getObject(getItem(name));
  204.     }
  205.  
  206.     public Variant getVariant(String name)        
  207.         throws ClassCastException 
  208.     {
  209.         return getItem(name);
  210.     }
  211.  
  212.     public void setObject(String name, Object o)        
  213.         throws AspComponentException 
  214.     {
  215.         try {
  216.             putItem(name, JavaToVariant.fromObject(o));
  217.         }
  218.         catch (Throwable t) {
  219.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  220.         }
  221.     }
  222.  
  223.     public void setBoolean(String name,boolean b)        
  224.         throws AspComponentException 
  225.     {
  226.         try {
  227.             putItem(name, JavaToVariant.fromBoolean(b));
  228.         }
  229.         catch (Throwable t) {
  230.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  231.         }
  232.     }
  233.  
  234.     public void setByte(String name,byte b)                
  235.         throws AspComponentException 
  236.     {
  237.         try {
  238.             putItem(name, JavaToVariant.fromByte(b));
  239.         }
  240.         catch (Throwable t) {
  241.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  242.         }
  243.     }
  244.  
  245.     public void setShort(String name,short v)            
  246.         throws AspComponentException 
  247.     {
  248.         try {
  249.             putItem(name, JavaToVariant.fromShort(v));
  250.         }
  251.         catch (Throwable t) {
  252.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  253.         }
  254.     }
  255.  
  256.     public void setInt(String name, int v)                
  257.         throws AspComponentException 
  258.     {
  259.         try {
  260.             putItem(name, JavaToVariant.fromInt(v));
  261.         }
  262.         catch (Throwable t) {
  263.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  264.         }
  265.     }
  266.  
  267.     public void setFloat(String name,float v)            
  268.         throws AspComponentException 
  269.     {
  270.         try {
  271.             putItem(name, JavaToVariant.fromFloat(v));
  272.         }
  273.         catch (Throwable t) {
  274.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  275.         }
  276.     }
  277.  
  278.     public void setDouble(String name,double v)            
  279.         throws AspComponentException 
  280.     {
  281.         try {
  282.             putItem(name, JavaToVariant.fromDouble(v));
  283.         }
  284.         catch (Throwable t) {
  285.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  286.         }
  287.     }
  288.  
  289.     public void setString(String name,String v)            
  290.         throws AspComponentException 
  291.     {
  292.         try {
  293.             putItem(name, JavaToVariant.fromString(v));
  294.         }
  295.         catch (Throwable t) {
  296.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  297.         }
  298.     }
  299.  
  300.     public void setDate(String name, Date v)            
  301.         throws AspComponentException 
  302.     {
  303.         try {
  304.             putItem(name, JavaToVariant.fromDate(v));
  305.         }
  306.         catch (Throwable t) {
  307.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  308.         }
  309.     }
  310.  
  311.     public void setVariant(String name, Variant var)    
  312.         throws AspComponentException 
  313.     {
  314.         try {
  315.             putItem(name, var);
  316.         }
  317.         catch (Throwable t) {
  318.             throw new AspComponentException(AspLocalizedStrings.ASP_E_READ_ONLY_DICT);
  319.         }
  320.     }
  321.  
  322.  
  323. /*  ********************************************************************************
  324.     External (Public) java.util.Enumeration Interface Methods **********************
  325.     ********************************************************************************  */
  326.  
  327.     public boolean hasMoreElements() 
  328.     {
  329.         return enum.hasMoreElements();
  330.     }
  331.  
  332.     public Object nextElement() 
  333.         throws NoSuchElementException 
  334.     {
  335.         return enum.nextElement();
  336.     }
  337.  
  338.  
  339. /*  ********************************************************************************
  340.     External (Public) java.lang.Cloneable Interface Methods ************************
  341.     ********************************************************************************  */
  342.  
  343.     public Object clone() 
  344.     {
  345.         return enum.clone();
  346.     }
  347.  
  348.  
  349. /*  ********************************************************************************
  350.     External (Public) aspcomp.Enumerator Interface Methods *************************
  351.     ********************************************************************************  */
  352.  
  353.     public void reset() 
  354.     {
  355.         enum.reset();
  356.     }
  357. }
  358.