KickJava   Java API By Example, From Geeks To Geeks.

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


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.OperationDesc;
19 import org.apache.axis.description.ParameterDesc;
20 import org.apache.axis.encoding.SerializationContext;
21 import org.apache.axis.utils.JavaUtils;
22 import org.apache.axis.utils.XMLUtils;
23 import org.w3c.dom.Element JavaDoc;
24 import org.xml.sax.helpers.AttributesImpl JavaDoc;
25
26 import javax.xml.namespace.QName JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 public class WSDDParameter extends WSDDElement
30 {
31     OperationDesc parent;
32     ParameterDesc parameter = new ParameterDesc();
33     
34     public WSDDParameter(Element JavaDoc e, OperationDesc parent)
35             throws WSDDException {
36         super(e);
37         this.parent = parent;
38         
39         // Get the parameter's name. If a qname is specified, use that,
40
// otherwise also look for a "name" attribute. (name specifies
41
// an unqualified name)
42
String JavaDoc nameStr = e.getAttribute(ATTR_QNAME);
43         if (nameStr != null && !nameStr.equals("")) {
44             parameter.setQName(XMLUtils.getQNameFromString(nameStr, e));
45         } else {
46             nameStr = e.getAttribute(ATTR_NAME);
47             if (nameStr != null && !nameStr.equals("")) {
48                 parameter.setQName(new QName JavaDoc(null, nameStr));
49             }
50         }
51         
52         String JavaDoc modeStr = e.getAttribute(ATTR_MODE);
53         if (modeStr != null && !modeStr.equals("")) {
54             parameter.setMode(ParameterDesc.modeFromString(modeStr));
55         }
56
57         String JavaDoc inHStr = e.getAttribute(ATTR_INHEADER);
58         if (inHStr != null) {
59             parameter.setInHeader(JavaUtils.isTrueExplicitly(inHStr));
60         }
61         String JavaDoc outHStr = e.getAttribute(ATTR_OUTHEADER);
62         if (outHStr != null) {
63             parameter.setOutHeader(JavaUtils.isTrueExplicitly(outHStr));
64         }
65         
66         String JavaDoc typeStr = e.getAttribute(ATTR_TYPE);
67         if (typeStr != null && !typeStr.equals("")) {
68             parameter.setTypeQName(XMLUtils.getQNameFromString(typeStr, e));
69         }
70
71         String JavaDoc itemQNameStr = e.getAttribute(ATTR_ITEMQNAME);
72         if (itemQNameStr != null && !itemQNameStr.equals("")) {
73             parameter.setItemQName(XMLUtils.getQNameFromString(itemQNameStr, e));
74         }
75
76         String JavaDoc itemTypeStr = e.getAttribute(ATTR_ITEMTYPE);
77         if (itemTypeStr != null && !itemTypeStr.equals("")) {
78             parameter.setItemType(XMLUtils.getQNameFromString(itemTypeStr, e));
79         }
80
81         Element JavaDoc docElem = getChildElement(e, ELEM_WSDD_DOC);
82         if (docElem != null) {
83             WSDDDocumentation documentation = new WSDDDocumentation(docElem);
84             parameter.setDocumentation(documentation.getValue());
85         }
86     }
87
88     public WSDDParameter() {
89     }
90
91     public WSDDParameter(ParameterDesc parameter) {
92         this.parameter = parameter;
93     }
94
95     /**
96      * Write this element out to a SerializationContext
97      */

98     public void writeToContext(SerializationContext context)
99             throws IOException JavaDoc {
100         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
101         
102         QName JavaDoc qname = parameter.getQName();
103         if (qname != null) {
104             if (qname.getNamespaceURI() != null &&
105                 !qname.getNamespaceURI().equals("")) {
106                 attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME,
107                                "CDATA",
108                                context.qName2String(parameter.getQName()));
109             } else {
110                 attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA",
111                                    parameter.getQName().getLocalPart());
112             }
113         }
114
115         // Write the mode attribute, but only if it's not the default (IN)
116
byte mode = parameter.getMode();
117         if (mode != ParameterDesc.IN) {
118             String JavaDoc modeStr = ParameterDesc.getModeAsString(mode);
119             attrs.addAttribute("", ATTR_MODE, ATTR_MODE, "CDATA", modeStr);
120         }
121
122         if (parameter.isInHeader()) {
123             attrs.addAttribute("", ATTR_INHEADER, ATTR_INHEADER,
124                                "CDATA", "true");
125         }
126
127         if (parameter.isOutHeader()) {
128             attrs.addAttribute("", ATTR_OUTHEADER, ATTR_OUTHEADER,
129                                "CDATA", "true");
130         }
131         
132         QName JavaDoc typeQName = parameter.getTypeQName();
133         if (typeQName != null) {
134             attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE, "CDATA",
135                                context.qName2String(typeQName));
136         }
137
138         QName JavaDoc itemQName = parameter.getItemQName();
139         if (itemQName != null) {
140             attrs.addAttribute("", ATTR_ITEMQNAME, ATTR_ITEMQNAME, "CDATA",
141                                context.qName2String(itemQName));
142         }
143
144         QName JavaDoc itemType = parameter.getItemType();
145         if (itemType != null) {
146             attrs.addAttribute("", ATTR_ITEMTYPE, ATTR_ITEMTYPE, "CDATA",
147                     context.qName2String(itemType));
148         }
149
150         context.startElement(getElementName(), attrs);
151         
152         if (parameter.getDocumentation() != null) {
153             WSDDDocumentation documentation = new WSDDDocumentation(parameter.getDocumentation());
154             documentation.writeToContext(context);
155         }
156                 
157         context.endElement();
158     }
159
160     public ParameterDesc getParameter() {
161         return parameter;
162     }
163
164     public void setParameter(ParameterDesc parameter) {
165         this.parameter = parameter;
166     }
167
168     /**
169      * Return the element name of a particular subclass.
170      */

171     protected QName JavaDoc getElementName() {
172         return WSDDConstants.QNAME_PARAM;
173     }
174 }
175
Popular Tags