Property Facade

Property Facade를 작성하여 여러 Property설정파일을 읽어들여  세팅하도록 해봤다.


public class PropertiesFacade
{


    public PropertiesFacade()
    {
    }


    public void loadProperties(String fileName)
    {
        if(properties == null)
            try
            {
                String localFilePath = “resources/config/”;
                String jarFilePath = “/config/”;
                URL url = getClass().getResource(jarFilePath + fileName);
                InputStream fileIn;
                if(url == null)
                    fileIn = new FileInputStream(localFilePath + fileName);
                else
                if(url.getFile().toString().indexOf(“!”) != -1)
                {
                    JarURLConnection jarConn = (JarURLConnection)url.openConnection();
                    fileIn = jarConn.getInputStream();
                } else
                {
                    fileIn = new FileInputStream(url.getPath());
                }
                properties = new Properties();
                properties.load(fileIn);
                fileIn.close();
            }
            catch(Exception e)
            {


                e.printStackTrace();
               


            }
    }


    public Properties getProperties()
    {
        return properties;
    }


    public String getProperty(String name)
    {
        if(properties.getProperty(name) != null)
            return properties.getProperty(name);
        else
            return “null”;
    }



    private Properties properties;


}


  getProperties()나 getProperty(name)을 이용하여 설정된 프로퍼티를 가져올수 있다.



 A class extends PropertiesFacade 처럼 상속하여 추가기능으로 사용하도록 만들었다..

String localFilePath = “resources/config/”;
String jarFilePath = “/config/”;
의 path를 적절히 바꾸어 사용하면 된다.

답글 남기기

이메일 주소는 공개되지 않습니다.