1 16 17 package org.apache.axis.configuration; 18 19 import java.io.BufferedWriter ; 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileOutputStream ; 23 import java.io.InputStream ; 24 import java.io.OutputStreamWriter ; 25 import java.io.PrintWriter ; 26 import java.io.Writer ; 27 import java.util.Hashtable ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import javax.xml.namespace.QName ; 32 33 import org.apache.axis.AxisEngine; 34 import org.apache.axis.ConfigurationException; 35 import org.apache.axis.Handler; 36 import org.apache.axis.WSDDEngineConfiguration; 37 import org.apache.axis.components.logger.LogFactory; 38 import org.apache.axis.deployment.wsdd.WSDDDeployment; 39 import org.apache.axis.deployment.wsdd.WSDDDocument; 40 import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration; 41 import org.apache.axis.encoding.TypeMappingRegistry; 42 import org.apache.axis.handlers.soap.SOAPService; 43 import org.apache.axis.utils.Admin; 44 import org.apache.axis.utils.ClassUtils; 45 import org.apache.axis.utils.Messages; 46 import org.apache.axis.utils.XMLUtils; 47 import org.apache.commons.logging.Log; 48 import org.w3c.dom.Document ; 49 50 57 public class FileProvider implements WSDDEngineConfiguration { 58 protected static Log log = 59 LogFactory.getLog(FileProvider.class.getName()); 60 61 private WSDDDeployment deployment = null; 62 63 private String filename; 64 private File configFile = null; 65 66 private InputStream myInputStream = null; 67 68 private boolean readOnly = true; 69 70 private boolean searchClasspath = true; 73 74 78 public FileProvider(String filename) { 79 this.filename = filename; 80 configFile = new File (filename); 81 check(); 82 } 83 84 88 public FileProvider(String basepath, String filename) 89 throws ConfigurationException { 90 this.filename = filename; 91 92 File dir = new File (basepath); 93 94 98 if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) { 99 throw new ConfigurationException(Messages.getMessage 100 ("invalidConfigFilePath", 101 basepath)); 102 } 103 104 configFile = new File (basepath, filename); 105 check(); 106 } 107 108 112 private void check() { 113 try { 114 readOnly = configFile.canRead() & !configFile.canWrite(); 115 } catch (SecurityException se){ 116 readOnly = true; 117 } 118 119 123 if (readOnly) { 124 log.info(Messages.getMessage("readOnlyConfigFile")); 125 } 126 } 127 128 132 public FileProvider(InputStream is) { 133 setInputStream(is); 134 } 135 136 public void setInputStream(InputStream is) { 137 myInputStream = is; 138 } 139 140 private InputStream getInputStream() { 141 return myInputStream; 142 } 143 144 public WSDDDeployment getDeployment() { 145 return deployment; 146 } 147 148 public void setDeployment(WSDDDeployment deployment) { 149 this.deployment = deployment; 150 } 151 152 158 public void setSearchClasspath(boolean searchClasspath) { 159 this.searchClasspath = searchClasspath; 160 } 161 162 public void configureEngine(AxisEngine engine) 163 throws ConfigurationException { 164 try { 165 if (getInputStream() == null) { 166 try { 167 setInputStream(new FileInputStream (configFile)); 168 } catch (Exception e) { 169 if (searchClasspath) 170 setInputStream(ClassUtils.getResourceAsStream(engine.getClass(), filename, true)); 171 } 172 } 173 174 if (getInputStream() == null) { 175 throw new ConfigurationException( 176 Messages.getMessage("noConfigFile")); 177 } 178 179 WSDDDocument doc = new WSDDDocument(XMLUtils. 180 newDocument(getInputStream())); 181 deployment = doc.getDeployment(); 182 183 deployment.configureEngine(engine); 184 engine.refreshGlobalOptions(); 185 186 setInputStream(null); 187 } catch (Exception e) { 188 throw new ConfigurationException(e); 189 } 190 } 191 192 197 public void writeEngineConfig(AxisEngine engine) 198 throws ConfigurationException { 199 if (!readOnly) { 200 try { 201 Document doc = Admin.listConfig(engine); 202 Writer osWriter = new OutputStreamWriter ( 203 new FileOutputStream (configFile),XMLUtils.getEncoding()); 204 PrintWriter writer = new PrintWriter (new BufferedWriter (osWriter)); 205 XMLUtils.DocumentToWriter(doc, writer); 206 writer.println(); 207 writer.close(); 208 } catch (Exception e) { 209 throw new ConfigurationException(e); 210 } 211 } 212 } 213 214 220 public Handler getHandler(QName qname) throws ConfigurationException { 221 return deployment.getHandler(qname); 222 } 223 224 230 public SOAPService getService(QName qname) throws ConfigurationException { 231 SOAPService service = deployment.getService(qname); 232 if (service == null) { 233 throw new ConfigurationException(Messages.getMessage("noService10", 234 qname.toString())); 235 } 236 return service; 237 } 238 239 245 public SOAPService getServiceByNamespaceURI(String namespace) 246 throws ConfigurationException { 247 return deployment.getServiceByNamespaceURI(namespace); 248 } 249 250 256 public Handler getTransport(QName qname) throws ConfigurationException { 257 return deployment.getTransport(qname); 258 } 259 260 public TypeMappingRegistry getTypeMappingRegistry() 261 throws ConfigurationException { 262 return deployment.getTypeMappingRegistry(); 263 } 264 265 268 public Handler getGlobalRequest() throws ConfigurationException { 269 return deployment.getGlobalRequest(); 270 } 271 272 275 public Handler getGlobalResponse() throws ConfigurationException { 276 return deployment.getGlobalResponse(); 277 } 278 279 282 public Hashtable getGlobalOptions() throws ConfigurationException { 283 WSDDGlobalConfiguration globalConfig 284 = deployment.getGlobalConfiguration(); 285 286 if (globalConfig != null) 287 return globalConfig.getParametersTable(); 288 289 return null; 290 } 291 292 295 public Iterator getDeployedServices() throws ConfigurationException { 296 return deployment.getDeployedServices(); 297 } 298 299 305 public List getRoles() { 306 return deployment.getRoles(); 307 } 308 } 309 | Popular Tags |