comparison WebServiceToolWorkflow/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/extensions/schema/SchemaDeserializer.java @ 0:d5cd409b8a18 default tip

Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author ganjoo
date Tue, 07 Jun 2011 18:00:50 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d5cd409b8a18
1 /*
2 * (c) Copyright IBM Corp 2004, 2005
3 */
4
5 package edu.uga.cs.lsdis.meteors.wadls.extensions.schema;
6
7 import java.io.Serializable;
8 import java.util.Hashtable;
9 import java.util.Map;
10
11 import javax.wadls.Application;
12 import javax.wadls.WADLSException;
13 import javax.wadls.extensions.ExtensionDeserializer;
14 import javax.wadls.extensions.schema.Schema;
15 import javax.wadls.extensions.schema.SchemaImport;
16 import javax.wadls.extensions.schema.SchemaReference;
17 import javax.wadls.xml.WADLLocator;
18 import javax.wadls.WADLSException;
19 import javax.wadls.extensions.ExtensibilityElement;
20 import javax.wadls.extensions.ExtensionRegistry;
21 import javax.xml.namespace.QName;
22
23 import org.w3c.dom.Element;
24
25
26 import edu.uga.cs.lsdis.meteors.wadls.extensions.schema.SchemaConstants;
27 import edu.uga.cs.lsdis.meteors.wadls.Constants;
28 import edu.uga.cs.lsdis.meteors.wadls.util.xml.DOMUtils;
29 import edu.uga.cs.lsdis.meteors.wadls.util.xml.QNameUtils;
30
31 /**
32 * This class is used to deserialize <code>&lt;schema&gt;</code> elements into
33 * Schema instances.
34 *
35 * @see SchemaImpl
36 * @see SchemaSerializer
37 *
38 * @author Jeremy Hughes <hughesj@uk.ibm.com>
39 */
40 public class SchemaDeserializer implements Serializable
41 {
42
43 // Need to set this since a Definition is serializable and it contains an
44 // extension registry which contains one of these
45 public static final long serialVersionUID = 1;
46
47 private final Map allReferencedSchemas = new Hashtable();
48
49 private static ThreadLocal wsdlLocator = new ThreadLocal();
50
51 /**
52 * Set the WSDLLocator to be used by the deserializer on this thread.
53 *
54 * @param loc The WSDLLocator to be used.
55 *
56 * @see WSDLLocator
57 */
58 public static void setLocator(WADLLocator loc)
59 {
60 wsdlLocator.set(loc);
61 }
62 public Schema unmarshall(QName elementType,
63 Element el,
64 Application def)
65 throws WADLSException
66 {
67
68 Schema schema = new SchemaImpl();
69
70 schema.setElementType(elementType);
71 schema.setElement(el);
72 schema.setDocumentBaseURI(def.getDocumentBaseURI());
73
74 //TODO: check if the 'required' attribute needs to be set
75
76 // Go through the schema Element looking for child schemas
77 if(elementType.getLocalPart().equalsIgnoreCase("include")){
78
79 Element tempEl = el;
80
81 QName tempElType = QNameUtils.newQName(tempEl);
82
83 // Create the appropriate SchemaReference subclass to represent
84 // an <import>, an <include> or a <redefine>
85
86 SchemaReference sr = null;
87 String locationURI = null;
88
89
90 if (SchemaConstants.XSD_INCLUDE_QNAME_LIST.contains(tempElType))
91 {
92
93 // Create a new include. Don't use the
94 // ExtensionRegistry.createExtension()
95 // method as a Schema include is not a WSDL import.
96 sr = schema.createInclude();
97
98 sr.setId(DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID));
99
100 locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_HREF);
101
102 sr.setSchemaLocationURI(locationURI);
103
104 // Now the include is set up except for the pointer to the
105 // referenced LWS, add the include to the LightWeightSchema.
106 schema.addInclude(sr);
107 }
108
109 }
110 else{
111 Element tempEl = DOMUtils.getFirstChildElement(el);
112
113
114 for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl))
115 {
116
117 QName tempElType = QNameUtils.newQName(tempEl);
118
119 // Create the appropriate SchemaReference subclass to represent
120 // an <import>, an <include> or a <redefine>
121
122 SchemaReference sr = null;
123 String locationURI = null;
124
125 if (SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType))
126 {
127
128
129 // Create a new import. Don't use the
130 // ExtensionRegistry.createExtension()
131 // method as a Schema import is not a WSDL import.
132 SchemaImport im = schema.createImport();
133
134
135 im.setId(DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID));
136 im.setNamespaceURI(DOMUtils.getAttribute(tempEl, Constants.ATTR_NAMESPACE));
137
138 locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
139 im.setSchemaLocationURI(locationURI);
140
141 // Now the import is set up except for the point to the
142 // referenced LWS, add the import to the LightWeightSchema.
143 schema.addImport(im);
144 }
145 else
146 if (SchemaConstants.XSD_INCLUDE_QNAME_LIST.contains(tempElType))
147 {
148
149 // Create a new include. Don't use the
150 // ExtensionRegistry.createExtension()
151 // method as a Schema include is not a WSDL import.
152 sr = schema.createInclude();
153
154 sr.setId(DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID));
155
156 locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
157
158 sr.setSchemaLocationURI(locationURI);
159
160 // Now the include is set up except for the pointer to the
161 // referenced LWS, add the include to the LightWeightSchema.
162 schema.addInclude(sr);
163 }
164 else
165 if (SchemaConstants.XSD_REDEFINE_QNAME_LIST.contains(tempElType))
166 {
167 // Create a new redefine. Don't use the
168 // ExtensionRegistry.createExtension() method as a Schema redefine
169 // is not a WSDL import.
170 sr = schema.createRedefine();
171
172 sr.setId(DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID));
173
174 locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
175
176 sr.setSchemaLocationURI(locationURI);
177
178 // Now the redefine is set up except for the pointer to the
179 // referenced LWS, add the redefine to the LightWeightSchema.
180 schema.addRedefine(sr);
181 }
182 else
183 {
184 // The element isn't one we're interested in so look at the next
185 // one
186 continue;
187 }
188
189 } //end for
190 }
191
192 return schema;
193 }
194
195
196 }