KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConfigurationException;
58 import org.jboss.axis.encoding.SerializationContext;
59 import org.jboss.axis.utils.Messages;
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.Iterator JavaDoc;
66 import java.util.Vector JavaDoc;
67
68
69 /**
70  * WSDD deployment element
71  *
72  * @author James Snell
73  */

74 public class WSDDUndeployment
75         extends WSDDElement
76         implements WSDDTypeMappingContainer
77 {
78    private Vector JavaDoc handlers = new Vector JavaDoc();
79    private Vector JavaDoc chains = new Vector JavaDoc();
80    private Vector JavaDoc services = new Vector JavaDoc();
81    private Vector JavaDoc transports = new Vector JavaDoc();
82    private Vector JavaDoc typeMappings = new Vector JavaDoc();
83
84    public void addHandler(QName JavaDoc handler)
85    {
86       handlers.add(handler);
87    }
88
89    public void addChain(QName JavaDoc chain)
90    {
91       chains.add(chain);
92    }
93
94    public void addTransport(QName JavaDoc transport)
95    {
96       transports.add(transport);
97    }
98
99    public void addService(QName JavaDoc service)
100    {
101       services.add(service);
102    }
103
104    public void deployTypeMapping(WSDDTypeMapping typeMapping)
105            throws WSDDException
106    {
107       typeMappings.add(typeMapping);
108    }
109
110    /**
111     * Default constructor
112     */

113    public WSDDUndeployment()
114    {
115    }
116
117    private QName JavaDoc getQName(Element JavaDoc el) throws WSDDException
118    {
119       String JavaDoc attr = el.getAttribute(ATTR_NAME);
120       if (attr == null || "".equals(attr))
121          throw new WSDDException(Messages.getMessage("badNameAttr00"));
122       return new QName JavaDoc("", attr);
123    }
124
125    /**
126     * Constructor - build an undeployment from a DOM Element.
127     *
128     * @param e the DOM Element to initialize from
129     * @throws WSDDException if there is a problem
130     */

131    public WSDDUndeployment(Element JavaDoc e)
132            throws WSDDException
133    {
134       super(e);
135
136       Element JavaDoc[] elements = getChildElements(e, ELEM_WSDD_HANDLER);
137       int i;
138
139       for (i = 0; i < elements.length; i++)
140       {
141          addHandler(getQName(elements[i]));
142       }
143
144       elements = getChildElements(e, ELEM_WSDD_CHAIN);
145       for (i = 0; i < elements.length; i++)
146       {
147          addChain(getQName(elements[i]));
148       }
149
150       elements = getChildElements(e, ELEM_WSDD_TRANSPORT);
151       for (i = 0; i < elements.length; i++)
152       {
153          addTransport(getQName(elements[i]));
154       }
155
156       elements = getChildElements(e, ELEM_WSDD_SERVICE);
157       for (i = 0; i < elements.length; i++)
158       {
159          addService(getQName(elements[i]));
160       }
161
162       /*
163       // How to deal with undeploying mappings?
164
165       elements = getChildElements(e, ELEM_WSDD_TYPEMAPPING);
166       for (i = 0; i < elements.length; i++) {
167           WSDDTypeMapping mapping = new WSDDTypeMapping(elements[i]);
168           addTypeMapping(mapping);
169       }
170
171       elements = getChildElements(e, ELEM_WSDD_BEANMAPPING);
172       for (i = 0; i < elements.length; i++) {
173           WSDDBeanMapping mapping = new WSDDBeanMapping(elements[i]);
174           addTypeMapping(mapping);
175       }
176       */

177    }
178
179    protected QName JavaDoc getElementName()
180    {
181       return QNAME_UNDEPLOY;
182    }
183
184    public void undeployFromRegistry(WSDDDeployment registry)
185            throws ConfigurationException
186    {
187       QName JavaDoc qname;
188       for (int n = 0; n < handlers.size(); n++)
189       {
190          qname = (QName JavaDoc)handlers.get(n);
191          registry.undeployHandler(qname);
192       }
193
194       for (int n = 0; n < chains.size(); n++)
195       {
196          qname = (QName JavaDoc)chains.get(n);
197          registry.undeployHandler(qname);
198       }
199
200       for (int n = 0; n < transports.size(); n++)
201       {
202          qname = (QName JavaDoc)transports.get(n);
203          registry.undeployTransport(qname);
204       }
205
206       for (int n = 0; n < services.size(); n++)
207       {
208          qname = (QName JavaDoc)services.get(n);
209          registry.undeployService(qname);
210       }
211    }
212
213    private void writeElement(SerializationContext context,
214                              QName JavaDoc elementQName,
215                              QName JavaDoc qname)
216            throws IOException JavaDoc
217    {
218       AttributesImpl JavaDoc attrs = new org.xml.sax.helpers.AttributesImpl JavaDoc();
219       attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA",
220               context.qName2String(qname));
221
222       context.startElement(elementQName, attrs);
223       context.endElement();
224    }
225
226    public void writeToContext(SerializationContext context)
227            throws IOException JavaDoc
228    {
229       context.registerPrefixForURI(NS_PREFIX_WSDD, URI_WSDD);
230       context.startElement(WSDDConstants.QNAME_UNDEPLOY, null);
231
232       Iterator JavaDoc i = handlers.iterator();
233       QName JavaDoc qname;
234       while (i.hasNext())
235       {
236          qname = (QName JavaDoc)i.next();
237          writeElement(context, QNAME_HANDLER, qname);
238       }
239
240       i = chains.iterator();
241       while (i.hasNext())
242       {
243          qname = (QName JavaDoc)i.next();
244          writeElement(context, QNAME_CHAIN, qname);
245       }
246
247       i = services.iterator();
248       while (i.hasNext())
249       {
250          qname = (QName JavaDoc)i.next();
251          writeElement(context, QNAME_SERVICE, qname);
252       }
253
254       i = transports.iterator();
255       while (i.hasNext())
256       {
257          qname = (QName JavaDoc)i.next();
258          writeElement(context, QNAME_TRANSPORT, qname);
259       }
260
261       i = typeMappings.iterator();
262       while (i.hasNext())
263       {
264          WSDDTypeMapping mapping = (WSDDTypeMapping)i.next();
265          mapping.writeToContext(context);
266       }
267
268       context.endElement();
269    }
270
271    /**
272     * @return XXX
273     */

274    public WSDDTypeMapping[] getTypeMappings()
275    {
276       WSDDTypeMapping[] t = new WSDDTypeMapping[typeMappings.size()];
277       typeMappings.toArray(t);
278       return t;
279    }
280
281 }
282
Popular Tags