KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > context > ConfigurationContextFactory


1 package org.apache.axis2.context;
2
3 import org.apache.axis2.deployment.DeploymentEngine;
4 import org.apache.axis2.deployment.DeploymentException;
5 import org.apache.axis2.description.ModuleDescription;
6 import org.apache.axis2.description.ServiceDescription;
7 import org.apache.axis2.description.TransportInDescription;
8 import org.apache.axis2.description.TransportOutDescription;
9 import org.apache.axis2.engine.AxisConfiguration;
10 import org.apache.axis2.engine.AxisConfigurationImpl;
11 import org.apache.axis2.engine.AxisFault;
12 import org.apache.axis2.modules.Module;
13 import org.apache.axis2.phaseresolver.PhaseException;
14 import org.apache.axis2.phaseresolver.PhaseResolver;
15 import org.apache.axis2.transport.TransportListener;
16 import org.apache.axis2.transport.TransportSender;
17
18 import javax.xml.namespace.QName JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 /**
25  * Created by IntelliJ IDEA.
26  * Author : Deepal Jayasinghe
27  * Date: Apr 19, 2005
28  * Time: 10:44:38 AM
29  */

30 public class ConfigurationContextFactory {
31
32     public ConfigurationContext buildConfigurationContext(String JavaDoc RepositaryName)
33         throws DeploymentException {
34         ConfigurationContext configurationContext = null;
35         try {
36             DeploymentEngine deploymentEngine =
37                 new DeploymentEngine(RepositaryName);
38             AxisConfiguration configuration = deploymentEngine.load();
39             PhaseResolver phaseResolver = new PhaseResolver(configuration);
40             configurationContext = new ConfigurationContext(configuration);
41             phaseResolver.buildTranspotsChains();
42             initModules(configurationContext);
43         } catch (AxisFault axisFault) {
44             throw new DeploymentException(axisFault);
45         }
46         return configurationContext;
47     }
48
49     public ConfigurationContext buildClientConfigurationContext(String JavaDoc axis2home)
50         throws DeploymentException {
51         ConfigurationContext engineContext = null;
52         try {
53             AxisConfiguration configuration =
54                 new DeploymentEngine().loadClient(axis2home);
55             PhaseResolver phaseResolver = new PhaseResolver(configuration);
56             engineContext = new ConfigurationContext(configuration);
57             phaseResolver.buildTranspotsChains();
58             initModules(engineContext);
59             initTransports(engineContext);
60         } catch (AxisFault axisFault) {
61             throw new DeploymentException(axisFault);
62         }
63         return engineContext;
64     }
65
66     /**
67      * Is used to initilize the modules , if the module needs to so some recovery process
68      * it can do inside init and this is differnt form module.engage()
69      *
70      * @param context
71      * @throws DeploymentException
72      */

73
74     private void initModules(ConfigurationContext context)
75         throws DeploymentException {
76         try {
77             HashMap JavaDoc modules =
78                 ((AxisConfigurationImpl) context.getAxisConfiguration())
79                     .getModules();
80             Collection JavaDoc col = modules.values();
81             for (Iterator JavaDoc iterator = col.iterator(); iterator.hasNext();) {
82                 ModuleDescription axismodule =
83                     (ModuleDescription) iterator.next();
84                 Module module = axismodule.getModule();
85                 if (module != null) {
86                     module.init(context.getAxisConfiguration());
87                 }
88             }
89         } catch (AxisFault e) {
90             throw new DeploymentException(e);
91         }
92     }
93
94     public static void createChains(
95         ServiceDescription service,
96         AxisConfiguration configurationContextVal,
97         ArrayList JavaDoc modules)
98         throws PhaseException {
99         try {
100             PhaseResolver reolve =
101                 new PhaseResolver(configurationContextVal, service);
102             reolve.buildchains();
103             for (int i = 0; i < modules.size(); i++) {
104                 QName JavaDoc qName = (QName JavaDoc) modules.get(i);
105                 ModuleDescription moduledecs =
106                     configurationContextVal.getModule(qName);
107                 reolve.engageModuleToService(service, moduledecs);
108             }
109         } catch (PhaseException e) {
110             throw new PhaseException(e.getMessage());
111         } catch (AxisFault axisFault) {
112             throw new PhaseException(axisFault);
113         }
114     }
115
116     public void initTransports(ConfigurationContext configContext)
117         throws AxisFault {
118         AxisConfiguration axisConf = configContext.getAxisConfiguration();
119         
120         //Initzialize Transport Ins
121
HashMap JavaDoc transportIns = axisConf.getTransportsIn();
122         Iterator JavaDoc values = transportIns.values().iterator();
123         while (values.hasNext()) {
124             TransportInDescription transportIn =
125                 (TransportInDescription) values.next();
126             TransportListener listener = transportIn.getReciever();
127             if (listener != null) {
128                 listener.init(configContext, transportIn);
129             }
130         }
131         //Initzialize Transport Outs
132
HashMap JavaDoc transportOuts = axisConf.getTransportsOut();
133         values = transportOuts.values().iterator();
134         while (values.hasNext()) {
135             TransportOutDescription transportOut =
136                 (TransportOutDescription) values.next();
137             TransportSender sender = transportOut.getSender();
138             if (sender != null) {
139                 sender.init(configContext, transportOut);
140             }
141         }
142
143     }
144
145 }
146
Popular Tags