View Javadoc

1   /*
2    * @(#) ScenarioParsingThread.java Mar 2, 2004
3    * 
4    * 
5    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
6    * Delft, the Netherlands. All rights reserved.
7    * 
8    * See for project information <a href="http://www.simulation.tudelft.nl/">
9    * www.simulation.tudelft.nl </a>.
10   * 
11   * The source code and binary code of this software is proprietary information
12   * of Delft University of Technology.
13   */
14  package org.gscg.experiment.scenario;
15  
16  import java.io.IOException;
17  import java.net.URL;
18  
19  import nl.tudelft.simulation.event.Event;
20  import nl.tudelft.simulation.event.EventListenerInterface;
21  import nl.tudelft.simulation.event.EventType;
22  import nl.tudelft.simulation.language.io.URLResource;
23  import nl.tudelft.simulation.logger.Logger;
24  
25  /***
26   * A ScenarioParsingThread.
27   * <p>
28   * 
29   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
30   * Delft, the Netherlands. All rights reserved.
31   * 
32   * See for project information <a href="http://www.simulation.tudelft.nl/">
33   * www.simulation.tudelft.nl </a>.
34   * 
35   * The source code and binary code of this software is proprietary information
36   * of Delft University of Technology.
37   * 
38   * @author <a
39   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
40   *         van Houten </a>
41   * @version $Revision: 1.2 $ $Date: 2005/08/03 08:52:50 $
42   * @since 1.0.0
43   */
44  public class ScenarioParsingThread extends Thread
45  {
46  	/*** SCENARIO_PARSED_EVENT */
47  	public static final EventType SCENARIO_PARSED_EVENT = new EventType(
48  			"SCENARIO_PARSED_EVENT");
49  
50  	/***
51  	 * the owning listener
52  	 * 
53  	 * @uml.property name="source"
54  	 * @uml.associationEnd
55  	 * @uml.property name="source"
56  	 */
57  	protected EventListenerInterface source = null;
58  
59  	/*** the scenario */
60  	protected URL scenario = null;
61  
62  	/***
63  	 * constructs a new ScenarioParsingThread
64  	 * 
65  	 * @param source the source of this thread
66  	 * @param scenario the scenario to parse
67  	 */
68  	public ScenarioParsingThread(final EventListenerInterface source,
69  			final URL scenario)
70  	{
71  		super("ScenarioParsingThread");
72  		this.source = source;
73  		this.scenario = scenario;
74  	}
75  
76  	/***
77  	 * @see java.lang.Runnable#run()
78  	 */
79  	public void run()
80  	{
81  		try
82  		{ // Let's find the XSD file
83  			String xsd = URLResource.getResource(
84  					"/nl/tudelft/simulation/scenario/parsing/scenario.xsd")
85  					.toExternalForm();
86  
87  			Scenario scenario = ScenarioParser
88  					.parseScenario(xsd, this.scenario);
89  			this.source
90  					.notify(new Event(SCENARIO_PARSED_EVENT, this, scenario));
91  		} catch (IOException exception)
92  		{
93  			Logger.warning(this, "run", exception);
94  		}
95  	}
96  }