From: Stefan T. <th...@us...> - 2002-02-22 12:48:57
|
Update of /cvsroot/xpg-xml/edu/iicm/xpg/statemachine In directory usw-pr-cvs1:/tmp/cvs-serv3328 Modified Files: DataObject.java XMLHandler.java Log Message: new DataObject Index: DataObject.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/DataObject.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DataObject.java 7 Feb 2002 09:38:12 -0000 1.2 --- DataObject.java 22 Feb 2002 12:48:54 -0000 1.3 *************** *** 27,30 **** --- 27,33 ---- import java.util.Stack; + import java.util.EmptyStackException; + + //---------------------------------------------------------------------- /** *************** *** 35,73 **** public class DataObject { ! protected boolean finished_ = false; ! ! protected Stack element_stack_ = new Stack(); ! protected Stack attribute_stack_ = new Stack(); ! ! protected StringBuffer result_ = new StringBuffer(); ! ! protected HashMap data_map_ = new HashMap(); ! //---------------------------------------------------------------------- ! /** ! * @param finished ! */ ! public void setFinished(boolean finished) ! { ! finished_ = finished; ! } ! //---------------------------------------------------------------------- ! /** ! * @return ! */ ! public boolean isFinished() ! { ! return finished_; ! } - //---------------------------------------------------------------------- - /** - * @return - */ - public StringBuffer getResult() - { - return result_; - } //---------------------------------------------------------------------- --- 38,56 ---- public class DataObject { ! private String element_value_; ! private Stack attribute_stack_; ! private StringBuffer result_; ! private HashMap data_map_; ! ! public DataObject() ! { ! element_value_= null; ! attribute_stack_ = new Stack(); ! result_ = new StringBuffer(); ! data_map_= new HashMap(); ! } //---------------------------------------------------------------------- *************** *** 75,91 **** * @param element the element that should be pushed on the stack */ ! public void pushElement(String element) ! { ! element_stack_.push(element); ! } ! ! //---------------------------------------------------------------------- ! /** ! * @return the top element ! */ ! public String topElement() ! { ! return (String)element_stack_.peek(); ! } //---------------------------------------------------------------------- --- 58,65 ---- * @param element the element that should be pushed on the stack */ ! protected void setElementValue(String elementvalue) ! { ! element_value_ = elementvalue; ! } //---------------------------------------------------------------------- *************** *** 93,100 **** * @return the top element and removes it */ ! public String popElement() ! { ! return (String)element_stack_.pop(); ! } //---------------------------------------------------------------------- --- 67,74 ---- * @return the top element and removes it */ ! public String getElementValue() ! { ! return element_value_; ! } //---------------------------------------------------------------------- *************** *** 102,109 **** * @param attributes the attributes that should be pushed on the stack */ ! public void pushAttributes(Attributes attributes) ! { ! attribute_stack_.push(attributes); ! } //---------------------------------------------------------------------- --- 76,83 ---- * @param attributes the attributes that should be pushed on the stack */ ! protected void pushAttributes(Attributes attributes) ! { ! attribute_stack_.push(attributes); ! } //---------------------------------------------------------------------- *************** *** 111,118 **** * @return the top attributes */ ! public Attributes topAttributes() { ! return (Attributes)attribute_stack_.peek(); } //---------------------------------------------------------------------- --- 85,101 ---- * @return the top attributes */ ! public Attributes topAttributes() ! { ! try { ! return (Attributes)attribute_stack_.peek(); ! } ! catch (EmptyStackException exc) ! { ! System.err.println(exc); ! exc.printStackTrace(); } + return null; + } //---------------------------------------------------------------------- *************** *** 120,127 **** * @return the top attributes and removes it */ ! public Attributes popAttributes() { ! return (Attributes)attribute_stack_.pop(); } //---------------------------------------------------------------------- --- 103,119 ---- * @return the top attributes and removes it */ ! protected Attributes popAttributes() ! { ! try ! { ! return (Attributes)attribute_stack_.pop(); ! } ! catch (EmptyStackException exc) { ! System.err.println(exc); ! exc.printStackTrace(); } + return null; + } //---------------------------------------------------------------------- *************** *** 130,142 **** * @param value the dataobject that should be stored */ ! public void putObject(String key, Object value) { ! if ( data_map_.containsKey(key) ) ! { ! System.err.println("\"" + key + "\" allready exists inDataObject"); ! return; ! } ! data_map_.put(key, value); } //---------------------------------------------------------------------- --- 122,134 ---- * @param value the dataobject that should be stored */ ! public void putObject(String key, Object value) ! { ! if ( data_map_.containsKey(key) ) { ! System.err.println("\"" + key + "\" allready exists inDataObject"); ! return; } + data_map_.put(key, value); + } //---------------------------------------------------------------------- *************** *** 145,152 **** * @return the dataobject */ ! public Object getObject(String key) ! { ! return data_map_.get(key); ! } //---------------------------------------------------------------------- --- 137,144 ---- * @return the dataobject */ ! public Object getObject(String key) ! { ! return data_map_.get(key); ! } //---------------------------------------------------------------------- *************** *** 155,164 **** * @return the dataobject */ ! public Object takeObject(String key) ! { ! return data_map_.remove(key); ! } ! } --- 147,174 ---- * @return the dataobject */ ! public Object takeObject(String key) ! { ! return data_map_.remove(key); ! } ! ! public StringBuffer getResult() ! { ! return result_; ! } ! } + + + + + + + + + + + + + Index: XMLHandler.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/XMLHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XMLHandler.java 14 Feb 2002 17:53:48 -0000 1.1 --- XMLHandler.java 22 Feb 2002 12:48:54 -0000 1.2 *************** *** 104,112 **** try { ! // FIXXME (Stefan Thalauer, Feb11 2002 17:32) -> why pop element and than push the characters on the element_stack ??? ! // data_.popElement(); ! // data_.pushElement(new String(chars)); ! // END FIXXME (Stefan Thalauer, Feb11 2002 17:35) ! state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } --- 104,108 ---- try { ! data_.setElementValue(new String(chars)); state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } *************** *** 132,136 **** try { - data_.pushElement(name); data_.pushAttributes(attributes); state_machine_.input(new XMLInput(Const.XML_START_TAG,name)); --- 128,131 ---- *************** *** 156,161 **** { state_machine_.input(new XMLInput(Const.XML_END_TAG,name)); ! data_.popAttributes(); ! data_.popElement(); } catch(Exception exc) --- 151,156 ---- { state_machine_.input(new XMLInput(Const.XML_END_TAG,name)); ! data_.setElementValue(null); ! data_.popAttributes(); } catch(Exception exc) *************** *** 223,237 **** System.err.println(" " + exc.getMessage()); exc.printStackTrace(); - } - - - //---------------------------------------------------------------------- - /** - * @return the object that has been generated - */ - - public synchronized Object getResult() - { - return(data_.getResult().toString()); } } --- 218,221 ---- |