KickJava   Java API By Example, From Geeks To Geeks.

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


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.Chain;
58 import org.jboss.axis.ConfigurationException;
59 import org.jboss.axis.EngineConfiguration;
60 import org.jboss.axis.Handler;
61 import org.jboss.axis.encoding.SerializationContext;
62 import org.w3c.dom.Element JavaDoc;
63 import org.xml.sax.helpers.AttributesImpl JavaDoc;
64
65 import javax.xml.namespace.QName JavaDoc;
66 import java.io.IOException JavaDoc;
67 import java.util.Vector JavaDoc;
68
69
70 /**
71  * WSDD chain element
72  */

73 public class WSDDChain
74         extends WSDDHandler
75 {
76    private Vector JavaDoc handlers = new Vector JavaDoc();
77
78    /**
79     * Default constructor
80     */

81    public WSDDChain()
82    {
83    }
84
85    /**
86     * @param e (Element) XXX
87     * @throws WSDDException XXX
88     */

89    public WSDDChain(Element JavaDoc e)
90            throws WSDDException
91    {
92       super(e);
93
94       // If we're simply a reference to an existing chain, return.
95
// !!! should check to make sure it's a valid chain?
96
if (type != null)
97          return;
98
99       Element JavaDoc[] elements = getChildElements(e, ELEM_WSDD_HANDLER);
100       if (elements.length != 0)
101       {
102          for (int i = 0; i < elements.length; i++)
103          {
104             WSDDHandler handler = new WSDDHandler(elements[i]);
105             addHandler(handler);
106          }
107       }
108
109       elements = getChildElements(e, ELEM_WSDD_CHAIN);
110       if (elements.length != 0)
111       {
112          for (int i = 0; i < elements.length; i++)
113          {
114             WSDDChain chain = new WSDDChain(elements[i]);
115             addHandler(chain);
116          }
117       }
118
119    }
120
121    protected QName JavaDoc getElementName()
122    {
123       return WSDDConstants.QNAME_CHAIN;
124    }
125
126    /**
127     * Add a Handler to the chain (at the end)
128     */

129    public void addHandler(WSDDHandler handler)
130    {
131       handlers.add(handler);
132    }
133
134    /**
135     * Obtain our handler list
136     *
137     * @return a Vector containing our Handlers
138     */

139    public Vector JavaDoc getHandlers()
140    {
141       return handlers;
142    }
143
144    /**
145     * Remove a Handler from the chain
146     */

147    public void removeHandler(WSDDHandler victim)
148    {
149       handlers.remove(victim);
150    }
151
152    /**
153     * Creates a new instance of this Chain
154     *
155     * @param registry XXX
156     * @return XXX
157     * @throws ConfigurationException XXX
158     */

159    public Handler makeNewInstance(EngineConfiguration registry)
160            throws ConfigurationException
161    {
162       Chain c = new org.jboss.axis.SimpleChain();
163
164       for (int n = 0; n < handlers.size(); n++)
165       {
166          WSDDHandler handler = (WSDDHandler)handlers.get(n);
167          Handler h = handler.getInstance(registry);
168          if (h != null)
169             c.addHandler(h);
170          else
171             throw new ConfigurationException("Can't find handler name:'" +
172                     handler.getQName() + "' type:'" +
173                     handler.getType() +
174                     "' in the registry");
175       }
176
177       return c;
178    }
179
180    /**
181     * Write this element out to a SerializationContext
182     */

183    public void writeToContext(SerializationContext context)
184            throws IOException JavaDoc
185    {
186       AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
187       QName JavaDoc name = getQName();
188       if (name != null)
189       {
190          attrs.addAttribute("", ATTR_NAME, ATTR_NAME,
191                  "CDATA", context.qName2String(name));
192       }
193       if (getType() != null)
194       {
195          attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE,
196                  "CDATA", context.qName2String(getType()));
197       }
198
199       context.startElement(getElementName(), attrs);
200       for (int n = 0; n < handlers.size(); n++)
201       {
202          WSDDHandler handler = (WSDDHandler)handlers.get(n);
203          handler.writeToContext(context);
204       }
205       context.endElement();
206    }
207
208    public void deployToRegistry(WSDDDeployment registry)
209    {
210       if (getQName() != null)
211          registry.addHandler(this);
212
213       for (int n = 0; n < handlers.size(); n++)
214       {
215          WSDDHandler handler = (WSDDHandler)handlers.get(n);
216          if (handler.getQName() != null)
217             handler.deployToRegistry(registry);
218       }
219    }
220 }
221
Popular Tags