glyn        02/02/12 04:51:53

  Modified:    java/src/org/apache/axis/configuration FileProvider.java
               java/src/org/apache/axis/utils resources.properties
  Log:
  If the engine configuration is derived from a read-only file, issue
  an informational message (via the logging package) and avoid trying
  to save configuration changes.
  
  Revision  Changes    Path
  1.16      +46 -26    
xml-axis/java/src/org/apache/axis/configuration/FileProvider.java
  
  Index: FileProvider.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/configuration/FileProvider.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FileProvider.java 28 Jan 2002 18:23:00 -0000      1.15
  +++ FileProvider.java 12 Feb 2002 12:51:53 -0000      1.16
  @@ -65,9 +65,12 @@
   import org.apache.axis.encoding.TypeMappingRegistry;
   import org.apache.axis.utils.Admin;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.JavaUtils;
  +import org.apache.log4j.Category;
   import org.w3c.dom.Document;
   
   import javax.xml.rpc.namespace.QName;
  +import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.InputStream;
  @@ -81,14 +84,20 @@
    * @author Glen Daniels ([EMAIL PROTECTED])
    */
   public class FileProvider implements EngineConfiguration {
  +    private static Category category =
  +       Category.getInstance(FileProvider.class.getName());
  +
       protected String sep = System.getProperty("file.separator");
   
       protected WSDDDeployment deployment = null;
   
  -    String basepath = ".";
  -    String filename;
  +    private static final String CURRENT_DIR = ".";
  +    protected String basepath;
  +    protected String filename;
  +
  +    protected InputStream myInputStream = null;
   
  -    InputStream myInputStream = null;
  +    protected boolean readOnly = true;
   
       // Should we search the classpath for the file if we don't find it in
       // the specified location?
  @@ -99,7 +108,7 @@
        * engine.
        */
       public FileProvider(String filename) {
  -        this.filename = filename;
  +        this(CURRENT_DIR, filename);
       }
   
       /**
  @@ -109,6 +118,10 @@
       public FileProvider(String basepath, String filename) {
           this.basepath = basepath;
           this.filename = filename;
  +        readOnly = !(new File(basepath, filename)).canWrite();
  +        if (readOnly) {
  +            category.info(JavaUtils.getMessage("readOnlyConfigFile"));
  +        }
       }
   
       /**
  @@ -137,23 +150,28 @@
           this.searchClasspath = searchClasspath;
       }
   
  -    public void configureEngine(AxisEngine engine) throws ConfigurationException {
  +    public void configureEngine(AxisEngine engine)
  +        throws ConfigurationException {
           try {
               if (myInputStream == null) {
                   try {
  -                    myInputStream = new FileInputStream(basepath + sep + filename);
  +                    myInputStream = new FileInputStream(basepath + sep +
  +                                                        filename);
                   } catch (Exception e) {
                       if (searchClasspath) {
  -                        myInputStream = 
engine.getClass().getResourceAsStream(filename);
  +                        myInputStream = engine.getClass().
  +                            getResourceAsStream(filename);
                       }
                   }
               }
   
               if (myInputStream == null) {
  -                throw new ConfigurationException("No engine configuration file - 
aborting!");
  +                throw new ConfigurationException("No engine configuration " +
  +                                                 "file - aborting!");
               }
   
  -            WSDDDocument doc = new 
WSDDDocument(XMLUtils.newDocument(myInputStream));
  +            WSDDDocument doc = new WSDDDocument(XMLUtils.
  +                                                newDocument(myInputStream));
               deployment = doc.getDeployment();
   
               deployment.configureEngine(engine);
  @@ -170,21 +188,21 @@
        * write it to a string before saving it out to the actual file so
        * we don't screw up the file.
        */
  -    public void writeEngineConfig(AxisEngine engine) throws ConfigurationException {
  -        try {
  -            // If there's no filename then we must have created this with just
  -            // an InputStream - in which case the config stuff is read-only
  -            if (filename == null) return;
  -
  -            Document doc = Admin.listConfig(engine);
  -            StringWriter writer = new StringWriter();
  -            XMLUtils.DocumentToWriter(doc, writer);
  -            writer.close();
  -            FileOutputStream fos = new FileOutputStream(basepath + sep + filename);
  -            fos.write(writer.getBuffer().toString().getBytes());
  -            fos.close();
  -        } catch (Exception e) {
  -            throw new ConfigurationException(e);
  +    public void writeEngineConfig(AxisEngine engine)
  +        throws ConfigurationException {
  +        if (!readOnly) {
  +            try {
  +                Document doc = Admin.listConfig(engine);
  +                StringWriter writer = new StringWriter();
  +                XMLUtils.DocumentToWriter(doc, writer);
  +                writer.close();
  +                FileOutputStream fos = new FileOutputStream(basepath + sep +
  +                                                            filename);
  +                fos.write(writer.getBuffer().toString().getBytes());
  +                fos.close();
  +            } catch (Exception e) {
  +                throw new ConfigurationException(e);
  +            }
           }
       }
   
  @@ -218,7 +236,8 @@
           return deployment.getTransport(qname);
       }
   
  -    public TypeMappingRegistry getTypeMappingRegistry() throws 
ConfigurationException {
  +    public TypeMappingRegistry getTypeMappingRegistry()
  +        throws ConfigurationException {
           return deployment.getTypeMappingRegistry();
       }
   
  @@ -240,7 +259,8 @@
        * Returns the global configuration options.
        */
       public Hashtable getGlobalOptions() throws ConfigurationException {
  -        WSDDGlobalConfiguration globalConfig = deployment.getGlobalConfiguration();
  +        WSDDGlobalConfiguration globalConfig = deployment.
  +            getGlobalConfiguration();
           if (globalConfig != null)
               return globalConfig.getParametersTable();
   
  
  
  
  1.52      +2 -0      xml-axis/java/src/org/apache/axis/utils/resources.properties
  
  Index: resources.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/resources.properties,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- resources.properties      8 Feb 2002 17:45:39 -0000       1.51
  +++ resources.properties      12 Feb 2002 12:51:53 -0000      1.52
  @@ -292,6 +292,8 @@
   
   noEngineWSDD=Engine configuration is not present or not WSDD!
   
  +readOnlyConfigFile=Configuration file read-only so engine configuration changes 
will not be saved.
  +
   noHandler00=Cannot locate handler:  {0}
   
   # NOTE:  in noHandler01, do not translate "QName"
  
  
  


Reply via email to