KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import javax.xml.namespace.QName JavaDoc;
22
23 import org.apache.axis.Chain;
24 import org.apache.axis.ConfigurationException;
25 import org.apache.axis.EngineConfiguration;
26 import org.apache.axis.Handler;
27 import org.apache.axis.encoding.SerializationContext;
28 import org.w3c.dom.Element JavaDoc;
29 import org.xml.sax.helpers.AttributesImpl JavaDoc;
30
31
32 /**
33  * WSDD chain element
34  *
35  */

36 public class WSDDChain
37     extends WSDDHandler
38 {
39     private Vector JavaDoc handlers = new Vector JavaDoc();
40     
41     /**
42      * Default constructor
43      */

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

53     public WSDDChain(Element JavaDoc e)
54         throws WSDDException
55     {
56         super(e);
57         
58         // If we're simply a reference to an existing chain, return.
59
// !!! should check to make sure it's a valid chain?
60
if (type != null)
61             return;
62         
63         Element JavaDoc [] elements = getChildElements(e, ELEM_WSDD_HANDLER);
64         if (elements.length != 0) {
65             for (int i = 0; i < elements.length; i++) {
66                 WSDDHandler handler = new WSDDHandler(elements[i]);
67                 addHandler(handler);
68             }
69         }
70         
71         elements = getChildElements(e, ELEM_WSDD_CHAIN);
72         if (elements.length != 0) {
73             for (int i = 0; i < elements.length; i++) {
74                 WSDDChain chain = new WSDDChain(elements[i]);
75                 addHandler(chain);
76             }
77         }
78
79     }
80     
81     protected QName JavaDoc getElementName()
82     {
83         return WSDDConstants.QNAME_CHAIN;
84     }
85     
86     /**
87      * Add a Handler to the chain (at the end)
88      */

89     public void addHandler(WSDDHandler handler)
90     {
91         handlers.add(handler);
92     }
93
94     /**
95      * Obtain our handler list
96      *
97      * @return a Vector containing our Handlers
98      */

99     public Vector JavaDoc getHandlers()
100     {
101         return handlers;
102     }
103
104     /**
105      * Remove a Handler from the chain
106      */

107     public void removeHandler(WSDDHandler victim)
108     {
109         handlers.remove(victim);
110     }
111
112     /**
113      * Creates a new instance of this Chain
114      * @param registry XXX
115      * @return XXX
116      * @throws ConfigurationException XXX
117      */

118     public Handler makeNewInstance(EngineConfiguration registry)
119         throws ConfigurationException
120     {
121         Chain c = new org.apache.axis.SimpleChain();
122         
123         for (int n = 0; n < handlers.size(); n++) {
124             WSDDHandler handler = (WSDDHandler)handlers.get(n);
125             Handler h = handler.getInstance(registry);
126             if ( h != null )
127               c.addHandler(h);
128             else
129               throw new ConfigurationException("Can't find handler name:'" +
130                                                handler.getQName() + "' type:'"+
131                                                handler.getType() +
132                                                "' in the registry");
133         }
134         
135         return c;
136     }
137     
138     /**
139      * Write this element out to a SerializationContext
140      */

141     public void writeToContext(SerializationContext context)
142         throws IOException JavaDoc
143     {
144         AttributesImpl JavaDoc attrs = new AttributesImpl JavaDoc();
145         QName JavaDoc name = getQName();
146         if (name != null) {
147             attrs.addAttribute("", ATTR_NAME, ATTR_NAME,
148                                "CDATA", context.qName2String(name));
149         }
150         if (getType() != null) {
151             attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE,
152                            "CDATA", context.qName2String(getType()));
153         }
154         
155         context.startElement(getElementName(), attrs);
156         for (int n = 0; n < handlers.size(); n++) {
157             WSDDHandler handler = (WSDDHandler)handlers.get(n);
158             handler.writeToContext(context);
159         }
160         context.endElement();
161     }
162
163     public void deployToRegistry(WSDDDeployment registry)
164     {
165         if (getQName() != null)
166             registry.addHandler(this);
167         
168         for (int n = 0; n < handlers.size(); n++) {
169             WSDDHandler handler = (WSDDHandler)handlers.get(n);
170             if (handler.getQName() != null)
171                 handler.deployToRegistry(registry);
172         }
173     }
174 }
175
Popular Tags