All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vfny.geoserver.global.Config Maven / Gradle / Ivy

There is a newer version: 1.7.0
Show newest version
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.vfny.geoserver.global;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.logging.Logger;

import javax.servlet.ServletContext;

import org.geoserver.util.ReaderUtils;
import org.geotools.factory.Hints;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.vfny.geoserver.global.dto.DataDTO;
import org.vfny.geoserver.global.dto.GeoServerDTO;
import org.vfny.geoserver.global.dto.WCSDTO;
import org.vfny.geoserver.global.dto.WFSDTO;
import org.vfny.geoserver.global.dto.WMSDTO;
import org.vfny.geoserver.global.xml.XMLConfigReader;


/**
 * The application configuratoin facade.
 *
 * @author Justin Deoliveira, The Open Planning Project, [email protected]
 *
 */
public class Config implements ApplicationContextAware {
    protected static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.global");
    WebApplicationContext context;
    XMLConfigReader reader;

//    public XMLConfigReader getXMLReader() throws ConfigurationException {
//        return reader;
//    }

    public File dataDirectory() {
        return GeoserverDataDirectory.getGeoserverDataDirectory();
    }

    public void setApplicationContext(ApplicationContext context)
        throws BeansException {
        
        this.context = (WebApplicationContext) context;

        ServletContext sc = this.context.getServletContext();

        try {
            GeoserverDataDirectory.init(this.context);
            //before proceeding perform some configuration sanity checks
            try {
                doConfigSanityCheck();
            } catch (ConfigurationException ce) {
                LOGGER.severe(ce.getMessage());
                throw new BeanInitializationException(ce.getMessage());
            }
            
            reader = new XMLConfigReader(dataDirectory(), sc);
        } catch (ConfigurationException e) {
            String msg = "Error creating xml config reader";
            throw new BeanInitializationException(msg, e);
        }
    }

    /**
     * Performs a sanity check on the configuration files to allow for
     * the early failure of the bean initialization and providing
     * a meaningful failure message.
     * 

* For the time being, it only ensures that the data dir exists. *

*/ private void doConfigSanityCheck() throws ConfigurationException { File dataDirectory = dataDirectory(); try { ReaderUtils.checkFile(dataDirectory, true); } catch (FileNotFoundException e) { throw new ConfigurationException("Can't access the configuration directory. Reason: " + e.getMessage()); } } public WebApplicationContext getApplictionContext() { return context; } public DataDTO getData() { return reader.getData(); } public GeoServerDTO getGeoServer() { return reader.getGeoServer(); } public WMSDTO getWms() { return reader.getWms(); } public WFSDTO getWfs() { return reader.getWfs(); } public WCSDTO getWcs() { return reader.getWcs(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy