FileDocCategorySizeDatePackage
FileProvider.javaAPI DocApache Axis 1.49694Sat Apr 22 18:57:28 BST 2006org.apache.axis.configuration

FileProvider

public class FileProvider extends Object implements org.apache.axis.WSDDEngineConfiguration
A simple ConfigurationProvider that uses the Admin class to read + write XML files.
author
Glen Daniels (gdaniels@apache.org)
author
Glyn Normington (glyn@apache.org)

Fields Summary
protected static Log
log
private org.apache.axis.deployment.wsdd.WSDDDeployment
deployment
private String
filename
private File
configFile
private InputStream
myInputStream
private boolean
readOnly
private boolean
searchClasspath
Constructors Summary
public FileProvider(String filename)
Constructor which accesses a file in the current directory of the engine or at an absolute path.


                          
       
        this.filename = filename;
        configFile = new File(filename);
        check();
    
public FileProvider(String basepath, String filename)
Constructor which accesses a file relative to a specific base path.

        this.filename = filename;

        File dir = new File(basepath);

        /*
         * If the basepath is not a readable directory, throw an internal
         * exception to make it easier to debug setup problems.
         */
        if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
            throw new ConfigurationException(Messages.getMessage
                                             ("invalidConfigFilePath",
                                              basepath));
        }

        configFile = new File(basepath, filename);
        check();
    
public FileProvider(InputStream is)
Constructor which takes an input stream directly. Note: The configuration will be read-only in this case!

        setInputStream(is);
    
Methods Summary
private voidcheck()
Check the configuration file attributes and remember whether or not the file is read-only.

        try {
            readOnly = configFile.canRead() & !configFile.canWrite();
        } catch (SecurityException se){
            readOnly = true;            
        }

        /*
         * If file is read-only, log informational message
         * as configuration changes will not persist.
         */
        if (readOnly) {
            log.info(Messages.getMessage("readOnlyConfigFile"));
        }
    
public voidconfigureEngine(org.apache.axis.AxisEngine engine)

        try {
            if (getInputStream() == null) {
                try {
                    setInputStream(new FileInputStream(configFile));
                } catch (Exception e) {
                    if (searchClasspath)
                        setInputStream(ClassUtils.getResourceAsStream(engine.getClass(), filename, true));
                }
            }

            if (getInputStream() == null) {
                throw new ConfigurationException(
                        Messages.getMessage("noConfigFile"));
            }

            WSDDDocument doc = new WSDDDocument(XMLUtils.
                                                newDocument(getInputStream()));
            deployment = doc.getDeployment();

            deployment.configureEngine(engine);
            engine.refreshGlobalOptions();

            setInputStream(null);
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
    
public java.util.IteratorgetDeployedServices()
Get an enumeration of the services deployed to this engine

        return deployment.getDeployedServices();
    
public org.apache.axis.deployment.wsdd.WSDDDeploymentgetDeployment()

        return deployment;
    
public java.util.HashtablegetGlobalOptions()
Returns the global configuration options.

        WSDDGlobalConfiguration globalConfig
            = deployment.getGlobalConfiguration();
            
        if (globalConfig != null)
            return globalConfig.getParametersTable();

        return null;
    
public org.apache.axis.HandlergetGlobalRequest()
Returns a global request handler.

        return deployment.getGlobalRequest();
    
public org.apache.axis.HandlergetGlobalResponse()
Returns a global response handler.

        return deployment.getGlobalResponse();
    
public org.apache.axis.HandlergetHandler(javax.xml.namespace.QName qname)
retrieve an instance of the named handler

param
qname XXX
return
XXX
throws
ConfigurationException XXX

        return deployment.getHandler(qname);
    
private java.io.InputStreamgetInputStream()

        return myInputStream;
    
public java.util.ListgetRoles()
Get a list of roles that this engine plays globally. Services within the engine configuration may also add additional roles.

return
a List of the roles for this engine

        return deployment.getRoles();
    
public org.apache.axis.handlers.soap.SOAPServicegetService(javax.xml.namespace.QName qname)
retrieve an instance of the named service

param
qname XXX
return
XXX
throws
ConfigurationException XXX

        SOAPService service = deployment.getService(qname);
        if (service == null) {
            throw new ConfigurationException(Messages.getMessage("noService10",
                                                           qname.toString()));
        }
        return service;
    
public org.apache.axis.handlers.soap.SOAPServicegetServiceByNamespaceURI(java.lang.String namespace)
Get a service which has been mapped to a particular namespace

param
namespace a namespace URI
return
an instance of the appropriate Service, or null

        return deployment.getServiceByNamespaceURI(namespace);
    
public org.apache.axis.HandlergetTransport(javax.xml.namespace.QName qname)
retrieve an instance of the named transport

param
qname XXX
return
XXX
throws
ConfigurationException XXX

        return deployment.getTransport(qname);
    
public org.apache.axis.encoding.TypeMappingRegistrygetTypeMappingRegistry()

        return deployment.getTypeMappingRegistry();
    
public voidsetDeployment(org.apache.axis.deployment.wsdd.WSDDDeployment deployment)

        this.deployment = deployment;
    
public voidsetInputStream(java.io.InputStream is)

        myInputStream = is;
    
public voidsetSearchClasspath(boolean searchClasspath)
Determine whether or not we will look for a "*-config.wsdd" file on the classpath if we don't find it in the specified location.

param
searchClasspath true if we should search the classpath

        this.searchClasspath = searchClasspath;
    
public voidwriteEngineConfig(org.apache.axis.AxisEngine engine)
Save the engine configuration. In case there's a problem, we write it to a string before saving it out to the actual file so we don't screw up the file.

        if (!readOnly) {
            try {
                Document doc = Admin.listConfig(engine);
                Writer osWriter = new OutputStreamWriter(
                        new FileOutputStream(configFile),XMLUtils.getEncoding());
                PrintWriter writer = new PrintWriter(new BufferedWriter(osWriter));
                XMLUtils.DocumentToWriter(doc, writer);
                writer.println();
                writer.close();
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
        }