KickJava   Java API By Example, From Geeks To Geeks.

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


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.encoding.SerializationContext;
19 import org.apache.axis.utils.Messages;
20 import org.apache.axis.utils.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22 import org.xml.sax.helpers.AttributesImpl JavaDoc;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Set JavaDoc;
30
31
32 /**
33  *
34  */

35 public class WSDDJAXRPCHandlerInfo
36     extends WSDDElement
37 {
38     private String JavaDoc _classname;
39     private Map JavaDoc _map;
40     private QName JavaDoc[] _headers;
41     
42     /**
43      * Default constructor
44      */

45     public WSDDJAXRPCHandlerInfo()
46     {
47     }
48
49     /**
50      *
51      * @param e (Element) XXX
52      * @throws WSDDException XXX
53      */

54     public WSDDJAXRPCHandlerInfo(Element JavaDoc e)
55         throws WSDDException
56     {
57         super(e);
58         
59         String JavaDoc classnameStr = e.getAttribute(ATTR_CLASSNAME);
60         if (classnameStr != null && !classnameStr.equals("")) {
61             _classname = classnameStr;
62         }
63         else
64             throw new WSDDException(Messages.getMessage("noClassNameAttr00"));
65         
66         Element JavaDoc[] elements = getChildElements(e, ELEM_WSDD_PARAM);
67
68         // instanciate an empty Map
69
_map = new HashMap JavaDoc();
70         if (elements.length != 0) {
71             // Load up the map
72
for (int i = 0; i < elements.length; i++) {
73                 Element JavaDoc param = elements[i];
74                 String JavaDoc pname = param.getAttribute(ATTR_NAME);
75                 String JavaDoc value = param.getAttribute(ATTR_VALUE);
76                 _map.put(pname, value);
77             }
78         }
79         
80         elements = getChildElements(e, ELEM_WSDD_JAXRPC_HEADER);
81         if (elements.length != 0) {
82             java.util.ArrayList JavaDoc headerList = new java.util.ArrayList JavaDoc();
83             for (int i = 0; i < elements.length; i++) {
84                 Element JavaDoc qElem = elements[i];
85                 String JavaDoc headerStr = qElem.getAttribute(ATTR_QNAME);
86                 if (headerStr == null || headerStr.equals(""))
87                     throw new WSDDException(Messages.getMessage("noValidHeader"));
88
89                 QName JavaDoc headerQName = XMLUtils.getQNameFromString(headerStr, qElem);
90                 if (headerQName != null)
91                     headerList.add(headerQName);
92             }
93             QName JavaDoc[] headers = new QName JavaDoc[headerList.size()];
94             _headers = (QName JavaDoc[]) headerList.toArray(headers);
95         }
96     }
97
98     protected QName JavaDoc getElementName()
99     {
100         return QNAME_JAXRPC_HANDLERINFO;
101     }
102
103     public String JavaDoc getHandlerClassName() {
104         return _classname;
105     }
106     
107     public void setHandlerClassName(String JavaDoc classname) {
108         _classname = classname;
109     }
110     
111     public Map JavaDoc getHandlerMap() {
112         return _map;
113     }
114     
115     public void setHandlerMap(Map JavaDoc map) {
116         _map = map;
117     }
118     
119     public QName JavaDoc[] getHeaders() {
120         return _headers;
121     }
122     
123     public void setHeaders(QName JavaDoc[] headers) {
124         _headers = headers;
125     }
126     
127     public void writeToContext(SerializationContext context)
128         throws IOException JavaDoc
129     {
130     AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
131     attrs.addAttribute("", ATTR_CLASSNAME, ATTR_CLASSNAME,
132                    "CDATA", _classname);
133     context.startElement(WSDDConstants.QNAME_JAXRPC_HANDLERINFO, attrs);
134
135     Map JavaDoc ht = _map;
136     if (ht != null) {
137         Set JavaDoc keys= ht.keySet();
138         Iterator JavaDoc iter = keys.iterator();
139         while (iter.hasNext()) {
140             String JavaDoc name = (String JavaDoc) iter.next();
141             String JavaDoc value = (String JavaDoc) ht.get(name);
142             attrs = new AttributesImpl JavaDoc();
143             attrs.addAttribute("",ATTR_NAME, ATTR_NAME, "CDATA", name);
144             attrs.addAttribute("",ATTR_VALUE, ATTR_VALUE, "CDATA", value);
145             context.startElement(WSDDConstants.QNAME_PARAM,attrs);
146             context.endElement();
147         }
148     }
149
150     if (_headers != null) {
151         for (int i=0 ; i < _headers.length ; i++) {
152         QName JavaDoc qname = _headers[i];
153         attrs = new AttributesImpl JavaDoc();
154         attrs.addAttribute("",ATTR_QNAME,ATTR_QNAME,"CDATA",context.qName2String(qname));
155         context.startElement(WSDDConstants.QNAME_JAXRPC_HEADER,attrs);
156         context.endElement();
157         }
158     }
159
160     context.endElement();
161     }
162
163 }
164
Popular Tags