KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-2002,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.components.logger.LogFactory;
19 import org.apache.axis.encoding.SerializationContext;
20 import org.apache.axis.handlers.HandlerInfoChainFactory;
21 import org.apache.axis.utils.ClassUtils;
22 import org.apache.axis.utils.Messages;
23 import org.apache.commons.logging.Log;
24 import org.w3c.dom.Element JavaDoc;
25 import org.xml.sax.helpers.AttributesImpl JavaDoc;
26
27 import javax.xml.namespace.QName JavaDoc;
28 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 /**
36  *
37  */

38 public class WSDDJAXRPCHandlerInfoChain extends WSDDHandler {
39     protected static Log log =
40         LogFactory.getLog(WSDDJAXRPCHandlerInfoChain.class.getName());
41     
42     private ArrayList JavaDoc _hiList;
43     private HandlerInfoChainFactory _hiChainFactory;
44     private String JavaDoc[] _roles;
45
46     /**
47      * Default constructor
48      */

49     public WSDDJAXRPCHandlerInfoChain() {
50     }
51
52     /**
53      *
54      * @param e (Element) XXX
55      * @throws WSDDException XXX
56      */

57     public WSDDJAXRPCHandlerInfoChain(Element JavaDoc e) throws WSDDException {
58         super(e);
59
60     ArrayList JavaDoc infoList = new ArrayList JavaDoc();
61     _hiList = new ArrayList JavaDoc();
62         Element JavaDoc[] elements = getChildElements(e, ELEM_WSDD_JAXRPC_HANDLERINFO);
63         if (elements.length != 0) {
64             for (int i = 0; i < elements.length; i++) {
65                 WSDDJAXRPCHandlerInfo handlerInfo =
66                     new WSDDJAXRPCHandlerInfo(elements[i]);
67         _hiList.add(handlerInfo);
68
69                 String JavaDoc handlerClassName = handlerInfo.getHandlerClassName();
70                 Class JavaDoc handlerClass = null;
71                 try {
72                     handlerClass = ClassUtils.forName(handlerClassName);
73                 } catch (ClassNotFoundException JavaDoc cnf) {
74                     log.error(Messages.getMessage("handlerInfoChainNoClass00", handlerClassName), cnf);
75                 }
76
77                 Map JavaDoc handlerMap = handlerInfo.getHandlerMap();
78                 QName JavaDoc[] headers = handlerInfo.getHeaders();
79                 
80                 if (handlerClass != null) {
81                     HandlerInfo JavaDoc hi =
82                         new HandlerInfo JavaDoc(handlerClass, handlerMap, headers);
83                     infoList.add(hi);
84                 }
85             }
86         }
87         _hiChainFactory = new HandlerInfoChainFactory(infoList);
88         
89         elements = getChildElements(e, ELEM_WSDD_JAXRPC_ROLE);
90         if (elements.length != 0) {
91             ArrayList JavaDoc roleList = new ArrayList JavaDoc();
92             for (int i = 0; i < elements.length; i++) {
93                 String JavaDoc role = elements[i].getAttribute( ATTR_SOAPACTORNAME);
94                 roleList.add(role);
95             }
96             _roles =new String JavaDoc[roleList.size()];
97             _roles = (String JavaDoc[]) roleList.toArray(_roles);
98             _hiChainFactory.setRoles(_roles);
99         }
100         
101     }
102
103     public HandlerInfoChainFactory getHandlerChainFactory() {
104         return _hiChainFactory;
105     }
106
107     public void setHandlerChainFactory(HandlerInfoChainFactory handlerInfoChainFactory) {
108         _hiChainFactory = handlerInfoChainFactory;
109     }
110
111     protected QName JavaDoc getElementName() {
112         return WSDDConstants.QNAME_JAXRPC_HANDLERINFOCHAIN;
113     }
114     
115     /**
116      * Write this element out to a SerializationContext
117      */

118     public void writeToContext(SerializationContext context)
119             throws IOException JavaDoc {
120             context.startElement(QNAME_JAXRPC_HANDLERINFOCHAIN,null);
121             
122             List JavaDoc his = _hiList;
123             Iterator JavaDoc iter = his.iterator();
124             while (iter.hasNext()) {
125                 WSDDJAXRPCHandlerInfo hi = (WSDDJAXRPCHandlerInfo) iter.next();
126                 hi.writeToContext(context);
127             }
128             
129             if (_roles != null) {
130                 for (int i=0; i < _roles.length ; i++) {
131                     AttributesImpl JavaDoc attrs1 = new AttributesImpl JavaDoc();
132                     attrs1.addAttribute("", ATTR_SOAPACTORNAME, ATTR_SOAPACTORNAME,
133                                "CDATA", _roles[i]);
134                     context.startElement(QNAME_JAXRPC_ROLE,attrs1);
135                     context.endElement();
136                 }
137             }
138             
139             context.endElement();
140     }
141     
142     public ArrayList JavaDoc getHandlerInfoList() {
143         return _hiList;
144     }
145     
146     public void setHandlerInfoList(ArrayList JavaDoc hiList) {
147         _hiList = hiList;
148     }
149     
150     public String JavaDoc[] getRoles() {
151         return _roles;
152     }
153     
154     public void setRoles(String JavaDoc[] roles) {
155         _roles = roles;
156     }
157 }
158
Popular Tags