    001    /*----------------------------------------------------------------------------
    002     This file is part of deegree, http://deegree.org/
    003     Copyright (C) 2001-2009 by:
    004       Department of Geography, University of Bonn
    005     and
    006       lat/lon GmbH
    007
    008     This library is free software; you can redistribute it and/or modify it under
    009     the terms of the GNU Lesser General Public License as published by the Free
    010     Software Foundation; either version 2.1 of the License, or (at your option)
    011     any later version.
    012     This library is distributed in the hope that it will be useful, but WITHOUT
    013     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    014     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    015     details.
    016     You should have received a copy of the GNU Lesser General Public License
    017     along with this library; if not, write to the Free Software Foundation, Inc.,
    018     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    019
    020     Contact information:
    021
    022     lat/lon GmbH
    023     Aennchenstr. 19, 53177 Bonn
    024     Germany
    025     http://lat-lon.de/
    026
    027     Department of Geography, University of Bonn
    028     Prof. Dr. Klaus Greve
    029     Postfach 1147, 53001 Bonn
    030     Germany
    031     http://www.geographie.uni-bonn.de/deegree/
    032
    033     e-mail: info@deegree.org
    034    ----------------------------------------------------------------------------*/
    035    package org.deegree.tools.datastore;
    036
    037    import java.io.IOException;
    038    import java.io.InputStream;
    039    import java.text.MessageFormat;
    040    import java.util.Properties;
    041
    042    import org.deegree.framework.util.BootLogger;
    043    import org.deegree.i18n.Messages;
    044
    045    /**
    046     *
    047     *
    048     *
    049     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    050     * @author last edited by: $Author: poth $
    051     *
    052     * @version $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
    053     */
    054    public class DBSchemaToDatastoreConfSQLSQLAccess {
    055
    056        private static Properties props = new Properties();
    057
    058        /**
    059         * Initialization done at class loading time.
    060         */
    061        static {
    062            try {
    063                String fileName = "DBSchemaToDatastoreConfSQL.properties";
    064                InputStream is = DBSchemaToDatastoreConfSQLSQLAccess.class.getResourceAsStream( fileName );
    065                props.load( is );
    066                is.close();
    067            } catch ( IOException e ) {
    068                BootLogger.logError( "Error while initializing " + Messages.class.getName() + " : " + e.getMessage(), e );
    069            }
    070        }
    071
    072        /**
    073         * Returns the sql statement assigned to the passed key. If no sql statement is assigned, an
    074         * error message will be returned that indicates the missing key.
    075         *
    076         * @see MessageFormat for conventions on string formatting and escape characters.
    077         *
    078         * @param key
    079         * @param arguments
    080         * @return the sql statement assigned to the passed key
    081         */
    082        public static String getSQLStatement( String key, Object... arguments ) {
    083            String s = props.getProperty( key );
    084            if ( s != null ) {
    085                return MessageFormat.format( s, arguments );
    086            }
    087
    088            // to avoid NPEs
    089            return "$SQLStatement with key: " + key + " not found$";
    090        }
    091    }