KickJava   Java API By Example, From Geeks To Geeks.

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


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.encoding.SerializationContext;
58 import org.jboss.axis.utils.Messages;
59 import org.jboss.axis.utils.XMLUtils;
60 import org.w3c.dom.Element JavaDoc;
61 import org.xml.sax.helpers.AttributesImpl JavaDoc;
62
63 import javax.xml.namespace.QName JavaDoc;
64 import java.io.IOException JavaDoc;
65 import java.util.HashMap JavaDoc;
66 import java.util.Iterator JavaDoc;
67 import java.util.Map JavaDoc;
68 import java.util.Set JavaDoc;
69
70
71 /**
72  *
73  */

74 public class WSDDJAXRPCHandlerInfo
75         extends WSDDElement
76 {
77    private String JavaDoc _classname;
78    private Map JavaDoc _map;
79    private QName JavaDoc[] _headers;
80
81    /**
82     * Default constructor
83     */

84    public WSDDJAXRPCHandlerInfo()
85    {
86    }
87
88    /**
89     * @param e (Element) XXX
90     * @throws WSDDException XXX
91     */

92    public WSDDJAXRPCHandlerInfo(Element JavaDoc e)
93            throws WSDDException
94    {
95       super(e);
96
97       String JavaDoc classnameStr = e.getAttribute(ATTR_CLASSNAME);
98       if (classnameStr != null && !classnameStr.equals(""))
99       {
100          _classname = classnameStr;
101       }
102       else
103          throw new WSDDException(Messages.getMessage("noClassNameAttr00"));
104
105       Element JavaDoc[] elements = getChildElements(e, ELEM_WSDD_PARAM);
106       if (elements.length != 0)
107       {
108          _map = new HashMap JavaDoc();
109
110          // Load up the map
111
for (int i = 0; i < elements.length; i++)
112          {
113             Element JavaDoc param = elements[i];
114             String JavaDoc pname = param.getAttribute(ATTR_NAME);
115             String JavaDoc value = param.getAttribute(ATTR_VALUE);
116             _map.put(pname, value);
117          }
118       }
119
120       elements = getChildElements(e, ELEM_WSDD_JAXRPC_HEADER);
121       if (elements.length != 0)
122       {
123          java.util.ArrayList JavaDoc headerList = new java.util.ArrayList JavaDoc();
124          for (int i = 0; i < elements.length; i++)
125          {
126             Element JavaDoc qElem = elements[i];
127             String JavaDoc headerStr = qElem.getAttribute(ATTR_QNAME);
128             if (headerStr == null || headerStr.equals(""))
129                throw new WSDDException(Messages.getMessage("noValidHeader"));
130
131             QName JavaDoc headerQName = XMLUtils.getQNameFromString(headerStr, qElem);
132             if (headerQName != null)
133                headerList.add(headerQName);
134          }
135          QName JavaDoc[] headers = new QName JavaDoc[headerList.size()];
136          _headers = (QName JavaDoc[])headerList.toArray(headers);
137       }
138    }
139
140    protected QName JavaDoc getElementName()
141    {
142       return QNAME_JAXRPC_HANDLERINFO;
143    }
144
145    public String JavaDoc getHandlerClassName()
146    {
147       return _classname;
148    }
149
150    public void setHandlerClassName(String JavaDoc classname)
151    {
152       _classname = classname;
153    }
154
155    public Map JavaDoc getHandlerMap()
156    {
157       return _map;
158    }
159
160    public void setHandlerMap(Map JavaDoc map)
161    {
162       _map = map;
163    }
164
165    public QName JavaDoc[] getHeaders()
166    {
167       return _headers;
168    }
169
170    public void setHeaders(QName JavaDoc[] headers)
171    {
172       _headers = headers;
173    }
174
175    public void writeToContext(SerializationContext context)
176            throws IOException JavaDoc
177    {
178       AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
179       attrs.addAttribute("", ATTR_CLASSNAME, ATTR_CLASSNAME,
180               "CDATA", _classname);
181       context.startElement(WSDDConstants.QNAME_JAXRPC_HANDLERINFO, attrs);
182
183       Map JavaDoc ht = _map;
184       if (ht != null)
185       {
186          Set JavaDoc keys = ht.keySet();
187          Iterator JavaDoc iter = keys.iterator();
188          while (iter.hasNext())
189          {
190             String JavaDoc name = (String JavaDoc)iter.next();
191             String JavaDoc value = (String JavaDoc)ht.get(name);
192             attrs = new AttributesImpl JavaDoc();
193             attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA", name);
194             attrs.addAttribute("", ATTR_VALUE, ATTR_VALUE, "CDATA", value);
195             context.startElement(WSDDConstants.QNAME_PARAM, attrs);
196             context.endElement();
197          }
198       }
199
200       if (_headers != null)
201       {
202          for (int i = 0; i < _headers.length; i++)
203          {
204             QName JavaDoc qname = _headers[i];
205             attrs = new AttributesImpl JavaDoc();
206             attrs.addAttribute("", ATTR_QNAME, ATTR_QNAME, "CDATA", context.qName2String(qname));
207             context.startElement(WSDDConstants.QNAME_JAXRPC_HEADER, attrs);
208             context.endElement();
209          }
210       }
211
212       context.endElement();
213    }
214
215 }
216
Popular Tags