À̹ø ±Û¿¡¼´Â ¿¹Àü¿¡ ¹ü¿ëÀûÀ¸·Î »ç¿ëÇÏ°íÀÚ Çß´ø ÇÁ·ÎÆÛƼ¿¡
´ëÇÑ ¿¹Àü¿¡ ÇÁ·ÎÁ§Æ®¿¡ Àû¿ëÇß´ø ³»¿ëÀ» Àû°íÀÚ ÇÑ´Ù. »ç½Ç ¿äÁòÀÌ¾ß xmlÀ» ±âº»À¸·Î ÇÏ¿©
¼³Á¤ÇÏ´Â °ÍÀÌ ÀϹÝÀûÀÌÁö¸¸ ºÒ°ú 1~2³âÀü¸¸ Çصµ property¶Ç´Â resource bundleÀ» ÀÌ¿ëÇÒ ¼ö
¾ø´ø ½ÃÀý(?) ÀÌ ÀÖ¾ú´Ù.
±× ´ç½Ã ÇÁ·ÎÆÛƼ¸¦ ±×¶§ ±×¶§ ²ø¾îµéÀÌ´Â ¹«½ÄÇÑ ¹æ¹ýÀÌ ¾Æ´Ï¶ó cache±â¹ýÀ» ÀÌ¿ëÇÏ¿©
¿ì¸®°¡ »ç¿ëÇÏ°Ô µÉ ¸ðµç ÇüÅÂÀÇ ³»¿ëÀ» ¸Þ¸ð¸®¿¡ ¿Ã·Á³õ´Â ¹æ¹ýÀ¸·Î ¾î¶»°Ôµç ¼ÓµµÂ÷¸¦
ÁÙÀÌ·Á Çß´Ù. ¿Ö³ÄÇÏ¸é ¾îÂ÷ÇÇ ÇÁ·ÎÆÛƼ´Â ÆÄÀÏ¿¡ Á÷Á¢ writingµÈ ÇüÅÂÀ̱⠶§¹®¿¡
ÀоîµéÀÌ´Â ½Ã°£¹× ·Îµå½Ã°£ÀÌ ¸¸¸¸Ä¡ ¾Ê±â ¶§¹®À̾ú´Ù. ³Ê¹«µµ ´ç¿¬ÇÏ À̾߱⸦ Çϴ°Ç
¾Æ´ÑÁö ¸ð¸£°Ú´Ù.
ÇÏ¿©°£ ÀÌ·¯ÇÑ ±â¹Ý¿¡ ÇѲ¨¹ø¿¡ ¾²ÀÌ´Â ¸ðµç ÇÁ·ÎÆÛƼ¼Ó¼ºÀ» Àоîµé¿© ÆÑÅ丮 ÇüÅÂÀÇ
°´Ã¼¿¡ ÀúÀåÇÑ ÈÄ ÀÌÈÄ È£ÃâÀÌ ÀÖÀ» °æ¿ì´Â cache°¡ Á¸ÀçÇÏ´ÂÁö ¾ÈÇÏ´ÂÁöÀÇ ¿©ºÎ¸¦ factory¿¡
ÀÇÇÏ¿© ÆǺ°ÇÑ ÈÄ Ã³¸®°¡ µÉ ¼ö ÀÖµµ·Ï ÇÏ¿´´Ù.
È®ÀåµÈ ÇüÅÂÀÇ ÇÁ·ÎÁ§Æ®¿¡¼´Â ÇØ´ç ÇÁ·ÎÆÛƼ¿¡ ´ëÇÑ ºÐ»ê °´Ã¼¸¦ Á¤ÀÇÇÏ¿© ¿©·¯´ëÀÇ box°¡
Á¸ÀçÇÒ °æ¿ì ÇϳªÀÇ box¿¡¼ propertyÀÇ º¯°æÀÌ Å½ÁöµÉ °æ¿ì ±× Á¤º¸¸¦ ´Ù¸¥ box·Î
ÀüÆÄ(propagation)½ÃÅ°´Â Ŭ·¡½ºµéÀ» ÀÛ¼ºÇÑ ÀûÀÌ ÀÖ´Ù.
ÀÌ Å¬·¡½ºµéÀº ±×·¯ÇÑ °³³äÀÇ °¡Àå ±âº»ÀûÀΠŬ·¡½ºµéÀÇ ÁýÇÕÀ̸ç, ÃÑ 6°³ÀÇ Å¬·¡½º·Î
Å×½ºÆ®µÇ¾îÁú ¼ö ÀÖ´Ù.
¿ì¼± °¡Àå ±âº»°ñ°ÝÀÎ PropertyManagerŬ·¡½ººÎÅÍ º¸µµ·Ï ÇÑ´Ù.
1. PropertyManager.java
package com.common.util;
import java.util.Properties;
import java.util.Hashtable;
import java.util.Date;
public class PropertyManager {
private static PropertyFactory factory = new PropertyFactory();
private static Hashtable propertyTable;
private static PropertyManager manager;
static{
synchronized(PropertyManager.class){
propertyTable = factory.getLoadProperties();
System.out.println("[" + new Date().toString() + "] Property loading......");
}
}
private PropertyManager() {}
/**
* WebPage, Query, Message, Environment loading
*/
public static PropertyManager getInstance() {
if(manager == null) {
manager = new PropertyManager();
}
return manager;
}
public static CommonProperties getProperties(String propertyName){
return findProperties(propertyName);
}
public static Hashtable getPropertyInfo(){
return propertyTable;
}
// ÇØ´ç factory°´Ã¼¿¡¼ ·ÎµùÇÑ ÇÁ·ÎÆÛƼ°¡ ÇöÀç Á¸ÀçÇÏ´ÂÁö¸¦ È®ÀÎÇÑ´Ù.
private static boolean checkInstance() {
return false;
}
// Çؽ¬Å×À̺í¾È¿¡ ÀúÀåµÈ °¢°¢ÀÇ ÇÁ·ÎÆÛƼ¸¦ °Ë»öÇÏ¿©
//¿øÇÏ´Â ÇÁ·ÎÆÛƼ¸¦ »ç¿ëÇÒ¼ö ÀÖµµ·Ï ¸®ÅÏÇÑ´Ù.
private static CommonProperties findProperties(String propertyName) {
CommonProperties prop = (CommonProperties) propertyTable.get(propertyName);
return prop;
}
};
À§ÀÇ Å¬·¡½º¿¡¼ ÇÙ½ÉÀûÀÎ ¸Þ¼Òµå´Â ´ç¿¬È÷ static initializer¿Í getPropertiesÀÌ´Ù
static initializer¿¡¼´Â ÃÖÃÊ·Î ·ÎµåµÇ¾îÁú ÇÁ·ÎÆÛƼµé¿¡ ´ëÇÑ Á¤º¸¸¦
²ø¾îµé¾î ÀÚ½ÅÀÌ °¡Áö°í ÀÖ´Â staticÇüÅÂÀÇ ÀúÀå¼Ò(repository)¿¡ ÀúÀåÇϵµ·Ï ÇÑ´Ù.
Written by carouser
2001-07-12 |