KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.deployment.wsdd;
56
57 import org.jboss.axis.description.FaultDesc;
58 import org.jboss.axis.description.OperationDesc;
59 import org.jboss.axis.description.ParameterDesc;
60 import org.jboss.axis.description.ServiceDesc;
61 import org.jboss.axis.encoding.SerializationContext;
62 import org.jboss.axis.utils.JavaUtils;
63 import org.jboss.axis.utils.XMLUtils;
64 import org.w3c.dom.Element JavaDoc;
65 import org.xml.sax.helpers.AttributesImpl JavaDoc;
66
67 import javax.xml.namespace.QName JavaDoc;
68 import java.io.IOException JavaDoc;
69 import java.util.ArrayList JavaDoc;
70 import java.util.Iterator JavaDoc;
71
72 /**
73  * Parse the WSDD operation elements.
74  * <p/>
75  * Example:
76  * <operation name="name" qname="element QName" returnQName="QName">
77  * <parameter ... />
78  * </operation>
79  */

80 public class WSDDOperation extends WSDDElement
81 {
82    /**
83     * Holds all our actual data
84     */

85    OperationDesc desc = new OperationDesc();
86
87    /**
88     * Constructor
89     */

90    public WSDDOperation(OperationDesc desc)
91    {
92       this.desc = desc;
93    }
94
95    /**
96     * Constructor from XML
97     *
98     * @param e (Element) the <operation> element
99     * @param parent our ServiceDesc.
100     * @throws WSDDException XXX
101     */

102    public WSDDOperation(Element JavaDoc e, ServiceDesc parent)
103            throws WSDDException
104    {
105       super(e);
106
107       desc.setParent(parent);
108       desc.setName(e.getAttribute(ATTR_NAME));
109       desc.setOneWay(JavaUtils.isTrueExplicitly(e.getAttribute(ATTR_ONEWAY)));
110
111       String JavaDoc qNameStr = e.getAttribute(ATTR_QNAME);
112       if (qNameStr != null && !qNameStr.equals(""))
113          desc.setElementQName(XMLUtils.getQNameFromString(qNameStr, e));
114
115       String JavaDoc retQNameStr = e.getAttribute(ATTR_RETQNAME);
116       if (retQNameStr != null && !retQNameStr.equals(""))
117          desc.setReturnQName(XMLUtils.getQNameFromString(retQNameStr, e));
118
119       String JavaDoc retTypeStr = e.getAttribute(ATTR_RETTYPE);
120       if (retTypeStr != null && !retTypeStr.equals(""))
121          desc.setReturnType(XMLUtils.getQNameFromString(retTypeStr, e));
122
123       String JavaDoc retHStr = e.getAttribute(ATTR_RETHEADER);
124       if (retHStr != null)
125       {
126          desc.setReturnHeader(JavaUtils.isTrueExplicitly(retHStr));
127       }
128
129       Element JavaDoc[] parameters = getChildElements(e, ELEM_WSDD_PARAM);
130       for (int i = 0; i < parameters.length; i++)
131       {
132          Element JavaDoc paramEl = parameters[i];
133          WSDDParameter parameter = new WSDDParameter(paramEl, desc);
134          desc.addParameter(parameter.getParameter());
135       }
136
137       Element JavaDoc[] faultElems = getChildElements(e, ELEM_WSDD_FAULT);
138       for (int i = 0; i < faultElems.length; i++)
139       {
140          Element JavaDoc faultElem = faultElems[i];
141          WSDDFault fault = new WSDDFault(faultElem);
142          desc.addFault(fault.getFaultDesc());
143       }
144    }
145
146    /**
147     * Write this element out to a SerializationContext
148     */

149    public void writeToContext(SerializationContext context)
150            throws IOException JavaDoc
151    {
152       AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
153
154       if (desc.getReturnQName() != null)
155       {
156          attrs.addAttribute("", ATTR_RETQNAME, ATTR_RETQNAME,
157                  "CDATA",
158                  context.qName2String(desc.getReturnQName()));
159       }
160
161       if (desc.getReturnType() != null)
162       {
163          attrs.addAttribute("", ATTR_RETTYPE, ATTR_RETTYPE,
164                  "CDATA",
165                  context.qName2String(desc.getReturnType()));
166       }
167       if (desc.isReturnHeader())
168       {
169          attrs.addAttribute("", ATTR_RETHEADER, ATTR_RETHEADER,
170                  "CDATA", "true");
171       }
172
173       if (desc.getName() != null)
174       {
175          attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA", desc.getName());
176       }
177
178       if (desc.getElementQName() != null)
179       {
180          attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME,
181                  "CDATA",
182                  context.qName2String(desc.getElementQName()));
183       }
184
185       context.startElement(getElementName(), attrs);
186
187       ArrayList JavaDoc params = desc.getParameters();
188       for (Iterator JavaDoc i = params.iterator(); i.hasNext();)
189       {
190          ParameterDesc parameterDesc = (ParameterDesc)i.next();
191          WSDDParameter p = new WSDDParameter(parameterDesc);
192          p.writeToContext(context);
193       }
194
195       ArrayList JavaDoc faults = desc.getFaults();
196       if (faults != null)
197       {
198          for (Iterator JavaDoc i = faults.iterator(); i.hasNext();)
199          {
200             FaultDesc faultDesc = (FaultDesc)i.next();
201             WSDDFault f = new WSDDFault(faultDesc);
202             f.writeToContext(context);
203          }
204       }
205
206       context.endElement();
207    }
208
209    protected QName JavaDoc getElementName()
210    {
211       return QNAME_OPERATION;
212    }
213
214    public OperationDesc getOperationDesc()
215    {
216       return desc;
217    }
218 }
219
Popular Tags