View Javadoc

1   /*
2    * @(#) ExperimentParsingThread.java Mar 2, 2004
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.gameleader.interactionlayer.experiment;
14  
15  import java.awt.Component;
16  import java.net.URL;
17  
18  import nl.tudelft.simulation.event.EventType;
19  import nl.tudelft.simulation.language.io.URLResource;
20  import nl.tudelft.simulation.naming.InitialEventContext;
21  
22  import org.gscg.gameleader.interactionlayer.RemoteInteractionLayerInterface;
23  import org.jdom.Element;
24  import org.jdom.input.SAXBuilder;
25  
26  /***
27   * A ExperimentParsingThread
28   * <p>
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 href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
39   *         Jacobs </a>
40   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:34:06 $
41   * @since 1.0.0 <br>
42   * 
43   */
44  public class ExperimentParsingThread extends Thread
45  {
46  	/*** EXPERIMENT_PARSED_EVENT */
47  	public static final EventType EXPERIMENT_PARSED_EVENT = new EventType(
48  			"EXPERIMENT_PARSED_EVENT");
49  
50  	/*** builder the xerces parser with validation turned on */
51  	private static SAXBuilder builder = new SAXBuilder(
52  			"org.apache.xerces.parsers.SAXParser", true);
53  	static
54  	{
55  		// turns on Schema Validation with Xerces
56  		builder.setFeature("http://xml.org/sax/features/validation", true);
57  		builder.setFeature("http://apache.org/xml/features/validation/schema",
58  				true);
59  		// Let's find the XSD file
60  		String xsd = URLResource.getResource("/xsd/experiment.xsd")
61  				.toExternalForm();
62  		builder
63  				.setProperty(
64  						"http://apache.org/xml/properties/schema/external-schemaLocation",
65  						"http://www.simulation.tudelft.nl " + xsd);
66  	}
67  
68  	/*** the parent component */
69  	protected Component parent = null;
70  
71  	/*** the url */
72  	private URL experiment = null;
73  
74  	/***
75  	 * constructs a new ExperimentParsingThread
76  	 * 
77  	 * @param parent the parent component
78  	 * @param experiment the experiment to parse
79  	 */
80  	public ExperimentParsingThread(final Component parent, final URL experiment)
81  	{
82  		super();
83  		this.parent = parent;
84  		this.experiment = experiment;
85  	}
86  
87  	/***
88  	 * @see java.lang.Runnable#run()
89  	 */
90  	public void run()
91  	{
92  		try
93  		{
94  			// parse the experiment url
95  			Element experimentElement = builder.build(this.experiment)
96  					.getRootElement();
97  
98  			RemoteInteractionLayerInterface remoteInteractionLayer = null;
99  			// lookup the context and the remote interaction layer interface
100 			InitialEventContext context = new InitialEventContext();
101 			remoteInteractionLayer = (RemoteInteractionLayerInterface) context
102 					.lookup("/" + "game leader");
103 
104 			remoteInteractionLayer.parseExperiment(experimentElement);
105 		} catch (Exception exception)
106 		{
107 			System.out.println(exception.getMessage());
108 		}
109 	}
110 }