001    package org.apache.ojb.broker.accesslayer.sql;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import org.apache.ojb.broker.util.factory.ConfigurableFactory;
019    import org.apache.ojb.broker.platforms.Platform;
020    
021    import java.util.Map;
022    import java.util.HashMap;
023    
024    /**
025     * This factory creates SqlGenerator instances. it is a configurable factory and
026     * can be used to generate user defined implementations too.
027     * @author Thomas Mahler
028     */
029    public class SqlGeneratorFactory extends ConfigurableFactory
030    {
031            private static SqlGeneratorFactory instance = null;
032    
033        private Map generatorMap = new HashMap();
034    
035            /**
036             * @see org.apache.ojb.broker.util.factory.ConfigurableFactory#getConfigurationKey()
037             */
038            protected String getConfigurationKey()
039            {
040                    return "SqlGeneratorClass";
041            }
042    
043            public SqlGenerator createSqlGenerator(Platform pf)
044            {
045                    SqlGenerator gen = (SqlGenerator) generatorMap.get(pf.getClass().getName());
046            if(gen == null)
047            {
048                gen = (SqlGenerator) this.createNewInstance(Platform.class, pf);
049                generatorMap.put(pf.getClass(), gen);
050            }
051            return gen;
052            }
053    
054            public static SqlGeneratorFactory getInstance()
055            {
056                    if (instance == null)
057                    {
058                            instance = new SqlGeneratorFactory();
059                    }
060                    return instance;
061            }
062    }