Mercurial > repos > ganjoo > webservice_toolsuite
comparison WebServiceToolWorkflow/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/ParamsImpl.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 package edu.uga.cs.lsdis.meteors.wadls; | |
2 | |
3 import java.net.URISyntaxException; | |
4 import java.util.ArrayList; | |
5 import java.util.Iterator; | |
6 import java.util.List; | |
7 import java.util.Map; | |
8 import java.util.Vector; | |
9 | |
10 import javax.wadls.Application; | |
11 import javax.wadls.ModelReference; | |
12 import javax.wadls.Params; | |
13 import javax.wadls.WADLSException; | |
14 import javax.wadls.extensions.schema.Schema; | |
15 import javax.xml.namespace.QName; | |
16 | |
17 import org.w3c.dom.Attr; | |
18 import org.w3c.dom.Element; | |
19 | |
20 import edu.uga.cs.lsdis.meteors.wadls.util.SchemaUtils; | |
21 | |
22 /** | |
23 * This class represents the <types> section of a WSDL document. | |
24 * | |
25 * @author Zixin Wu (wuzixin@uga.edu) | |
26 * @author Matthew J. Duftler (duftler@us.ibm.com) | |
27 */ | |
28 public class ParamsImpl implements Params | |
29 { | |
30 protected List<ModelReference> modelRefs = null; | |
31 protected Application app = null; //WSDLS Definition | |
32 protected Element docEl = null; | |
33 protected List extElements = new Vector(); | |
34 protected Map allSchemas = null; | |
35 | |
36 public static final long serialVersionUID = 1; | |
37 | |
38 public ParamsImpl(Application app){ | |
39 this.app = app; | |
40 } | |
41 | |
42 public List getTopLevelSchemas(){ | |
43 return SchemaUtils.getSchemas(this.extElements); | |
44 } | |
45 | |
46 /** | |
47 * Get the DOM elements of all the schemas in this Types. | |
48 * @return A list of DOM elements of all the schemas in this Types. | |
49 */ | |
50 public Map getSchemas(){ | |
51 return this.allSchemas; | |
52 } | |
53 | |
54 public void setSchemas(Map allSchemas){ | |
55 this.allSchemas = allSchemas; | |
56 } | |
57 | |
58 | |
59 | |
60 public void addModelReference (ModelReference modelReference){ | |
61 if (this.modelRefs == null) | |
62 modelRefs= new ArrayList<ModelReference> (); | |
63 modelRefs.add(modelReference); | |
64 } | |
65 | |
66 | |
67 /** | |
68 * Get the modelReference of this operation. | |
69 * | |
70 * @return the modelReference value | |
71 */ | |
72 | |
73 public ModelReference getModelReference(){ | |
74 if(modelRefs == null) | |
75 return null; | |
76 return modelRefs.get(0); | |
77 } | |
78 /** | |
79 * Get the DOM element of the first schema in this Types. | |
80 * @return The DOM element of the first schema in this Types. | |
81 */ | |
82 public Schema getFirstSchema(){ | |
83 return SchemaUtils.getFirstSchema(this.extElements); | |
84 } | |
85 public List<ModelReference> getModelReferences() { | |
86 return modelRefs; | |
87 } | |
88 public void setModelReferences(List<ModelReference> refs) { | |
89 modelRefs = refs; | |
90 } | |
91 /** | |
92 * Get the XSD simpleType with the given name. | |
93 * @param name The QName of the type | |
94 * @return A DOM Element representing the simpleType | |
95 * @throws WADLSException | |
96 */ | |
97 | |
98 public Element getXSDElement(String xpath) throws WADLSException{ | |
99 Element returnElt = null; | |
100 Map schemas = this.getSchemas(); | |
101 Iterator it = schemas.values().iterator(); | |
102 while(it.hasNext()){ | |
103 Schema schema = (Schema)(it.next()); | |
104 Element schemaEle = schema.getElement(); | |
105 returnElt = this.getXSDElement(schemaEle, xpath); | |
106 if (returnElt != null) | |
107 return returnElt; | |
108 } | |
109 return null; | |
110 } | |
111 | |
112 /** | |
113 * Get the modelReference on the element located by the given path. | |
114 * @param startElement The starting element of the path | |
115 * @param path | |
116 * @return The modelReference | |
117 */ | |
118 public ModelReference getModelReference(Element startElement, String path, Application app) throws WADLSException, URISyntaxException{ | |
119 List<ModelReference> mrefs = getModelReferences(startElement, path, app); | |
120 return mrefs.get(0); | |
121 } | |
122 | |
123 /** | |
124 * Set the modelReference on the element located by the given path. | |
125 * @param startElement The starting element of the path | |
126 * @param path | |
127 * @param modelReference The desired modelReference | |
128 */ | |
129 public void addModelReference(Element startElement, String path, ModelReference modelReference) throws WADLSException{ | |
130 Element el = getXSDEle(startElement, path); | |
131 | |
132 if (modelReference != null){ | |
133 String strModelReference = modelReference.value(); | |
134 Attr attr = el.getAttributeNodeNS( | |
135 Constants.NS_URI_WADLS, Constants.ATTR_MODELREF); | |
136 if(attr == null) { | |
137 attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF); | |
138 attr.setPrefix(Constants.PREFIX_WSDLS); | |
139 el.setAttributeNodeNS(attr); | |
140 } | |
141 String value = attr.getValue(); | |
142 if(value != null) { | |
143 value += " " + strModelReference; | |
144 } else { | |
145 value = strModelReference; | |
146 } | |
147 attr.setValue(value); | |
148 modelReference.setParent(el); | |
149 } | |
150 else | |
151 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF); | |
152 } | |
153 | |
154 /** | |
155 * Get the liftingSchemaMapping on the element located by the given path. | |
156 * @param startElement The starting element of the path | |
157 * @param path | |
158 * @return The schemaMapping value | |
159 */ | |
160 public String getLiftingSchemaMapping(Element startElement, String path) throws WADLSException{ | |
161 Element el = getXSDEle(startElement, path); | |
162 if (el == null) | |
163 return null; | |
164 String attrSchemaMapping = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING); | |
165 if (attrSchemaMapping == "") | |
166 return null; | |
167 return attrSchemaMapping; | |
168 } | |
169 | |
170 /** | |
171 * Get the loweringSchemaMapping on the element located by the given path. | |
172 * @param startElement The starting element of the path | |
173 * @param path | |
174 * @return The schemaMapping value | |
175 */ | |
176 public String getLoweringSchemaMapping(Element startElement, String path) throws WADLSException{ | |
177 Element el = getXSDEle(startElement, path); | |
178 if (el == null) | |
179 return null; | |
180 String attrSchemaMapping = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING); | |
181 if (attrSchemaMapping == "") | |
182 return null; | |
183 return attrSchemaMapping; | |
184 } | |
185 | |
186 /** | |
187 * Set the liftingSchemaMapping on the element located by the given path. | |
188 * @param startElement The starting element of the path | |
189 * @param path | |
190 * @param schemaMapping The desired schemaMapping | |
191 */ | |
192 public void setLiftingSchemaMapping(Element startElement, String path, String schemaMapping) throws WADLSException{ | |
193 Element el = getXSDEle(startElement, path); | |
194 if (schemaMapping != null){ | |
195 Attr attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING); | |
196 attr.setPrefix(Constants.PREFIX_WSDLS); | |
197 attr.setValue(schemaMapping); | |
198 el.setAttributeNodeNS(attr); | |
199 } | |
200 else | |
201 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING); | |
202 } | |
203 | |
204 /** | |
205 * Set the loweringSchemaMapping on the element located by the given path. | |
206 * @param startElement The starting element of the path | |
207 * @param path | |
208 * @param schemaMapping The desired schemaMapping | |
209 */ | |
210 public void setLoweringSchemaMapping(Element startElement, String path, String schemaMapping) throws WADLSException{ | |
211 Element el = getXSDEle(startElement, path); | |
212 if (schemaMapping != null){ | |
213 Attr attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING); | |
214 attr.setPrefix(Constants.PREFIX_WSDLS); | |
215 attr.setValue(schemaMapping); | |
216 el.setAttributeNodeNS(attr); | |
217 } | |
218 else | |
219 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING); | |
220 } | |
221 | |
222 private Element getXSDEle(Element startElement, String path) throws WADLSException{ | |
223 if (path == null || path == "") | |
224 return startElement; | |
225 String eleName = startElement.getLocalName(); | |
226 if (eleName.equals("element")){ //search the target from <element ... | |
227 return SchemaUtils.findXSDEleOnEle(startElement, path, this); | |
228 } | |
229 else if (eleName.equals("complexType")){ //search the target from <complexType ... | |
230 return SchemaUtils.findXSDEleOnComplexType(startElement, path, this); | |
231 } | |
232 else{ //error | |
233 WADLSException wsdlsExc = new WADLSException(WADLSException.PATH_ERROR, | |
234 "simpleType cannot has path"); | |
235 throw wsdlsExc; | |
236 } | |
237 } | |
238 | |
239 /** | |
240 * Return an XML Schema Element by locating it from the XSD Element startElement and using the path. | |
241 * @param startElement | |
242 * @param path | |
243 * @return an XML Schema Element | |
244 * @throws WADLSException | |
245 */ | |
246 public Element getXSDElement(Element startElement, String path) throws WADLSException{ | |
247 return SchemaUtils.findXSDEleOnEle(startElement, path, this); | |
248 } | |
249 | |
250 /** | |
251 * Return a list of XSD elements contained in the ComplexType startElement, search in only 1 level depth. | |
252 * @param startXSDElement | |
253 * @return A list of XSD elements contained in the startElement. If no XSD element is contained, the list has 0 element. | |
254 * @throws WADLSException | |
255 */ | |
256 public List getXSDElementsInComplexType(Element startXSDElement) throws WADLSException{ | |
257 return SchemaUtils.listXSDElesInComplexType(startXSDElement); | |
258 } | |
259 | |
260 /** | |
261 * Return a list of XSD elements contained in the startElement, search in only 1 level depth. | |
262 * @param startXSDComplexType | |
263 * @return A list of XSD elements contained in the startElement. If no XSD element is contained, the list has 0 element. | |
264 * @throws WADLSException | |
265 */ | |
266 public List getXSDElementsInElement(Element startXSDComplexType) throws WADLSException{ | |
267 return SchemaUtils.listXSDElesInEle(startXSDComplexType, this); | |
268 } | |
269 | |
270 | |
271 | |
272 /** | |
273 * Set the documentation element for this document. This dependency | |
274 * on org.w3c.dom.Element should eventually be removed when a more | |
275 * appropriate way of representing this information is employed. | |
276 * | |
277 * @param docEl the documentation element | |
278 */ | |
279 public void setDocumentationElement(Element docEl) | |
280 { | |
281 this.docEl = docEl; | |
282 } | |
283 | |
284 /** | |
285 * Get the documentation element. This dependency on org.w3c.dom.Element | |
286 * should eventually be removed when a more appropriate way of | |
287 * representing this information is employed. | |
288 * | |
289 * @return the documentation element | |
290 */ | |
291 public Element getDocumentationElement() | |
292 { | |
293 return docEl; | |
294 } | |
295 | |
296 /** | |
297 * Add an extensibility element. | |
298 * | |
299 * @param extElement the extensibility element to be added | |
300 */ | |
301 | |
302 | |
303 /** | |
304 * Get all the extensibility elements defined here. | |
305 */ | |
306 public List getExtensibilityElements() | |
307 { | |
308 return extElements; | |
309 } | |
310 | |
311 public String toString() | |
312 { | |
313 StringBuffer strBuf = new StringBuffer(); | |
314 | |
315 strBuf.append("Types:"); | |
316 | |
317 if (extElements != null) | |
318 { | |
319 Iterator extIterator = extElements.iterator(); | |
320 | |
321 while (extIterator.hasNext()) | |
322 { | |
323 strBuf.append("\n" + extIterator.next()); | |
324 } | |
325 } | |
326 | |
327 return strBuf.toString(); | |
328 } | |
329 | |
330 public List<ModelReference> getModelReferences(Element startElement, String path, Application app) throws WADLSException, URISyntaxException { | |
331 Element el = getXSDEle(startElement, path); | |
332 if (el == null) | |
333 return null; | |
334 String attrModelReference = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF); | |
335 if (attrModelReference.equals("")) | |
336 return null; | |
337 List<ModelReference> mrefs = ModelReferenceImpl.getModelReferences(attrModelReference, app); | |
338 if(mrefs.size() == 0) | |
339 return null; | |
340 return mrefs; | |
341 } | |
342 public void setModelReferences(Element startElement, String path, List<ModelReference> refs) throws WADLSException { | |
343 for(ModelReference ref : refs) { | |
344 addModelReference(startElement, path, ref); | |
345 } | |
346 } | |
347 } |