From: G?nther B. <br...@us...> - 2002-02-28 06:40:22
|
Update of /cvsroot/xpg-xml/edu/iicm/xpg/statemachine In directory usw-pr-cvs1:/tmp/cvs-serv32148 Modified Files: Const.java DataObject.java InitInitializeStateMachine.java InitParser.java Initializer.java Parser.java XMLHandler.java Added Files: ElementObject.java Log Message: ElementObject added; DataObject modified --- NEW FILE: ElementObject.java --- /*********************************************************************** * * Copyright (c) 2001 IICM, Graz University of Technology * Schiesstattgasse 4a, A-8010 Graz, Austria. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License (LGPL) * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***********************************************************************/ package edu.iicm.xpg.statemachine; import org.xml.sax.Attributes; import java.util.HashMap; import java.util.Stack; import java.util.EmptyStackException; //---------------------------------------------------------------------- /** * @author Günther Brand * @version $revision$ */ public class ElementObject { protected String element_name_; protected String element_value_; protected Attributes attributes_; //---------------------------------------------------------------------- /** * @param element the elementname that should be set */ protected void setElementName(String elementname) { element_name_ = elementname; } //---------------------------------------------------------------------- /** * @return the element name */ public String getElementName() { return element_name_; } //---------------------------------------------------------------------- /** * @param element the elementvalue that should be set */ protected void setElementValue(String elementvalue) { element_value_ = elementvalue; } //---------------------------------------------------------------------- /** * @return the element value */ public String getElementValue() { return element_value_; } //---------------------------------------------------------------------- /** * @param attributes the attributes that should be set */ protected void setAttributes(Attributes attributes) { attributes_ = attributes; } //---------------------------------------------------------------------- /** * @return the attributes */ public Attributes getAttributes() { return attributes_; } } Index: Const.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/Const.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Const.java 29 Jan 2002 10:43:13 -0000 1.1.1.1 --- Const.java 28 Feb 2002 06:40:19 -0000 1.2 *************** *** 1,42 **** ! /*********************************************************************** ! * @(#)$RCSfile$ $Revision$ $Date$ ! * ! * Copyright (c) 2001 IICM, Graz University of Technology ! * Schiesstattgasse 4a, A-8010 Graz, Austria. ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU Lesser General Public License (LGPL) ! * as published by the Free Software Foundation; either version 2.1 of ! * the License, or (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this program; if not, write to the ! * Free Software Foundation, Inc., ! * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! ***********************************************************************/ ! ! ! package edu.iicm.xpg.statemachine; ! ! //---------------------------------------------------------------------- ! /** ! * @author Klaus Schmaranz ! * @author Günther Brand ! * @version $revision$ ! */ ! ! public class Const ! { ! // XML Input Types ! public final static String XML_END_DOCUMENT = "enddoc"; ! public final static String XML_CHARS = "chars"; ! public final static String XML_START_TAG = "start"; ! public final static String XML_END_TAG = "end"; ! } ! ! --- 1,44 ---- ! /*********************************************************************** ! * @(#)$RCSfile$ $Revision$ $Date$ ! * ! * Copyright (c) 2001 IICM, Graz University of Technology ! * Schiesstattgasse 4a, A-8010 Graz, Austria. ! * ! * This program is free software; you can redistribute it and/or modify ! * it under the terms of the GNU Lesser General Public License (LGPL) ! * as published by the Free Software Foundation; either version 2.1 of ! * the License, or (at your option) any later version. ! * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public ! * License along with this program; if not, write to the ! * Free Software Foundation, Inc., ! * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! ***********************************************************************/ ! ! ! package edu.iicm.xpg.statemachine; ! ! //---------------------------------------------------------------------- ! /** ! * @author Klaus Schmaranz ! * @author Günther Brand ! * @version $revision$ ! */ ! ! public class Const ! { ! // XML Input Types ! public final static String XML_END_DOCUMENT = "enddoc"; ! public final static String XML_CHARS = "chars"; ! public final static String XML_START_TAG = "start"; ! public final static String XML_END_TAG = "end"; ! ! public final static String RESULT_BUFFER = "result-buffer"; ! } ! ! Index: DataObject.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/DataObject.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataObject.java 22 Feb 2002 12:48:54 -0000 1.3 --- DataObject.java 28 Feb 2002 06:40:19 -0000 1.4 *************** *** 23,27 **** package edu.iicm.xpg.statemachine; - import org.xml.sax.Attributes; import java.util.HashMap; import java.util.Stack; --- 23,26 ---- *************** *** 38,45 **** public class DataObject { ! private String element_value_; ! private Stack attribute_stack_; ! ! private StringBuffer result_; private HashMap data_map_; --- 37,41 ---- public class DataObject { ! private Stack element_stack_; private HashMap data_map_; *************** *** 47,93 **** public DataObject() { ! element_value_= null; ! attribute_stack_ = new Stack(); ! result_ = new StringBuffer(); data_map_= new HashMap(); } - - //---------------------------------------------------------------------- - /** - * @param element the element that should be pushed on the stack - */ - protected void setElementValue(String elementvalue) - { - element_value_ = elementvalue; - } - //---------------------------------------------------------------------- /** ! * @return the top element and removes it ! */ ! public String getElementValue() ! { ! return element_value_; ! } ! ! //---------------------------------------------------------------------- ! /** ! * @param attributes the attributes that should be pushed on the stack */ ! protected void pushAttributes(Attributes attributes) { ! attribute_stack_.push(attributes); } //---------------------------------------------------------------------- /** ! * @return the top attributes */ ! public Attributes topAttributes() { try { ! return (Attributes)attribute_stack_.peek(); } catch (EmptyStackException exc) --- 43,68 ---- public DataObject() { ! element_stack_ = new Stack(); data_map_= new HashMap(); } //---------------------------------------------------------------------- /** ! * @param element_object the elementobject that should be pushed on the stack */ ! protected void pushElementObject(ElementObject element_object) { ! element_stack_.push(element_object); } //---------------------------------------------------------------------- /** ! * @return the top element object */ ! public ElementObject topElementObject() { try { ! return (ElementObject)element_stack_.peek(); } catch (EmptyStackException exc) *************** *** 101,111 **** //---------------------------------------------------------------------- /** ! * @return the top attributes and removes it */ ! protected Attributes popAttributes() { try { ! return (Attributes)attribute_stack_.pop(); } catch (EmptyStackException exc) --- 76,86 ---- //---------------------------------------------------------------------- /** ! * @return the top element object and removes it */ ! protected ElementObject popElementObject() { try { ! return (ElementObject)element_stack_.pop(); } catch (EmptyStackException exc) *************** *** 147,160 **** * @return the dataobject */ ! public Object takeObject(String key) { return data_map_.remove(key); } - - public StringBuffer getResult() - { - return result_; - } - } --- 122,129 ---- * @return the dataobject */ ! public Object removeObject(String key) { return data_map_.remove(key); } } Index: InitInitializeStateMachine.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/InitInitializeStateMachine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InitInitializeStateMachine.java 22 Feb 2002 13:14:34 -0000 1.2 --- InitInitializeStateMachine.java 28 Feb 2002 06:40:19 -0000 1.3 *************** *** 31,40 **** import edu.iicm.xpg.transitions.SetSearchPathTransition; - - //---------------------------------------------------------------------- /** * This class implements the Initializer Interface. ! * It register the States and Transitions for the * Statemachine which is used to initialize the * Document Statemachine. --- 31,38 ---- import edu.iicm.xpg.transitions.SetSearchPathTransition; //---------------------------------------------------------------------- /** * This class implements the Initializer Interface. ! * It registers the States and Transitions for the * Statemachine which is used to initialize the * Document Statemachine. *************** *** 45,48 **** --- 43,47 ---- * * @author Stefan Thalauer + * @author Günther Brand * @version $Revision$ */ *************** *** 105,109 **** { state_machine_ = state_machine; - // state_machine_.setUserDefinedDataObject(data_); state_machine_.registerState(new PrimitiveState(),STATE_TOP_LEVEL_FILE); --- 104,107 ---- Index: InitParser.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/InitParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InitParser.java 22 Feb 2002 13:14:34 -0000 1.2 --- InitParser.java 28 Feb 2002 06:40:19 -0000 1.3 *************** *** 51,61 **** { super(); DFactory transition_factory = new DFactory(DEFAULT_SEARCH_PATH); data_.putObject(TRANSITION_FATORY, transition_factory); config_file_= config_file; initializer_ = new InitInitializeStateMachine(); - state_machine_ = new PrimitiveStateMachine(); - - handler_ = new XMLHandler(state_machine_,data_); } --- 51,59 ---- { super(); + DFactory transition_factory = new DFactory(DEFAULT_SEARCH_PATH); data_.putObject(TRANSITION_FATORY, transition_factory); config_file_= config_file; initializer_ = new InitInitializeStateMachine(); } *************** *** 73,79 **** initializer_.initialize(state_machine_); - state_machine_=initializer_.getStateMachine(); data_.putObject(STATE_MACHINE,new_state_machine); - state_machine_.setUserDefinedDataObject(data_); parseFile(config_file_); --- 71,75 ---- Index: Initializer.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/Initializer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Initializer.java 22 Feb 2002 13:14:34 -0000 1.3 --- Initializer.java 28 Feb 2002 06:40:19 -0000 1.4 *************** *** 46,50 **** * @return the initialized Statemachine */ ! public PrimitiveStateMachine getStateMachine(); } --- 46,51 ---- * @return the initialized Statemachine */ ! ! public PrimitiveStateMachine getStateMachine(); } Index: Parser.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/Parser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Parser.java 22 Feb 2002 13:14:34 -0000 1.3 --- Parser.java 28 Feb 2002 06:40:19 -0000 1.4 *************** *** 20,36 **** ***********************************************************************/ - package edu.iicm.xpg.statemachine; - import java.io.FileReader; import java.io.File; import org.xml.sax.XMLReader; import org.xml.sax.InputSource; - import org.xml.sax.helpers.XMLReaderFactory; import org.xml.sax.SAXException; ! ! import org.dinopolis.util.DFactory; ! //---------------------------------------------------------------------- --- 20,31 ---- ***********************************************************************/ package edu.iicm.xpg.statemachine; import java.io.FileReader; import java.io.File; import org.xml.sax.XMLReader; import org.xml.sax.InputSource; import org.xml.sax.SAXException; ! import org.xml.sax.helpers.XMLReaderFactory; //---------------------------------------------------------------------- *************** *** 49,54 **** protected final static String XML_READER = "org.apache.xerces.parsers.SAXParser"; protected final static String PARSER_FEATURE_SCHEMA = "http://xml.org/sax/features/validation"; ! protected final static String PARSER_FEATURE_VALIDATING = "http://apache.org/xml/features/validation/schema"; ! protected final static String PARSER_FEATURE_VALIDATING_DYNAMIC ="http://apache.org/xml/features/validation/dynamic"; protected final static String STATE_MACHINE="doc_state_machine"; --- 44,49 ---- protected final static String XML_READER = "org.apache.xerces.parsers.SAXParser"; protected final static String PARSER_FEATURE_SCHEMA = "http://xml.org/sax/features/validation"; ! protected final static String PARSER_FEATURE_VALIDATING = "http://apache.org/xml/features/validation/schema"; ! protected final static String PARSER_FEATURE_VALIDATING_DYNAMIC ="http://apache.org/xml/features/validation/dynamic"; protected final static String STATE_MACHINE="doc_state_machine"; *************** *** 62,65 **** --- 57,63 ---- { data_ = new DataObject(); + state_machine_ = new PrimitiveStateMachine(); + state_machine_.setUserDefinedDataObject(data_); + handler_ = new XMLHandler(state_machine_,data_); try { *************** *** 74,89 **** //---------------------------------------------------------------------- /** ! * @param state_machine */ ! public Parser(PrimitiveStateMachine state_machine) ! { ! this(); ! state_machine_=state_machine; ! state_machine_.setUserDefinedDataObject(data_); ! handler_ = new XMLHandler(state_machine_,data_); } - //---------------------------------------------------------------------- /** --- 72,84 ---- //---------------------------------------------------------------------- /** ! * @deprecated */ ! public Parser(PrimitiveStateMachine state_machine) ! { ! this(); ! state_machine_ = state_machine; } //---------------------------------------------------------------------- /** *************** *** 103,106 **** --- 98,102 ---- try { + System.out.println("Begin Parsing"); FileReader file_reader = new FileReader(input_file); reader_.parse(new InputSource(file_reader)); *************** *** 113,139 **** } } - - - //---------------------------------------------------------------------- - /** - * @return the object that has been generated - */ - - public synchronized Object getResult() - { - return(data_.getResult().toString()); - } - - //---------------------------------------------------------------------- - /** - * This was just a test function - * @return the object that has been generated - */ - - // public synchronized PrimitiveStateMachine getStateMachine() - // { - // return (PrimitiveStateMachine) data_.getObject(STATE_MACHINE); - // } - //---------------------------------------------------------------------- --- 109,112 ---- Index: XMLHandler.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/XMLHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XMLHandler.java 22 Feb 2002 12:48:54 -0000 1.2 --- XMLHandler.java 28 Feb 2002 06:40:19 -0000 1.3 *************** *** 51,56 **** //---------------------------------------------------------------------- /** ! * @param configfile the filename of the configfile ! * @param filename the filename of the inputfile */ --- 51,56 ---- //---------------------------------------------------------------------- /** ! * @param state_machine the statemachine which handles the parsed states ! * @param data the DataObject for storing diverse data */ *************** *** 104,108 **** try { ! data_.setElementValue(new String(chars)); state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } --- 104,108 ---- try { ! data_.topElementObject().setElementValue(new String(chars)); state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } *************** *** 128,132 **** try { ! data_.pushAttributes(attributes); state_machine_.input(new XMLInput(Const.XML_START_TAG,name)); } --- 128,136 ---- try { ! ElementObject element_object = new ElementObject(); ! element_object.setElementName(name); ! element_object.setAttributes(attributes); ! data_.pushElementObject(element_object); ! state_machine_.input(new XMLInput(Const.XML_START_TAG,name)); } *************** *** 151,156 **** { state_machine_.input(new XMLInput(Const.XML_END_TAG,name)); ! data_.setElementValue(null); ! data_.popAttributes(); } catch(Exception exc) --- 155,159 ---- { state_machine_.input(new XMLInput(Const.XML_END_TAG,name)); ! data_.popElementObject(); } catch(Exception exc) |