1 package org.gscg;
2
3 import java.net.URL;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import nl.tudelft.simulation.language.io.URLResource;
8
9 import org.jdom.Element;
10 import org.jdom.input.SAXBuilder;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 /***
27 * Test the XML description of a model.
28 * <p>
29 * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
30 * University of Technology </a>, the Netherlands. <br>
31 * See for project information <a
32 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
33 *
34 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
35 * Delft, the Netherlands. All rights reserved.
36 *
37 * See for project information <a href="http://www.simulation.tudelft.nl/">
38 * www.simulation.tudelft.nl </a>.
39 *
40 * The source code and binary code of this software is proprietary information
41 * of Delft University of Technology.
42 *
43 * @author <a
44 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
45 * van Houten </a>
46 * @version $Revision: 1.1 $ $Date: 2005/06/16 12:34:03 $
47 * @since 1.1.3
48 */
49 public class TestHandlerXMLXSDDescription
50 {
51 /*** builder the xerces parser with validation turned on */
52 private static SAXBuilder builder = new SAXBuilder(
53 "org.apache.xerces.parsers.SAXParser", true);
54
55 static
56 {
57
58 TestHandlerXMLXSDDescription.builder.setFeature(
59 "http://xml.org/sax/features/validation", true);
60 TestHandlerXMLXSDDescription.builder.setFeature(
61 "http://apache.org/xml/features/validation/schema", true);
62
63
64 String xsd = URLResource.getResource("/handler.xsd").toExternalForm();
65 System.out.println("XSD: " + xsd);
66 TestHandlerXMLXSDDescription.builder
67 .setProperty(
68 "http://apache.org/xml/properties/schema/external-schemaLocation",
69 "http://www.simulation.tudelft.nl/dsol " + xsd);
70 }
71
72 /***
73 * constructs a new TestHandlerXMLXSDDescription
74 *
75 * @param model the model description
76 */
77 public TestHandlerXMLXSDDescription(final URL model)
78 {
79 super();
80 System.out.println("using " + model.toExternalForm());
81 try
82 {
83 Element rootElement = builder.build(model).getRootElement();
84
85
86
87
88 System.out.println("\n<<<<<< HANDLERS >>>>>>>");
89 for (Iterator i = rootElement.getChildren().iterator(); i.hasNext();)
90 {
91 Element groupElement = (Element) i.next();
92 System.out.println("GroupElement: " + groupElement);
93
94 String groupName = groupElement.getName();
95
96 if (groupName.equalsIgnoreCase("requestforquotehandlergroup"))
97 {
98 List children = groupElement.getChildren();
99
100 for (int ii = 0; ii < children.size(); ii++)
101 {
102 Element handlerElement = (Element) children.get(ii);
103 String handlerName = handlerElement.getName();
104 System.out.println("Handler name: " + handlerName);
105 }
106 } else if (groupName.equalsIgnoreCase("orderhandlergroup"))
107 {
108 List children = groupElement.getChildren();
109
110 for (int ii = 0; ii < children.size(); ii++)
111 {
112 Element handlerElement = (Element) children.get(ii);
113 String handlerName = handlerElement.getName();
114 System.out.println("Handler name: " + handlerName);
115 }
116 } else
117 {
118 System.err.println("Found unknown handler group name: "
119 + groupName);
120 }
121 }
122 } catch (Exception exception)
123 {
124 exception.printStackTrace();
125 }
126 }
127
128 /***
129 * @param args command-line arguments
130 */
131 public static void main(final String[] args)
132 {
133 new TestHandlerXMLXSDDescription(URLResource
134 .getResource("/handler.xml"));
135 }
136 }