Update of /cvsroot/xpg-xml/edu/iicm/xpg/statemachine In directory usw-pr-cvs1:/tmp/cvs-serv31375/statemachine Modified Files: DataObject.java InitInitializeStateMachine.java InitParser.java Initializer.java Parser.java XMLElement.java XMLHandler.java Log Message: a little exception handling added Index: DataObject.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/DataObject.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataObject.java 21 Mar 2002 08:10:16 -0000 1.6 --- DataObject.java 4 Apr 2002 05:42:24 -0000 1.7 *************** *** 40,43 **** --- 40,46 ---- protected HashMap data_map_; + //---------------------------------------------------------------------- + /** + */ public DataObject() { *************** *** 48,53 **** --- 51,59 ---- //---------------------------------------------------------------------- /** + * get the 'actual' xml element * @return the top xml element */ + // FIXXME: should this function throw an exception if the stack is empty + // (but no EmptyStackException!) ? public XMLElement getXMLElement() { *************** *** 65,68 **** --- 71,75 ---- //---------------------------------------------------------------------- /** + * get the whole xml element stack * @return the xml element stack */ *************** *** 74,110 **** //---------------------------------------------------------------------- /** * @param key a description of the stored data * @param value the dataobject that should be stored */ public void putObject(String key, Object value) { // FIXXME: there should be a possibility storing multiple data with // the same key; possibly a stack for each data object will be used ! if ( data_map_.containsKey(key) ) ! { ! System.err.println("\"" + key + "\" allready exists inDataObject"); ! return; ! } ! data_map_.put(key, value); } //---------------------------------------------------------------------- /** * @param key the identificator of the stored data * @return the dataobject */ public Object getObject(String key) { ! return data_map_.get(key); } //---------------------------------------------------------------------- /** * @param key the identificator of the stored data * @return the dataobject */ public Object removeObject(String key) { ! return data_map_.remove(key); } } --- 81,141 ---- //---------------------------------------------------------------------- /** + * put a kind of data as object to the hashmap and store it by usage of key * @param key a description of the stored data * @param value the dataobject that should be stored + * @exception IllegalArgumentException thrown if one of the arguments is NULL */ public void putObject(String key, Object value) + throws IllegalArgumentException { + if (key == null || value == null) + { + throw (new IllegalArgumentException + ("put object into data object with key or value equal null!")); + } // FIXXME: there should be a possibility storing multiple data with // the same key; possibly a stack for each data object will be used ! if ( data_map_.containsKey(key) ) ! { ! System.err.println("\"" + key + "\" allready exists inDataObject"); ! return; ! } ! data_map_.put(key, value); } //---------------------------------------------------------------------- /** + * get data from the hashmap stored by key * @param key the identificator of the stored data * @return the dataobject + * @exception IllegalArgumentException thrown if key is null */ public Object getObject(String key) + throws IllegalArgumentException { ! if (key == null) ! { ! throw (new IllegalArgumentException ! ("get object with key equal null!")); ! } ! return data_map_.get(key); } //---------------------------------------------------------------------- /** + * get data from the hashmap stored by key and remove it * @param key the identificator of the stored data * @return the dataobject + * @exception IllegalArgumentException thrown if key is null */ public Object removeObject(String key) + throws IllegalArgumentException { ! if (key == null) ! { ! throw (new IllegalArgumentException ! ("remove object with key equal null!")); ! } ! return data_map_.remove(key); } } Index: InitInitializeStateMachine.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/InitInitializeStateMachine.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** InitInitializeStateMachine.java 8 Mar 2002 19:04:38 -0000 1.4 --- InitInitializeStateMachine.java 4 Apr 2002 05:42:24 -0000 1.5 *************** *** 31,34 **** --- 31,35 ---- import edu.iicm.xpg.transitions.SetSearchPathTransition; + //---------------------------------------------------------------------- /** *************** *** 43,47 **** * * @author Stefan Thalauer ! * @author Günther Brand * @version $Revision$ */ --- 44,48 ---- * * @author Stefan Thalauer ! * @author Guenther Brand * @version $Revision$ */ *************** *** 52,106 **** // elements ! public final static String XML_STM_CONFIG = "statemachine"; ! public final static String XML_PATH_DEF = "path"; ! public final static String XML_STATE_LIST = "states"; ! public final static String XML_START_STATE_DEF = "startstate"; ! public final static String XML_STATE_DEF = "state"; ! public final static String XML_TRANSITION_LIST = "transitions"; ! public final static String XML_TRANSITION_DEF = "transition"; ! public final static String XML_BEGINSTATE = "beginstate"; ! public final static String XML_NEXTSTATE = "nextstate"; ! public final static String XML_ELEMENT = "element"; ! public final static String XML_CLASSNAME = "classname"; // machine states ! public final static String STATE_TOP_LEVEL_FILE = "file top"; ! public final static String STATE_TOP_LEVEL_DOC_TYPE = "doctype top"; ! public final static String STATE_PATH_DEF = "path def"; ! public final static String STATE_STATE_LIST = "state list"; ! public final static String STATE_START_STATE_DEF = "start state def"; ! public final static String STATE_STATE_DEF = "state def"; ! public final static String STATE_TRANSITION_LIST = "transition list"; ! public final static String STATE_TRANSITION_DEF = "transition def"; ! public final static String STATE_BEGINSTATE = "beginstate"; ! public final static String STATE_NEXTSTATE = "nextstate"; ! public final static String STATE_ELEMENT = "element"; ! public final static String STATE_CLASSNAME = "classname"; ! public final static String STATE_FINISHED = "finished"; public InitInitializeStateMachine() { ! state_machine_=null; } //---------------------------------------------------------------------- /** * @return the initialized Statemachine */ public PrimitiveStateMachine getStateMachine() { ! return state_machine_; } //---------------------------------------------------------------------- /** ! * The following state machine is built here: Init a Statemachine ! * * @param state_machine the statemachine * @return */ public void initialize(PrimitiveStateMachine state_machine) { state_machine_ = state_machine; --- 53,124 ---- // elements ! protected final static String XML_STM_CONFIG = "statemachine"; ! protected final static String XML_PATH_DEF = "path"; ! protected final static String XML_STATE_LIST = "states"; ! protected final static String XML_START_STATE_DEF = "startstate"; ! protected final static String XML_STATE_DEF = "state"; ! protected final static String XML_TRANSITION_LIST = "transitions"; ! protected final static String XML_TRANSITION_DEF = "transition"; ! protected final static String XML_BEGINSTATE = "beginstate"; ! protected final static String XML_NEXTSTATE = "nextstate"; ! protected final static String XML_ELEMENT = "element"; ! protected final static String XML_CLASSNAME = "classname"; // machine states ! protected final static String STATE_TOP_LEVEL_FILE = "file top"; ! protected final static String STATE_TOP_LEVEL_DOC_TYPE = "doctype top"; ! protected final static String STATE_PATH_DEF = "path def"; ! protected final static String STATE_STATE_LIST = "state list"; ! protected final static String STATE_START_STATE_DEF = "start state def"; ! protected final static String STATE_STATE_DEF = "state def"; ! protected final static String STATE_TRANSITION_LIST = "transition list"; ! protected final static String STATE_TRANSITION_DEF = "transition def"; ! protected final static String STATE_BEGINSTATE = "beginstate"; ! protected final static String STATE_NEXTSTATE = "nextstate"; ! protected final static String STATE_ELEMENT = "element"; ! protected final static String STATE_CLASSNAME = "classname"; ! protected final static String STATE_FINISHED = "finished"; + //---------------------------------------------------------------------- + /** + */ public InitInitializeStateMachine() { ! state_machine_ = null; } //---------------------------------------------------------------------- /** + * get the (initialized) statemachine * @return the initialized Statemachine + * @exception IllegalStateException thrown if the statemachine is null */ public PrimitiveStateMachine getStateMachine() + throws IllegalStateException { ! if (state_machine_ == null) ! { ! throw (new IllegalStateException("statemachine is null!")); ! } ! return state_machine_; } //---------------------------------------------------------------------- /** ! * initialize the 'hardcoded' statemachine * @param state_machine the statemachine * @return + * @exception IllegalArgumentException thrown if state_machine is null */ public void initialize(PrimitiveStateMachine state_machine) + throws IllegalArgumentException { + if (state_machine == null) + { + throw (new IllegalArgumentException + ("statemachine to initialize is null!")); + } + state_machine_ = state_machine; *************** *** 301,304 **** --- 319,323 ---- catch (Exception exc) { + // FIXXME: think of a better exceptionhandling here! exc.printStackTrace(); } Index: InitParser.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/InitParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** InitParser.java 28 Feb 2002 06:40:19 -0000 1.3 --- InitParser.java 4 Apr 2002 05:42:24 -0000 1.4 *************** *** 28,31 **** --- 28,32 ---- import org.dinopolis.util.DFactory; + //---------------------------------------------------------------------- /** *************** *** 46,55 **** /** * @param config_file */ ! public InitParser(String config_file) { super(); DFactory transition_factory = new DFactory(DEFAULT_SEARCH_PATH); data_.putObject(TRANSITION_FATORY, transition_factory); --- 47,63 ---- /** * @param config_file + * @exception IllegalArgumentException thrown if config_file is null */ ! public InitParser(String config_file) ! throws IllegalArgumentException { super(); + if (config_file == null) + { + throw (new IllegalArgumentException + ("configfile of InitParser is null!")); + } DFactory transition_factory = new DFactory(DEFAULT_SEARCH_PATH); data_.putObject(TRANSITION_FATORY, transition_factory); *************** *** 60,70 **** //---------------------------------------------------------------------- /** ! * The following state machine is built here: * * @return ! * @exception Exception whatever can happen during initialization */ public void initialize(PrimitiveStateMachine new_state_machine) { setFeatures(); setHandlers(); --- 68,86 ---- //---------------------------------------------------------------------- /** ! * initialize the statemachine with the initializer ! * @param new_state_machine the statemachine that should be initialized * @return ! * @exception IllegalArgumentException thrown if new_state_machine is null */ public void initialize(PrimitiveStateMachine new_state_machine) + throws IllegalArgumentException { + if (new_state_machine == null) + { + throw (new IllegalArgumentException + ("new_state_machine in initialize is null!")); + } + setFeatures(); setHandlers(); *************** *** 78,81 **** --- 94,98 ---- //---------------------------------------------------------------------- /** + * get the initialized statemachine * @return the initialized Statemachine */ Index: Initializer.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/Initializer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Initializer.java 28 Feb 2002 06:40:19 -0000 1.4 --- Initializer.java 4 Apr 2002 05:42:24 -0000 1.5 *************** *** 33,47 **** { - //---------------------------------------------------------------------- /** * @param statemachine the statemachine * @return */ ! public void initialize(PrimitiveStateMachine statemachine); //---------------------------------------------------------------------- /** * @return the initialized Statemachine */ --- 33,50 ---- { //---------------------------------------------------------------------- /** + * initialize a statemachine * @param statemachine the statemachine * @return + * @exception IllegalArgumentException thrown if statemachine is null */ ! public void initialize(PrimitiveStateMachine statemachine) ! throws IllegalArgumentException; //---------------------------------------------------------------------- /** + * get the (initialized) statemachine * @return the initialized Statemachine */ Index: Parser.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/Parser.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Parser.java 8 Mar 2002 19:04:38 -0000 1.5 --- Parser.java 4 Apr 2002 05:42:24 -0000 1.6 *************** *** 66,69 **** --- 66,70 ---- catch (SAXException exc) { + // FIXXME: maybe think of a better exception handling here! exc.printStackTrace(); } *************** *** 72,89 **** //---------------------------------------------------------------------- /** - * @deprecated - */ - - public Parser(PrimitiveStateMachine state_machine) - { - this(); - state_machine_ = state_machine; - } - - //---------------------------------------------------------------------- - /** * Parse a file , calls the XMLHandler * @param file the xml file to parse ! * @return public */ --- 73,79 ---- //---------------------------------------------------------------------- /** * Parse a file , calls the XMLHandler * @param file the xml file to parse ! * @return */ *************** *** 93,96 **** --- 83,87 ---- if (!input_file.exists()) { + // FIXXME: better exception handling is needed here! System.err.println("Parser: File " + filename + " not existing"); System.exit(-1); *************** *** 104,108 **** catch (Exception exc) { ! System.err.println(exc); exc.printStackTrace(); System.exit(1); --- 95,99 ---- catch (Exception exc) { ! // FIXXME: System.exit ?? exc.printStackTrace(); System.exit(1); *************** *** 112,128 **** //---------------------------------------------------------------------- /** * @return */ public void setHandlers(XMLHandler handler) { ! reader_.setContentHandler(handler); ! reader_.setErrorHandler(handler); ! reader_.setDTDHandler(handler); } - //---------------------------------------------------------------------- /** * @return */ --- 103,128 ---- //---------------------------------------------------------------------- /** + * set the diverse handlers for the xml reader + * @param handler the handler that should be set * @return + * @exception IllegalArgumentException thrown if handler is null */ public void setHandlers(XMLHandler handler) + throws IllegalArgumentException { ! if (handler == null) ! { ! throw (new IllegalArgumentException ! ("handler in setHandlers is null!")); ! } ! reader_.setContentHandler(handler); ! reader_.setErrorHandler(handler); ! reader_.setDTDHandler(handler); } //---------------------------------------------------------------------- /** + * set the intern handler for the xml reader * @return */ *************** *** 135,142 **** } - //---------------------------------------------------------------------- /** ! * @param * @return */ --- 135,141 ---- } //---------------------------------------------------------------------- /** ! * set the features for the xml reader * @return */ Index: XMLElement.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/XMLElement.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XMLElement.java 21 Mar 2002 08:10:16 -0000 1.2 --- XMLElement.java 4 Apr 2002 05:42:24 -0000 1.3 *************** *** 25,28 **** --- 25,29 ---- import org.xml.sax.helpers.AttributesImpl; + //---------------------------------------------------------------------- /** *************** *** 39,70 **** //---------------------------------------------------------------------- /** - * @param name the name that should be set */ protected void setName(String name) { ! if ( name != null) ! name_ = name; ! else ; ! // FIXXME: send warning! } //---------------------------------------------------------------------- /** * @return the name */ - public String getName() { ! return name_; } //---------------------------------------------------------------------- /** * @param value the value that should be set */ - protected void setValue(String value) { value_ = value; } --- 40,98 ---- //---------------------------------------------------------------------- /** */ + public XMLElement() + { + name_ = null; + value_ = null; + attributes_ = null; + } + //---------------------------------------------------------------------- + /** + * set the name of the xml element + * @param name the name that should be set + * @exception IllegalArgumentException thrown if name is null + */ protected void setName(String name) + throws IllegalArgumentException { ! if (name == null) ! { ! throw (new IllegalArgumentException ! ("set name of xml element equal to null!")); ! } ! name_ = name; } //---------------------------------------------------------------------- /** + * get the name of the xml element * @return the name + * @exception IllegalStateException thrown if name is null */ public String getName() + throws IllegalStateException { ! if (name_ == null) ! { ! throw (new IllegalStateException("name of xml element is null!")); ! } ! return name_; } //---------------------------------------------------------------------- /** + * set the value (content) of the xml element * @param value the value that should be set + * @exception IllegalArgumentException thrown if value is null */ protected void setValue(String value) + throws IllegalArgumentException { + if (value == null) + { + throw (new IllegalArgumentException + ("set value of xml element equal to null!")); + } value_ = value; } *************** *** 72,78 **** //---------------------------------------------------------------------- /** * @return the value */ - public String getValue() { --- 100,106 ---- //---------------------------------------------------------------------- /** + * get the value of the xml element * @return the value */ public String getValue() { *************** *** 82,90 **** //---------------------------------------------------------------------- /** * @param attributes the attributes that should be set */ - protected void setAttributes(Attributes attributes) { attributes_ = new AttributesImpl(attributes); } --- 110,125 ---- //---------------------------------------------------------------------- /** + * set the attributes of the xml element * @param attributes the attributes that should be set + * @exception IllegalArgumentException thrown if attributes are null */ protected void setAttributes(Attributes attributes) + throws IllegalArgumentException { + if (attributes == null) + { + throw (new IllegalArgumentException + ("set attributes of xml element equal to null!")); + } attributes_ = new AttributesImpl(attributes); } *************** *** 92,98 **** //---------------------------------------------------------------------- /** * @return the attributes */ - public Attributes getAttributes() { --- 127,133 ---- //---------------------------------------------------------------------- /** + * get the attributes of the xml element * @return the attributes */ public Attributes getAttributes() { Index: XMLHandler.java =================================================================== RCS file: /cvsroot/xpg-xml/edu/iicm/xpg/statemachine/XMLHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XMLHandler.java 21 Mar 2002 08:10:16 -0000 1.6 --- XMLHandler.java 4 Apr 2002 05:42:24 -0000 1.7 *************** *** 34,41 **** * This class extends the DefaultHandler of the SAX2.0 API. * It sends the XMLInputs to the statemachine. - * This class replaces the callback functionality of - * the depricated classes: - * - InitStatemachine - * - Generator (Package: .xpg.generator) * * @author Stefan Thalauer --- 34,37 ---- *************** *** 53,61 **** --- 49,65 ---- * @param state_machine the statemachine which handles the parsed states * @param data the DataObject for storing diverse data + * @exception IllegalArgumentException thrown if state_machine or data is null */ public XMLHandler(PrimitiveStateMachine state_machine,DataObject data) + throws IllegalArgumentException { super(); + + if (state_machine == null || data == null) + { + throw (new IllegalArgumentException + ("initialize XMLHandler with statemachine or data equal null!")); + } state_machine_=state_machine; data_=data; *************** *** 104,114 **** try { ! data_.getXMLElement().setValue(new String(chars, start, length)); ! state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } catch(Exception exc) { ! exc.printStackTrace(); ! System.exit(1); } } --- 108,122 ---- try { ! if (length > 0) ! { ! data_.getXMLElement().setValue(new String(chars, start, length)); ! } ! state_machine_.input(new XMLInput(Const.XML_CHARS,chars,start,length)); } catch(Exception exc) { ! // FIXXME: think of better exception handling; no system.exit? ! exc.printStackTrace(); ! System.exit(1); } } *************** *** 130,134 **** XMLElement xml_element = new XMLElement(); xml_element.setName(name); ! xml_element.setAttributes(attributes); data_.getXMLElementStack().push(xml_element); --- 138,145 ---- XMLElement xml_element = new XMLElement(); xml_element.setName(name); ! if (attributes != null) ! { ! xml_element.setAttributes(attributes); ! } data_.getXMLElementStack().push(xml_element); |