comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/lib/SAWADLParser/src/edu/uga/cs/lsdis/meteors/wadls/GrammarsImpl.java @ 0:049760c677de default tip

Galaxy WSExtensions added successfully
author uga-galaxy-group
date Tue, 05 Jul 2011 19:34:18 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:049760c677de
1 /*
2 * (c) Copyright IBM Corp 2001, 2005
3 */
4
5 package edu.uga.cs.lsdis.meteors.wadls;
6
7 import java.net.URISyntaxException;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Vector;
13
14 import javax.wadls.Application;
15 import javax.wadls.ModelReference;
16 import javax.wadls.Grammars;
17 import javax.wadls.WADLSException;
18 import javax.wadls.extensions.schema.Schema;
19 import javax.wadls.extensions.ExtensibilityElement;
20 import javax.xml.namespace.QName;
21
22 import org.w3c.dom.Attr;
23 import org.w3c.dom.Element;
24
25 import edu.uga.cs.lsdis.meteors.wadls.util.SchemaUtils;
26
27 /**
28 * This class represents the <types> section of a WSDL document.
29 *
30 * @author Zixin Wu (wuzixin@uga.edu)
31 * @author Matthew J. Duftler (duftler@us.ibm.com)
32 */
33 public class GrammarsImpl implements Grammars
34 {
35 protected Application app = null; //WADLS Definition
36 protected List<ModelReference> modelReferences = null;
37 protected Element docEl = null;
38 protected List extElements = new Vector();
39 protected Map allSchemas = null;
40
41
42 public static final long serialVersionUID = 1;
43
44 public GrammarsImpl(Application app){
45 this.app = app;
46 }
47
48 public List getTopLevelSchemas(){
49 return SchemaUtils.getSchemas(this.extElements);
50 }
51
52 /**
53 * Get the DOM elements of all the schemas in this Types.
54 * @return A list of DOM elements of all the schemas in this Types.
55 */
56 public Map getSchemas(){
57 return this.allSchemas;
58 }
59
60 public void setSchemas(Map allSchemas){
61 this.allSchemas = allSchemas;
62 }
63
64
65 /**
66 * Get the DOM element of the first schema in this Types.
67 * @return The DOM element of the first schema in this Types.
68 */
69 public Schema getFirstSchema(){
70 return SchemaUtils.getFirstSchema(this.extElements);
71 }
72 public ModelReference getModelReference(){
73 if(modelReferences == null)
74 return null;
75 return modelReferences.get(0);
76 }
77
78 public List<ModelReference> getModelReferences(Element startElement, String path, Application app) throws WADLSException, URISyntaxException {
79 Element el = getXSDEle(startElement, path);
80 if (el == null)
81 return null;
82 String attrModelReference = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF);
83 if (attrModelReference.equals(""))
84 return null;
85 List<ModelReference> mrefs = ModelReferenceImpl.getModelReferences(attrModelReference, app);
86 if(mrefs.size() == 0)
87 return null;
88 return mrefs;
89 }
90 public ModelReference getModelReference(Element startElement, String path, Application app) throws WADLSException, URISyntaxException{
91 List<ModelReference> mrefs = getModelReferences(startElement, path, app);
92 return mrefs.get(0);
93 }
94
95
96 private Element getXSDEle(Element startElement, String path) throws WADLSException{
97 if (path == null || path == "")
98 return startElement;
99 String eleName = startElement.getLocalName();
100 if (eleName.equals("element")){ //search the target from <element ...
101 return SchemaUtils.findXSDEleOnEle(startElement, path, this);
102 }
103 else if (eleName.equals("complexType")){ //search the target from <complexType ...
104 return SchemaUtils.findXSDEleOnComplexType(startElement, path, this);
105 }
106 else{ //error
107 WADLSException wsdlsExc = new WADLSException(WADLSException.PATH_ERROR,
108 "simpleType cannot has path");
109 throw wsdlsExc;
110 }
111 }
112
113
114
115 /**
116 * Get all the extensibility elements defined here.
117 */
118
119 /**
120 * Set the modelReference.
121 *
122 * @param modelReference The desired modelReference.
123 */
124 public void addModelReference(ModelReference modelReference){
125 if(modelReferences == null)
126 modelReferences = new ArrayList<ModelReference>();
127 modelReferences.add(0, modelReference);
128 }
129
130 public List<ModelReference> getModelReferences() {
131 return modelReferences;
132 }
133
134 public void setModelReferences(List<ModelReference> refs) {
135 modelReferences = refs;
136 }
137
138 /**
139 * Set the documentation element for this document. This dependency
140 * on org.w3c.dom.Element should eventually be removed when a more
141 * appropriate way of representing this information is employed.
142 *
143 * @param docEl the documentation element
144 */
145 public void setDocumentationElement(Element docEl)
146 {
147 this.docEl = docEl;
148 }
149
150 public void setModelReferences(Element startElement, String path, List<ModelReference> refs) throws WADLSException {
151 for(ModelReference ref : refs) {
152 addModelReference(startElement, path, ref);
153 }
154 }
155
156 public void addModelReference(Element startElement, String path, ModelReference modelReference) throws WADLSException{
157 Element el = getXSDEle(startElement, path);
158
159 if (modelReference != null){
160 String strModelReference = modelReference.value();
161 Attr attr = el.getAttributeNodeNS(
162 Constants.NS_URI_WADLS, Constants.ATTR_MODELREF);
163 if(attr == null) {
164 attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF);
165 attr.setPrefix(Constants.PREFIX_WSDLS);
166 el.setAttributeNodeNS(attr);
167 }
168 String value = attr.getValue();
169 if(value != null) {
170 value += " " + strModelReference;
171 } else {
172 value = strModelReference;
173 }
174 attr.setValue(value);
175 modelReference.setParent(el);
176 }
177 else
178 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_MODELREF);
179 }
180
181
182 /**
183 * Get the documentation element. This dependency on org.w3c.dom.Element
184 * should eventually be removed when a more appropriate way of
185 * representing this information is employed.
186 *
187 * @return the documentation element
188 */
189 public Element getDocumentationElement()
190 {
191 return docEl;
192 }
193
194 public void setLoweringSchemaMapping(Element startElement, String path, String schemaMapping) throws WADLSException{
195 Element el = getXSDEle(startElement, path);
196 if (schemaMapping != null){
197 Attr attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING);
198 attr.setPrefix(Constants.PREFIX_WSDLS);
199 attr.setValue(schemaMapping);
200 el.setAttributeNodeNS(attr);
201 }
202 else
203 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING);
204 }
205
206 public void setLiftingSchemaMapping(Element startElement, String path, String schemaMapping) throws WADLSException{
207 Element el = getXSDEle(startElement, path);
208 if (schemaMapping != null){
209 Attr attr = el.getOwnerDocument().createAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING);
210 attr.setPrefix(Constants.PREFIX_WSDLS);
211 attr.setValue(schemaMapping);
212 el.setAttributeNodeNS(attr);
213 }
214 else
215 el.removeAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING);
216 }
217 public String getLoweringSchemaMapping(Element startElement, String path) throws WADLSException{
218 Element el = getXSDEle(startElement, path);
219 if (el == null)
220 return null;
221 String attrSchemaMapping = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LOWERINGSCHEMAMAPPING);
222 if (attrSchemaMapping == "")
223 return null;
224 return attrSchemaMapping;
225
226 }
227
228 public String getLiftingSchemaMapping(Element startElement, String path) throws WADLSException{
229 Element el = getXSDEle(startElement, path);
230 if (el == null)
231 return null;
232 String attrSchemaMapping = el.getAttributeNS(Constants.NS_URI_WADLS, Constants.ATTR_LIFTINGSCHEMAMAPPING);
233 if (attrSchemaMapping == "")
234 return null;
235 return attrSchemaMapping;
236
237 }
238
239
240 /**
241 * Add an extensibility element.
242 *
243 * @param extElement the extensibility element to be added
244 */
245
246
247 /**
248 * Get all the extensibility elements defined here.
249 */
250
251
252 public String toString()
253 {
254 StringBuffer strBuf = new StringBuffer();
255
256 strBuf.append("Types:");
257
258 if (extElements != null)
259 {
260 Iterator extIterator = extElements.iterator();
261
262 while (extIterator.hasNext())
263 {
264 strBuf.append("\n" + extIterator.next());
265 }
266 }
267
268 return strBuf.toString();
269 }
270
271
272 }