converterfactory.java

来自「Persistence Layer s ebook and source cod」· Java 代码 · 共 62 行

JAVA
62
字号
package pl.converter;

import java.util.Properties;
import pl.PlException;

/**
 * This class is the factory for converter objects.
 *
 * @author  Artem Rudoy
 */
public class ConverterFactory
{
    private static Converter trivialConverter = new TrivialConverter();

    public static final Converter getConverter(String className, ClassLoader loader, Properties properties) throws PlException
    {
        try
        {
            Class cl = Class.forName(className, true, loader);
            Converter converter = (Converter)cl.newInstance();
            converter.init(properties);
            return converter;
        }
        catch(InstantiationException e)
        {
            throw new PlException(e);
        }
        catch(IllegalAccessException e)
        {
            throw new PlException(e);
        }
        catch(ClassNotFoundException e)
        {
            throw new PlException(e);
        }
    }

/*    public static final Converter getConverter(String className, ClassLoader loader, Properties properties)
        throws PlException
    {
        try
        {
            return getConverter(Class.forName(className, true, loader), properties);
        }
        catch(ClassNotFoundException e)
        {
            throw new PlException(e);
        }
    }

    public static final Converter getConverter(String className, Properties properties)
        throws PlException
    {
        return getConverter(className, ConverterFactory.class.getClassLoader(), properties);
    }*/

    public static final Converter getTrivialConverter()
    {
        return trivialConverter;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?