KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConfigurationException;
19 import org.apache.axis.encoding.SerializationContext;
20 import org.apache.axis.handlers.soap.SOAPService;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.utils.Messages;
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 import java.util.Iterator JavaDoc;
29 import java.util.Vector JavaDoc;
30
31
32 /**
33  * WSDD deployment element
34  *
35  * @author James Snell
36  */

37 public class WSDDUndeployment
38     extends WSDDElement
39     implements WSDDTypeMappingContainer
40 {
41     private Vector JavaDoc handlers = new Vector JavaDoc();
42     private Vector JavaDoc chains = new Vector JavaDoc();
43     private Vector JavaDoc services = new Vector JavaDoc();
44     private Vector JavaDoc transports = new Vector JavaDoc();
45     private Vector JavaDoc typeMappings = new Vector JavaDoc();
46
47     public void addHandler(QName JavaDoc handler)
48     {
49         handlers.add(handler);
50     }
51
52     public void addChain(QName JavaDoc chain)
53     {
54         chains.add(chain);
55     }
56
57     public void addTransport(QName JavaDoc transport)
58     {
59         transports.add(transport);
60     }
61     
62     public void addService(QName JavaDoc service)
63     {
64         services.add(service);
65     }
66     
67     public void deployTypeMapping(WSDDTypeMapping typeMapping)
68         throws WSDDException
69     {
70         typeMappings.add(typeMapping);
71     }
72
73     /**
74      * Default constructor
75      */

76     public WSDDUndeployment()
77     {
78     }
79
80     private QName JavaDoc getQName(Element JavaDoc el) throws WSDDException
81     {
82         String JavaDoc attr = el.getAttribute(ATTR_NAME);
83         if (attr == null || "".equals(attr))
84             throw new WSDDException(Messages.getMessage("badNameAttr00"));
85         return new QName JavaDoc("", attr);
86     }
87
88     /**
89      * Constructor - build an undeployment from a DOM Element.
90      *
91      * @param e the DOM Element to initialize from
92      * @throws WSDDException if there is a problem
93      */

94     public WSDDUndeployment(Element JavaDoc e)
95         throws WSDDException
96     {
97         super(e);
98         
99         Element JavaDoc [] elements = getChildElements(e, ELEM_WSDD_HANDLER);
100         int i;
101
102         for (i = 0; i < elements.length; i++) {
103             addHandler(getQName(elements[i]));
104         }
105
106         elements = getChildElements(e, ELEM_WSDD_CHAIN);
107         for (i = 0; i < elements.length; i++) {
108             addChain(getQName(elements[i]));
109         }
110         
111         elements = getChildElements(e, ELEM_WSDD_TRANSPORT);
112         for (i = 0; i < elements.length; i++) {
113             addTransport(getQName(elements[i]));
114         }
115         
116         elements = getChildElements(e, ELEM_WSDD_SERVICE);
117         for (i = 0; i < elements.length; i++) {
118             addService(getQName(elements[i]));
119         }
120
121         /*
122         // How to deal with undeploying mappings?
123
124         elements = getChildElements(e, ELEM_WSDD_TYPEMAPPING);
125         for (i = 0; i < elements.length; i++) {
126             WSDDTypeMapping mapping = new WSDDTypeMapping(elements[i]);
127             addTypeMapping(mapping);
128         }
129
130         elements = getChildElements(e, ELEM_WSDD_BEANMAPPING);
131         for (i = 0; i < elements.length; i++) {
132             WSDDBeanMapping mapping = new WSDDBeanMapping(elements[i]);
133             addTypeMapping(mapping);
134         }
135         */

136     }
137
138     protected QName JavaDoc getElementName()
139     {
140         return QNAME_UNDEPLOY;
141     }
142
143     public void undeployFromRegistry(WSDDDeployment registry)
144         throws ConfigurationException
145     {
146         QName JavaDoc qname;
147         for (int n = 0; n < handlers.size(); n++) {
148             qname = (QName JavaDoc)handlers.get(n);
149             registry.undeployHandler(qname);
150         }
151
152         for (int n = 0; n < chains.size(); n++) {
153             qname = (QName JavaDoc)chains.get(n);
154             registry.undeployHandler(qname);
155         }
156
157         for (int n = 0; n < transports.size(); n++) {
158             qname = (QName JavaDoc)transports.get(n);
159             registry.undeployTransport(qname);
160         }
161
162         for (int n = 0; n < services.size(); n++) {
163             qname = (QName JavaDoc)services.get(n);
164  
165             try {
166                 String JavaDoc sname = qname.getLocalPart();
167                 MessageContext messageContext = MessageContext.getCurrentContext();
168                 if (messageContext != null) {
169                     SOAPService service = messageContext.getAxisEngine()
170                             .getService(sname);
171                     if ( service != null ) service.clearSessions();
172                 }
173             } catch(Exception JavaDoc exp) {
174                 throw new ConfigurationException(exp);
175             }
176             registry.undeployService(qname);
177         }
178     }
179
180     private void writeElement(SerializationContext context,
181                               QName JavaDoc elementQName,
182                               QName JavaDoc qname)
183         throws IOException JavaDoc
184     {
185         AttributesImpl JavaDoc attrs = new org.xml.sax.helpers.AttributesImpl JavaDoc();
186         attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA",
187                            context.qName2String(qname));
188          
189         context.startElement(elementQName, attrs);
190         context.endElement();
191     }
192
193     public void writeToContext(SerializationContext context)
194         throws IOException JavaDoc
195     {
196         context.registerPrefixForURI(NS_PREFIX_WSDD, URI_WSDD);
197         context.startElement(WSDDConstants.QNAME_UNDEPLOY, null);
198         
199         Iterator JavaDoc i = handlers.iterator();
200         QName JavaDoc qname;
201         while (i.hasNext()) {
202             qname = (QName JavaDoc)i.next();
203             writeElement(context, QNAME_HANDLER, qname);
204         }
205         
206         i = chains.iterator();
207         while (i.hasNext()) {
208             qname = (QName JavaDoc)i.next();
209             writeElement(context, QNAME_CHAIN, qname);
210         }
211
212         i = services.iterator();
213         while (i.hasNext()) {
214             qname = (QName JavaDoc)i.next();
215             writeElement(context, QNAME_SERVICE, qname);
216         }
217         
218         i = transports.iterator();
219         while (i.hasNext()) {
220             qname = (QName JavaDoc)i.next();
221             writeElement(context, QNAME_TRANSPORT, qname);
222         }
223         
224         i = typeMappings.iterator();
225         while (i.hasNext()) {
226             WSDDTypeMapping mapping = (WSDDTypeMapping)i.next();
227             mapping.writeToContext(context);
228         }
229
230         context.endElement();
231     }
232     
233     /**
234      *
235      * @return XXX
236      */

237     public WSDDTypeMapping[] getTypeMappings()
238     {
239         WSDDTypeMapping[] t = new WSDDTypeMapping[typeMappings.size()];
240         typeMappings.toArray(t);
241         return t;
242     }
243
244 }
245
Popular Tags