KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > deployment > wsdd > WSDDOperation


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.deployment.wsdd;
17
18 import org.apache.axis.description.FaultDesc;
19 import org.apache.axis.description.OperationDesc;
20 import org.apache.axis.description.ParameterDesc;
21 import org.apache.axis.description.ServiceDesc;
22 import org.apache.axis.encoding.SerializationContext;
23 import org.apache.axis.utils.JavaUtils;
24 import org.apache.axis.utils.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.helpers.AttributesImpl JavaDoc;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 /**
34  *
35  * Parse the WSDD operation elements.
36  *
37  * Example:
38  * <operation name="name" qname="element QName" returnQName="QName">
39  * <parameter ... />
40  * </operation>
41  *
42  */

43 public class WSDDOperation extends WSDDElement
44 {
45     /** Holds all our actual data */
46     OperationDesc desc = new OperationDesc();
47
48     /**
49      * Constructor
50      */

51     public WSDDOperation(OperationDesc desc) {
52         this.desc = desc;
53     }
54         
55     /**
56      * Constructor from XML
57      *
58      * @param e (Element) the <operation> element
59      * @param parent our ServiceDesc.
60      * @throws WSDDException XXX
61      */

62     public WSDDOperation(Element JavaDoc e, ServiceDesc parent)
63         throws WSDDException
64     {
65         super(e);
66
67         desc.setParent(parent);
68         desc.setName(e.getAttribute(ATTR_NAME));
69
70         String JavaDoc qNameStr = e.getAttribute(ATTR_QNAME);
71         if (qNameStr != null && !qNameStr.equals(""))
72             desc.setElementQName(XMLUtils.getQNameFromString(qNameStr, e));
73         
74         String JavaDoc retQNameStr = e.getAttribute(ATTR_RETQNAME);
75         if (retQNameStr != null && !retQNameStr.equals(""))
76             desc.setReturnQName(XMLUtils.getQNameFromString(retQNameStr, e));
77         
78         String JavaDoc retTypeStr = e.getAttribute(ATTR_RETTYPE);
79         if (retTypeStr != null && !retTypeStr.equals(""))
80             desc.setReturnType(XMLUtils.getQNameFromString(retTypeStr, e));
81
82         String JavaDoc retHStr = e.getAttribute(ATTR_RETHEADER);
83         if (retHStr != null) {
84             desc.setReturnHeader(JavaUtils.isTrueExplicitly(retHStr));
85         }
86
87         String JavaDoc retItemQName = e.getAttribute(ATTR_RETITEMQNAME);
88         if (retItemQName != null && !retItemQName.equals("")) {
89             ParameterDesc param = desc.getReturnParamDesc();
90             param.setItemQName(XMLUtils.getQNameFromString(retItemQName, e));
91         }
92
93         String JavaDoc retItemType = e.getAttribute(ATTR_RETITEMTYPE);
94         if (retItemType != null && !retItemType.equals("")) {
95             ParameterDesc param = desc.getReturnParamDesc();
96             param.setItemType(XMLUtils.getQNameFromString(retItemType, e));
97         }
98
99         String JavaDoc soapAction = e.getAttribute(ATTR_SOAPACTION);
100         if (soapAction != null) {
101             desc.setSoapAction(soapAction);
102         }
103
104         String JavaDoc mepString = e.getAttribute(ATTR_MEP);
105         if (mepString != null) {
106             desc.setMep(mepString);
107         }
108
109         Element JavaDoc [] parameters = getChildElements(e, ELEM_WSDD_PARAM);
110         for (int i = 0; i < parameters.length; i++) {
111             Element JavaDoc paramEl = parameters[i];
112             WSDDParameter parameter = new WSDDParameter(paramEl, desc);
113             desc.addParameter(parameter.getParameter());
114         }
115
116         Element JavaDoc [] faultElems = getChildElements(e, ELEM_WSDD_FAULT);
117         for (int i = 0; i < faultElems.length; i++) {
118             Element JavaDoc faultElem = faultElems[i];
119             WSDDFault fault = new WSDDFault(faultElem);
120             desc.addFault(fault.getFaultDesc());
121         }
122
123         Element JavaDoc docElem = getChildElement(e, ELEM_WSDD_DOC);
124         if (docElem != null) {
125             WSDDDocumentation documentation = new WSDDDocumentation(docElem);
126             desc.setDocumentation(documentation.getValue());
127         }
128     }
129
130     /**
131      * Write this element out to a SerializationContext
132      */

133     public void writeToContext(SerializationContext context)
134             throws IOException JavaDoc {
135         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
136
137         if (desc.getReturnQName() != null) {
138             attrs.addAttribute("", ATTR_RETQNAME, ATTR_RETQNAME,
139                                "CDATA",
140                                context.qName2String(desc.getReturnQName()));
141         }
142
143         if (desc.getReturnType() != null) {
144             attrs.addAttribute("", ATTR_RETTYPE, ATTR_RETTYPE,
145                                "CDATA",
146                                context.qName2String(desc.getReturnType()));
147         }
148         if (desc.isReturnHeader()) {
149             attrs.addAttribute("", ATTR_RETHEADER, ATTR_RETHEADER,
150                                "CDATA", "true");
151         }
152
153         if (desc.getName() != null) {
154             attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA", desc.getName());
155         }
156
157         if (desc.getElementQName() != null) {
158             attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME,
159                                "CDATA",
160                                context.qName2String(desc.getElementQName()));
161         }
162
163         QName JavaDoc retItemQName = desc.getReturnParamDesc().getItemQName();
164         if (retItemQName != null) {
165             attrs.addAttribute("", ATTR_RETITEMQNAME, ATTR_RETITEMQNAME,
166                                "CDATA",
167                                context.qName2String(retItemQName));
168         }
169
170         if (desc.getSoapAction() != null) {
171             attrs.addAttribute("", ATTR_SOAPACTION, ATTR_SOAPACTION, "CDATA", desc.getSoapAction());
172         }
173
174         context.startElement(getElementName(), attrs);
175
176         if (desc.getDocumentation() != null) {
177             WSDDDocumentation documentation = new WSDDDocumentation(desc.getDocumentation());
178             documentation.writeToContext(context);
179         }
180         
181         ArrayList JavaDoc params = desc.getParameters();
182         for (Iterator JavaDoc i = params.iterator(); i.hasNext();) {
183             ParameterDesc parameterDesc = (ParameterDesc) i.next();
184             WSDDParameter p = new WSDDParameter(parameterDesc);
185             p.writeToContext(context);
186         }
187         
188         ArrayList JavaDoc faults = desc.getFaults();
189         if (faults != null) {
190             for (Iterator JavaDoc i = faults.iterator(); i.hasNext();) {
191                 FaultDesc faultDesc = (FaultDesc) i.next();
192                 WSDDFault f = new WSDDFault(faultDesc);
193                 f.writeToContext(context);
194             }
195         }
196
197         context.endElement();
198     }
199
200     protected QName JavaDoc getElementName() {
201         return QNAME_OPERATION;
202     }
203
204     public OperationDesc getOperationDesc()
205     {
206         return desc;
207     }
208 }
209
Popular Tags