1 16 17 package org.apache.axis.configuration; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.InputStream ; 22 import java.io.FileFilter ; 23 import java.io.IOException ; 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import javax.xml.namespace.QName ; 29 30 import org.apache.axis.AxisEngine; 31 import org.apache.axis.ConfigurationException; 32 import org.apache.axis.Handler; 33 import org.apache.axis.WSDDEngineConfiguration; 34 import org.apache.axis.deployment.wsdd.WSDDDeployment; 35 import org.apache.axis.deployment.wsdd.WSDDDocument; 36 import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration; 37 import org.apache.axis.encoding.TypeMappingRegistry; 38 import org.apache.axis.handlers.soap.SOAPService; 39 import org.apache.axis.utils.Messages; 40 import org.apache.axis.utils.XMLUtils; 41 42 import org.apache.commons.logging.LogFactory; 43 import org.apache.commons.logging.Log; 44 45 import org.w3c.dom.Document ; 46 47 public class DirProvider implements WSDDEngineConfiguration { 48 49 protected static Log log = 50 LogFactory.getLog(DirProvider.class.getName()); 51 52 private WSDDDeployment deployment = null; 53 private String configFile; 54 private File dir; 55 56 private static final String SERVER_CONFIG_FILE = 57 "server-config.wsdd"; 58 59 public DirProvider(String basepath) 60 throws ConfigurationException { 61 this(basepath, SERVER_CONFIG_FILE); 62 } 63 64 public DirProvider(String basepath, String configFile) 65 throws ConfigurationException { 66 File dir = new File (basepath); 67 68 72 if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) { 73 throw new ConfigurationException(Messages.getMessage 74 ("invalidConfigFilePath", 75 basepath)); 76 } 77 78 this.dir = dir; 79 this.configFile = configFile; 80 } 81 82 public WSDDDeployment getDeployment() { 83 return this.deployment; 84 } 85 86 private static class DirFilter implements FileFilter { 87 public boolean accept(File path) { 88 return path.isDirectory(); 89 } 90 } 91 92 public void configureEngine(AxisEngine engine) 93 throws ConfigurationException { 94 this.deployment = new WSDDDeployment(); 95 WSDDGlobalConfiguration config = new WSDDGlobalConfiguration(); 96 config.setOptionsHashtable(new Hashtable ()); 97 this.deployment.setGlobalConfiguration(config); 98 File [] dirs = this.dir.listFiles(new DirFilter()); 99 for (int i = 0; i < dirs.length; i++) { 100 processWSDD(dirs[i]); 101 } 102 this.deployment.configureEngine(engine); 103 engine.refreshGlobalOptions(); 104 } 105 106 private void processWSDD(File dir) 107 throws ConfigurationException { 108 File file = new File (dir, this.configFile); 109 if (!file.exists()) { 110 return; 111 } 112 log.debug("Loading service configuration from file: " + file); 113 InputStream in = null; 114 try { 115 in = new FileInputStream (file); 116 WSDDDocument doc = new WSDDDocument(XMLUtils.newDocument(in)); 117 doc.deploy(this.deployment); 118 } catch (Exception e) { 119 throw new ConfigurationException(e); 120 } finally { 121 if (in != null) { 122 try { 123 in.close(); 124 } catch (IOException e) {} 125 } 126 } 127 } 128 129 134 public void writeEngineConfig(AxisEngine engine) 135 throws ConfigurationException { 136 } 138 139 145 public Handler getHandler(QName qname) throws ConfigurationException { 146 return this.deployment.getHandler(qname); 147 } 148 149 155 public SOAPService getService(QName qname) throws ConfigurationException { 156 SOAPService service = this.deployment.getService(qname); 157 if (service == null) { 158 throw new ConfigurationException(Messages.getMessage("noService10", 159 qname.toString())); 160 } 161 return service; 162 } 163 164 170 public SOAPService getServiceByNamespaceURI(String namespace) 171 throws ConfigurationException { 172 return this.deployment.getServiceByNamespaceURI(namespace); 173 } 174 175 181 public Handler getTransport(QName qname) throws ConfigurationException { 182 return this.deployment.getTransport(qname); 183 } 184 185 public TypeMappingRegistry getTypeMappingRegistry() 186 throws ConfigurationException { 187 return this.deployment.getTypeMappingRegistry(); 188 } 189 190 193 public Handler getGlobalRequest() throws ConfigurationException { 194 return this.deployment.getGlobalRequest(); 195 } 196 197 200 public Handler getGlobalResponse() throws ConfigurationException { 201 return this.deployment.getGlobalResponse(); 202 } 203 204 207 public Hashtable getGlobalOptions() throws ConfigurationException { 208 WSDDGlobalConfiguration globalConfig 209 = this.deployment.getGlobalConfiguration(); 210 211 if (globalConfig != null) 212 return globalConfig.getParametersTable(); 213 214 return null; 215 } 216 217 220 public Iterator getDeployedServices() throws ConfigurationException { 221 return this.deployment.getDeployedServices(); 222 } 223 224 230 public List getRoles() { 231 return this.deployment.getRoles(); 232 } 233 } 234 | Popular Tags |