KickJava   Java API By Example, From Geeks To Geeks.

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


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.EngineConfiguration;
20 import org.apache.axis.Handler;
21 import org.apache.axis.encoding.SerializationContext;
22 import org.apache.axis.utils.ClassUtils;
23 import org.apache.axis.utils.Messages;
24 import org.apache.axis.utils.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 import javax.xml.namespace.QName JavaDoc;
28 import java.io.IOException JavaDoc;
29
30
31 /**
32  *
33  */

34 public abstract class WSDDTargetedChain
35     extends WSDDDeployableItem
36 {
37     private WSDDRequestFlow requestFlow;
38     private WSDDResponseFlow responseFlow;
39     private QName JavaDoc pivotQName;
40     
41     protected WSDDTargetedChain()
42     {
43     }
44
45     /**
46      *
47      * @param e (Element) XXX
48      * @throws WSDDException XXX
49      */

50     protected WSDDTargetedChain(Element JavaDoc e)
51         throws WSDDException
52     {
53         super(e);
54         Element JavaDoc reqEl = getChildElement(e, ELEM_WSDD_REQFLOW);
55         if (reqEl != null && reqEl.getElementsByTagName("*").getLength()>0) {
56             requestFlow = new WSDDRequestFlow(reqEl);
57         }
58         Element JavaDoc respEl = getChildElement(e, ELEM_WSDD_RESPFLOW);
59         if (respEl != null && respEl.getElementsByTagName("*").getLength()>0) {
60             responseFlow = new WSDDResponseFlow(respEl);
61         }
62         
63         // !!! pivot? use polymorphic method?
64
String JavaDoc pivotStr = e.getAttribute(ATTR_PIVOT);
65         if (pivotStr != null && !pivotStr.equals(""))
66             pivotQName = XMLUtils.getQNameFromString(pivotStr, e);
67         
68     }
69
70     public WSDDRequestFlow getRequestFlow()
71     {
72         return requestFlow;
73     }
74     
75     public void setRequestFlow(WSDDRequestFlow flow)
76     {
77         requestFlow = flow;
78     }
79
80     public WSDDResponseFlow getResponseFlow()
81     {
82         return responseFlow;
83     }
84     
85     public void setResponseFlow(WSDDResponseFlow flow)
86     {
87         responseFlow = flow;
88     }
89
90     /**
91      *
92      * @return XXX
93      */

94     public WSDDFaultFlow[] getFaultFlows()
95     {
96         return null;
97     }
98
99     /**
100      *
101      * @param name XXX
102      * @return XXX
103      */

104     public WSDDFaultFlow getFaultFlow(QName JavaDoc name)
105     {
106
107         WSDDFaultFlow[] t = getFaultFlows();
108
109         for (int n = 0; n < t.length; n++) {
110             if (t[n].getQName().equals(name)) {
111                 return t[n];
112             }
113         }
114
115         return null;
116     }
117
118     /**
119      *
120      * @param type XXX
121      */

122     public void setType(String JavaDoc type) throws WSDDException
123     {
124         throw new WSDDException(Messages.getMessage(
125                 "noTypeSetting", getElementName().getLocalPart()));
126     }
127     
128     public QName JavaDoc getPivotQName()
129     {
130         return pivotQName;
131     }
132
133     public void setPivotQName(QName JavaDoc pivotQName) {
134         this.pivotQName = pivotQName;
135     }
136
137     /**
138      *
139      * @param pivot XXX
140      * @param registry XXX
141      * @return XXX
142      * @throws ConfigurationException XXX
143      */

144     public Handler makeNewInstance(EngineConfiguration registry)
145         throws ConfigurationException
146     {
147         Handler reqHandler = null;
148
149         WSDDChain req = getRequestFlow();
150         if (req != null)
151             reqHandler = req.getInstance(registry);
152         
153         Handler pivot = null;
154         if (pivotQName != null) {
155             if (URI_WSDD_JAVA.equals(pivotQName.getNamespaceURI())) {
156                 try {
157                     pivot = (Handler)ClassUtils.forName(pivotQName.getLocalPart()).newInstance();
158                 } catch (InstantiationException JavaDoc e) {
159                     throw new ConfigurationException(e);
160                 } catch (IllegalAccessException JavaDoc e) {
161                     throw new ConfigurationException(e);
162                 } catch (ClassNotFoundException JavaDoc e) {
163                     throw new ConfigurationException(e);
164                 }
165             } else {
166                 pivot = registry.getHandler(pivotQName);
167             }
168         }
169         
170         Handler respHandler = null;
171         WSDDChain resp = getResponseFlow();
172         if (resp != null)
173             respHandler = resp.getInstance(registry);
174
175         Handler retVal = new org.apache.axis.SimpleTargetedChain(reqHandler, pivot,
176                                                        respHandler);
177         retVal.setOptions(getParametersTable());
178         return retVal;
179     }
180
181     /**
182      * Write this element out to a SerializationContext
183      */

184     public final void writeFlowsToContext(SerializationContext context)
185             throws IOException JavaDoc {
186         if (requestFlow != null) {
187             requestFlow.writeToContext(context);
188         }
189         if (responseFlow != null) {
190             responseFlow.writeToContext(context);
191         }
192         
193     }
194     
195     public void deployToRegistry(WSDDDeployment registry)
196     {
197         // deploy any named subparts
198
if (requestFlow != null) {
199             requestFlow.deployToRegistry(registry);
200         }
201         
202         if (responseFlow != null) {
203             responseFlow.deployToRegistry(registry);
204         }
205     }
206 }
207
Popular Tags