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 ; 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 24 30 public class ConfigurationContextFactory { 31 32 public ConfigurationContext buildConfigurationContext(String 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 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 73 74 private void initModules(ConfigurationContext context) 75 throws DeploymentException { 76 try { 77 HashMap modules = 78 ((AxisConfigurationImpl) context.getAxisConfiguration()) 79 .getModules(); 80 Collection col = modules.values(); 81 for (Iterator 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 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 qName = (QName ) 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 HashMap transportIns = axisConf.getTransportsIn(); 122 Iterator 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 HashMap 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 |