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