1 55 56 package org.jboss.axis.configuration; 57 58 import org.jboss.axis.AxisEngine; 59 import org.jboss.axis.ConfigurationException; 60 import org.jboss.axis.Handler; 61 import org.jboss.axis.WSDDEngineConfiguration; 62 import org.jboss.axis.deployment.wsdd.WSDDDeployment; 63 import org.jboss.axis.deployment.wsdd.WSDDDocument; 64 import org.jboss.axis.deployment.wsdd.WSDDGlobalConfiguration; 65 import org.jboss.axis.encoding.TypeMappingRegistry; 66 import org.jboss.axis.handlers.soap.SOAPService; 67 import org.jboss.axis.utils.Admin; 68 import org.jboss.axis.utils.ClassUtils; 69 import org.jboss.axis.utils.Messages; 70 import org.jboss.axis.utils.XMLUtils; 71 import org.jboss.logging.Logger; 72 import org.w3c.dom.Document ; 73 74 import javax.xml.namespace.QName ; 75 import java.io.File ; 76 import java.io.FileInputStream ; 77 import java.io.FileOutputStream ; 78 import java.io.InputStream ; 79 import java.io.StringWriter ; 80 import java.util.Hashtable ; 81 import java.util.Iterator ; 82 83 90 public class FileProvider implements WSDDEngineConfiguration 91 { 92 private static Logger log = Logger.getLogger(FileProvider.class.getName()); 93 94 private WSDDDeployment deployment = null; 95 96 private String filename; 97 private File configFile = null; 98 99 private InputStream myInputStream = null; 100 101 private boolean readOnly = true; 102 103 private boolean searchClasspath = true; 106 107 111 public FileProvider(String filename) 112 { 113 this.filename = filename; 114 configFile = new File (filename); 115 check(); 116 } 117 118 122 public FileProvider(String basepath, String filename) 123 throws ConfigurationException 124 { 125 this.filename = filename; 126 127 File dir = new File (basepath); 128 129 133 if (!dir.isDirectory() || !dir.canRead()) 134 { 135 throw new ConfigurationException(Messages.getMessage 136 ("invalidConfigFilePath", 137 basepath)); 138 } 139 140 configFile = new File (basepath, filename); 141 check(); 142 } 143 144 148 private void check() 149 { 150 readOnly = configFile.canRead() & !configFile.canWrite(); 151 152 156 if (readOnly) 157 { 158 log.info(Messages.getMessage("readOnlyConfigFile")); 159 } 160 } 161 162 166 public FileProvider(InputStream is) 167 { 168 setInputStream(is); 169 } 170 171 public void setInputStream(InputStream is) 172 { 173 myInputStream = is; 174 } 175 176 private InputStream getInputStream() 177 { 178 return myInputStream; 179 } 180 181 public WSDDDeployment getDeployment() 182 { 183 return deployment; 184 } 185 186 public void setDeployment(WSDDDeployment deployment) 187 { 188 this.deployment = deployment; 189 } 190 191 197 public void setSearchClasspath(boolean searchClasspath) 198 { 199 this.searchClasspath = searchClasspath; 200 } 201 202 public void configureEngine(AxisEngine engine) 203 throws ConfigurationException 204 { 205 try 206 { 207 if (getInputStream() == null) 208 { 209 try 210 { 211 setInputStream(new FileInputStream (configFile)); 212 } 213 catch (Exception e) 214 { 215 if (searchClasspath) 216 setInputStream(ClassUtils.getResourceAsStream(engine.getClass(), filename)); 217 } 218 } 219 220 if (getInputStream() == null) 221 { 222 throw new ConfigurationException(Messages.getMessage("noConfigFile")); 223 } 224 225 WSDDDocument doc = new WSDDDocument(XMLUtils. 226 newDocument(getInputStream())); 227 deployment = doc.getDeployment(); 228 229 deployment.configureEngine(engine); 230 engine.refreshGlobalOptions(); 231 232 setInputStream(null); 233 } 234 catch (Exception e) 235 { 236 throw new ConfigurationException(e); 237 } 238 } 239 240 245 public void writeEngineConfig(AxisEngine engine) 246 throws ConfigurationException 247 { 248 if (!readOnly) 249 { 250 try 251 { 252 Document doc = Admin.listConfig(engine); 253 StringWriter writer = new StringWriter (); 254 XMLUtils.DocumentToWriter(doc, writer); 255 writer.close(); 256 FileOutputStream fos = new FileOutputStream (configFile); 257 fos.write(writer.getBuffer().toString().getBytes()); 258 fos.close(); 259 } 260 catch (Exception e) 261 { 262 throw new ConfigurationException(e); 263 } 264 } 265 } 266 267 274 public Handler getHandler(QName qname) throws ConfigurationException 275 { 276 return deployment.getHandler(qname); 277 } 278 279 286 public SOAPService getService(QName qname) throws ConfigurationException 287 { 288 return deployment.getService(qname); 289 } 290 291 297 public SOAPService getServiceByNamespaceURI(String namespace) 298 throws ConfigurationException 299 { 300 return deployment.getServiceByNamespaceURI(namespace); 301 } 302 303 310 public Handler getTransport(QName qname) throws ConfigurationException 311 { 312 return deployment.getTransport(qname); 313 } 314 315 public TypeMappingRegistry getTypeMappingRegistry() 316 throws ConfigurationException 317 { 318 return deployment.getTypeMappingRegistry(); 319 } 320 321 324 public Handler getGlobalRequest() throws ConfigurationException 325 { 326 return deployment.getGlobalRequest(); 327 } 328 329 332 public Handler getGlobalResponse() throws ConfigurationException 333 { 334 return deployment.getGlobalResponse(); 335 } 336 337 340 public Hashtable getGlobalOptions() throws ConfigurationException 341 { 342 WSDDGlobalConfiguration globalConfig 343 = deployment.getGlobalConfiguration(); 344 345 if (globalConfig != null) 346 return globalConfig.getParametersTable(); 347 348 return null; 349 } 350 351 354 public Iterator getDeployedServices() throws ConfigurationException 355 { 356 return deployment.getDeployedServices(); 357 } 358 } 359 | Popular Tags |