title: Java Vector Field (private member) accumulator doesn't store my Cows!
body: <p>Edit: This code is fine.  I found a logic bug somewhere that doesn't exist in my pseudo code.  I was blaming it on my lack of Java experience.</p>
  
  <p>In the <strong>pseudo code</strong> below, I'm trying to parse the XML shown.  A silly example maybe but my code was too large/specific for anyone to get any real value out of seeing it and learning from answers posted.  So, this is more entertaining and hopefully others can learn from the answer as well as me.</p>
  
  <p>I'm new to Java but an experienced C++ programmer which makes me believe my problem lies in my understanding of the Java language.</p>
  
  <p>Problem: When the parser finishes, my Vector is full of uninitialized Cows.  I create the Vector of Cows with a default capacity (which shouldn't effect it's "size" if it's anything like C++ STL Vector).  When I print the contents of the Cow Vector out after the parse, it gives the right size of Vector but all the values appear never to have been set.</p>
  
  <p>Info: I have successfully done this with other parsers that don't have Vector <em>fields</em> but in this case, I'd like to use a Vector to accumulate Cow properties.</p>
  
  <p>MoreInfo: I can't use generics (Vector&lt; Cow >) so please don't point me there.  :)</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>&lt;pluralcow&gt;
          &lt;cow&gt;
              &lt;color&gt;black&lt;/color&gt;
              &lt;age&gt;1&lt;/age&gt;
          &lt;/cow&gt;
          &lt;cow&gt;
              &lt;color&gt;brown&lt;/color&gt;
              &lt;age&gt;2&lt;/age&gt;
          &lt;/cow&gt;
          &lt;cow&gt;
              &lt;color&gt;blue&lt;/color&gt;
              &lt;age&gt;3&lt;/age&gt;
          &lt;/cow&gt;
  &lt;/pluralcow&gt;
  
  public class Handler extends DefaultHandler{
      // vector to store all the cow knowledge
      private Vector  m_CowVec;
  
      // temp variable to store cow knowledge until
      // we're ready to add it to the vector
      private Cow     m_WorkingCow;
  
      // flags to indicate when to look at char data
      private boolean m_bColor;
      private boolean m_bAge;
  
      public void startElement(...tag...)
      {
          if(tag == pluralcow){   // rule: there is only 1 pluralcow tag in the doc
                  // I happen to magically know how many cows there are here.             
                  m_CowVec = new Vector(numcows);
          }else if(tag == cow ){  // rule: multiple cow tags exist
              m_WorkingCow = new Cow();
          }else if(tag == color){ // rule: single color within cow
              m_bColor = true;
          }else if(tag == age){   // rule: single age within cow
              m_bAge = true;
          }
      }
  
      public void characters(...chars...)
      {
          if(m_bColor){
              m_WorkingCow.setColor(chars);   
          }else if(m_bAge){
              m_WorkingCow.setAge(chars);
          }
      }
  
      public void endElement(...tag...)
      {
          if(tag == pluralcow){
              // that's all the cows
          }else if(tag == cow ){
              m_CowVec.addElement(m_WorkingCow);      
          }else if(tag == color){
              m_bColor = false;
          }else if(tag == age){
              m_bAge = false;
          }
      }
  }
  </code></pre>