Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: edu/iicm/xpg/statemachine/InitParser.java


1   /***********************************************************************
2    * @(#)$RCSfile: InitParser.java,v $   $Revision: 1.6 $ $Date: 2002/05/21 16:59:30 $
3    *
4    * Copyright (c) 2002 stefan thalauer
5    * 
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License (LGPL)
8    * as published by the Free Software Foundation; either version 2.1 of
9    * the License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public 
17   * License along with this program; if not, write to the
18   * Free Software Foundation, Inc., 
19   * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20   ***********************************************************************/
21  
22  
23  package edu.iicm.xpg.statemachine;
24  
25  import org.xml.sax.helpers.XMLReaderFactory;
26  import org.xml.sax.SAXException;
27  import java.io.IOException;
28  
29  import edu.iicm.xpg.util.Factory;
30  
31  
32  //----------------------------------------------------------------------
33  /**
34   * @author Stefan Thalauer
35   * @version $revision$
36   */
37  
38  public class InitParser extends Parser
39    implements Initializer
40  {
41    protected String config_file_;
42    protected Initializer initializer_;
43  
44    protected final static String[]  DEFAULT_SEARCH_PATH={"edu.iicm.xpg.transitions"};
45  
46  
47  //----------------------------------------------------------------------
48  /**
49   * @param config_file
50   * @exception IllegalArgumentException thrown if config_file is null
51   */
52   
53    public InitParser(String config_file)  
54      throws IllegalArgumentException,SAXException
55    {    
56      super();
57      init(config_file);
58    }
59  
60  //----------------------------------------------------------------------
61  /**
62   * @param config_file
63   * @exception IllegalArgumentException thrown if config_file is null
64   */
65   
66    public InitParser(String config_file,String xml_reader)  
67      throws IllegalArgumentException,SAXException
68    {    
69      super(xml_reader);
70      init(config_file);
71    }
72  
73  //----------------------------------------------------------------------
74  /**
75   */
76    protected void init(String config_file)
77      throws IllegalArgumentException
78    {
79        if (config_file == null)
80      {
81        throw (new IllegalArgumentException
82               ("configfile of InitParser is null!"));
83      }
84  
85      Factory transition_factory = new Factory(DEFAULT_SEARCH_PATH);
86      data_.putObject(TRANSITION_FATORY, transition_factory);
87      config_file_= config_file;
88      initializer_ = new InitInitializeStateMachine();
89    }
90  
91  
92  //----------------------------------------------------------------------
93  /**
94   * initialize the statemachine with the initializer
95   * @param new_state_machine the statemachine that should be initialized
96   * @return
97   * @exception IllegalArgumentException thrown if new_state_machine is null
98   */
99  
100   public void initialize(PrimitiveStateMachine new_state_machine)
101     throws IllegalArgumentException,SAXException,IOException
102   {    
103     if (new_state_machine == null)
104     {
105       throw (new IllegalArgumentException
106              ("new_state_machine in initialize is null!"));
107     }
108 
109     setFeatures();
110     setHandlers();
111     
112     initializer_.initialize(state_machine_);
113     data_.putObject(STATE_MACHINE,new_state_machine);
114 
115     parseFile(config_file_);
116   }
117 
118 //----------------------------------------------------------------------
119 /**
120  * get the initialized statemachine
121  * @return the initialized Statemachine
122  */
123 
124   public PrimitiveStateMachine getStateMachine()
125   {
126     return (PrimitiveStateMachine) data_.getObject(STATE_MACHINE);
127   }
128 }
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142