KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > engine > AxisConfigurationImpl


1 /*
2 * Copyright 2004,2005 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.axis2.engine;
17
18 import org.apache.axis2.deployment.DeploymentEngine;
19 import org.apache.axis2.deployment.repository.util.ArchiveReader;
20 import org.apache.axis2.description.*;
21 import org.apache.axis2.phaseresolver.PhaseMetadata;
22 import org.apache.axis2.phaseresolver.PhaseResolver;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import java.io.File JavaDoc;
26 import java.util.*;
27
28 /**
29  * Class EngineRegistryImpl
30  */

31 public class AxisConfigurationImpl implements AxisConfiguration {
32     /**
33      * To store Erroness services
34      */

35     private Hashtable errornesServices;
36
37     private Hashtable errornesModules;
38
39     /**
40      * Field modules
41      */

42     private final HashMap modules = new HashMap();
43
44     /**
45      * Field services
46      */

47     private final HashMap services = new HashMap();
48
49
50
51     private final HashMap transportsIn = new HashMap();
52
53     private final HashMap transportsOut = new HashMap();
54
55     /**
56      * Field phases
57      */

58     private ArrayList inPhases;
59     private ArrayList outPhases;
60     private ArrayList inFaultPhases;
61     private ArrayList outFaultPhases;
62
63     private ArrayList inPhasesUptoAndIncludingPostDispatch;
64
65
66
67     /////////////////////// From AxisGlobal /////////////////////////////////////
68
/**
69      * Field paramInclude
70      */

71     protected final ParameterInclude paramInclude;
72
73     /**
74      * Field modules
75      */

76     protected final List engagedModules;
77
78     protected HashMap messagRecievers;
79     /////////////////////// From AxisGlobal /////////////////////////////////////
80
/**
81      * Constructor EngineRegistryImpl
82      */

83     public AxisConfigurationImpl() {
84         paramInclude = new ParameterIncludeImpl();
85         engagedModules = new ArrayList();
86         messagRecievers = new HashMap();
87
88         inPhases = new ArrayList();
89         outPhases = new ArrayList();
90         inFaultPhases = new ArrayList();
91         outFaultPhases = new ArrayList();
92         errornesServices = new Hashtable();
93         errornesModules = new Hashtable();
94
95         inPhasesUptoAndIncludingPostDispatch = new ArrayList();
96         inPhasesUptoAndIncludingPostDispatch.add(new Phase(PhaseMetadata.PHASE_TRANSPORTIN));
97         inPhasesUptoAndIncludingPostDispatch.add(new Phase(PhaseMetadata.PHASE_PRE_DISPATCH));
98         
99         Phase dispatch = new Phase(PhaseMetadata.PHASE_DISPATCH);
100         dispatch.addHandler(new AddressingBasedDispatcher(), 0);
101         dispatch.addHandler(new RequestURIBasedDispatcher(), 1);
102         dispatch.addHandler(new SOAPActionBasedDispatcher(), 2);
103         dispatch.addHandler(new SOAPMessageBodyBasedDispatcher(),3);
104         inPhasesUptoAndIncludingPostDispatch.add(dispatch);
105         
106         Phase postDispatch = new Phase(PhaseMetadata.PHASE_POST_DISPATCH);
107         postDispatch.addHandler(new DispatchPostConditionsEvaluator());
108         inPhasesUptoAndIncludingPostDispatch.add(postDispatch);
109     }
110
111     /**
112      * Method getServices
113      *
114      * @return
115      */

116     public HashMap getServices() {
117         return services;
118     }
119
120     public Hashtable getFaulytServices() {
121         return errornesServices;
122     }
123
124     public Hashtable getFaulytModules() {
125         return errornesModules;
126     }
127
128     /**
129      * Method addMdoule
130      *
131      * @param module
132      * @throws AxisFault
133      */

134     public synchronized void addMdoule(ModuleDescription module) throws AxisFault {
135         modules.put(module.getName(), module);
136     }
137
138     /**
139      * Method addService
140      *
141      * @param service
142      * @throws AxisFault
143      */

144     public synchronized void addService(ServiceDescription service) throws AxisFault {
145         services.put(service.getName(), service);
146         PhaseResolver handlerResolver = new PhaseResolver(this,service);
147         handlerResolver.buildchains();
148     }
149
150     /**
151      * Method getModule
152      *
153      * @param name
154      * @return
155      * @throws AxisFault
156      */

157     public ModuleDescription getModule(QName JavaDoc name) throws AxisFault {
158         return (ModuleDescription) modules.get(name);
159     }
160
161     /**
162      * @return
163      */

164     public HashMap getModules() {
165         return modules;
166     }
167
168
169     /**
170      * Method getService
171      *
172      * @param name
173      * @return
174      * @throws AxisFault
175      */

176     public ServiceDescription getService(QName JavaDoc name) throws AxisFault {
177         return (ServiceDescription) services.get(name);
178     }
179
180     /**
181      * Method removeService
182      *
183      * @param name
184      * @throws AxisFault
185      */

186     public synchronized void removeService(QName JavaDoc name) throws AxisFault {
187         services.remove(name);
188     }
189
190
191     public TransportInDescription getTransportIn(QName JavaDoc name) throws AxisFault {
192         return (TransportInDescription) transportsIn.get(name);
193     }
194
195     /**
196      * Method addTransport
197      *
198      * @param transport
199      * @throws AxisFault
200      */

201     public synchronized void addTransportIn(TransportInDescription transport)
202             throws AxisFault {
203         transportsIn.put(transport.getName(), transport);
204     }
205
206     public TransportOutDescription getTransportOut(QName JavaDoc name) throws AxisFault {
207         return (TransportOutDescription) transportsOut.get(name);
208     }
209
210     /**
211      * Method addTransport
212      *
213      * @param transport
214      * @throws AxisFault
215      */

216     public synchronized void addTransportOut(TransportOutDescription transport)
217             throws AxisFault {
218         transportsOut.put(transport.getName(), transport);
219     }
220
221     public HashMap getTransportsIn() {
222         return transportsIn;
223     }
224
225     public HashMap getTransportsOut() {
226         return transportsOut;
227     }
228
229
230     public void setInPhases(ArrayList inPhases) {
231         this.inPhases = inPhases;
232     }
233
234     public void setOutPhases(ArrayList outPhases) {
235         this.outPhases = outPhases;
236     }
237
238
239     public ArrayList getInPhasesUptoAndIncludingPostDispatch() {
240         return inPhasesUptoAndIncludingPostDispatch;
241     }
242
243     public ArrayList getOutFlow() {
244         return outPhases;
245     }
246
247
248     /**
249      * @return
250      */

251     public ArrayList getInFaultFlow() {
252         return inFaultPhases;
253     }
254
255     /**
256      * @return
257      */

258     public ArrayList getOutFaultFlow() {
259         return outFaultPhases;
260     }
261
262     /**
263      * @param list
264      */

265     public void setInFaultPhases(ArrayList list) {
266         inFaultPhases = list;
267     }
268
269     /**
270      * @param list
271      */

272     public void setOutFaultPhases(ArrayList list) {
273         outFaultPhases = list;
274     }
275
276     ////////////////////////// Form Axis Global
277

278     public void addMessageReceiver(String JavaDoc key, MessageReceiver messageReceiver) {
279         messagRecievers.put(key, messageReceiver);
280     }
281
282     public MessageReceiver getMessageReceiver(String JavaDoc key) {
283         return (MessageReceiver) messagRecievers.get(key);
284     }
285
286     /**
287      * Method getParameter
288      *
289      * @param name
290      * @return
291      */

292     public Parameter getParameter(String JavaDoc name) {
293         return paramInclude.getParameter(name);
294     }
295
296     /**
297      * Method addParameter
298      *
299      * @param param
300      */

301     public void addParameter(Parameter param) {
302         paramInclude.addParameter(param);
303     }
304     /**
305      * Method getEngadgedModules
306      *
307      * @return
308      */

309     public Collection getEngadgedModules() {
310         return engagedModules;
311     }
312
313     public void engageModule(QName JavaDoc moduleref) throws AxisFault {
314         ModuleDescription module = getModule(moduleref);
315         boolean isNewmodule = false;
316         if(module == null ) {
317             File JavaDoc file = new ArchiveReader().creatModuleArchivefromResource(moduleref.getLocalPart());
318             module = new DeploymentEngine().buildModule(file);
319             isNewmodule = true;
320         }
321         if (module != null) {
322             for (Iterator iterator = engagedModules.iterator(); iterator.hasNext();) {
323                 QName JavaDoc qName = (QName JavaDoc) iterator.next();
324                 if(moduleref.equals(qName)){
325                     throw new AxisFault(moduleref.getLocalPart()+ " module has alredy engaged globally" +
326                             " operation terminated !!!");
327                 }
328             }
329             new PhaseResolver(this).engageModuleGlobally(module);
330         } else {
331              throw new AxisFault(this + " Refer to invalid module "
332                      + moduleref.getLocalPart() + " has not bean deployed yet !");
333         }
334         engagedModules.add(moduleref);
335         if(isNewmodule){
336             addMdoule(module);
337         }
338     }
339     
340     public boolean isEngaged(QName JavaDoc moduleName){
341         return engagedModules.contains(moduleName);
342     }
343
344 }
345
Popular Tags