home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML in Action / Dynamicke-HTML-v-akci-covermount.bin / XML / PARSER / XMLINST.EXE / classes / com / ms / xml / util / ReadOnlyAttributes.java < prev    next >
Encoding:
Java Source  |  1997-11-03  |  2.1 KB  |  104 lines

  1. /*
  2.  * @(#)ReadOnlyAttributes.java 1.0 97/5/6
  3.  * 
  4.  * Copyright (c) 1997 Microsoft, Corp. All Rights Reserved.
  5.  * 
  6.  */
  7.  
  8. package com.ms.xml.util;
  9.  
  10. import java.util.Vector;
  11. import java.util.Enumeration;
  12.  
  13.  
  14. /**
  15.  * Attributes wrapper class which provides read only access.
  16.  *
  17.  * @author  Istvan Cseri
  18.  * @version 1.0, 5/6/97
  19.  */
  20. public class ReadOnlyAttributes
  21. {
  22.     /**
  23.      * Collection of Attribute objects.
  24.      */
  25.     Vector attributes;
  26.  
  27.     /**
  28.      * Construct empty attributes collection.
  29.      */
  30.     public ReadOnlyAttributes()
  31.     {
  32.         attributes = new Vector();
  33.     }
  34.  
  35.     /**
  36.     * Construct attributes collection using the vector of attributes.
  37.     *
  38.     * @param   v   Attribute vector
  39.     */
  40.     public ReadOnlyAttributes(Vector v)
  41.     {
  42.         attributes = v;
  43.     }
  44.  
  45.     /**
  46.      * Construct attributes collection with given number of empty slots.
  47.      * The collection will grow automatically
  48.      * if you add more than this number.
  49.      * @param elems the number of attributes to reserve initially.
  50.      */
  51.     public ReadOnlyAttributes(int elems)
  52.     {
  53.         attributes = new Vector(elems);
  54.     }
  55.  
  56.     /**
  57.      * Return the number of attribute/value pairs in the collection.
  58.      */
  59.     public int size()
  60.     {
  61.         return attributes.size();
  62.     }
  63.  
  64.     /**
  65.      * Find the named attribute and return the associated value.
  66.      */
  67.     public Object get(Name name)
  68.     {
  69.         Attribute a = lookup(name);
  70.         if (a == null) 
  71.         {
  72.             return null;
  73.         }
  74.         return a.getValue();
  75.     }
  76.  
  77.     /**
  78.      * Return an Enumeration for iterating through the attributes.
  79.      */
  80.     public Enumeration attributes()
  81.     {
  82.         return attributes.elements();
  83.     }
  84.  
  85.      
  86.     public Attribute lookup(Name name)
  87.     {
  88.         for (Enumeration e = attributes.elements(); e.hasMoreElements(); ) 
  89.         {
  90.             Attribute a = (Attribute)e.nextElement();
  91.             if (a.name == name) 
  92.             {
  93.                 return a;
  94.             }
  95.         }
  96.         return null;
  97.     }
  98.  
  99.     public String toString()
  100.     {
  101.         return getClass().getName();
  102.     }
  103. }    
  104.