낭중에 아래의 형태로 추가를 해야겠습니다.

public boolean write(ArrayList<ConfigValue> list) throws Exception {
                
        for(int i=0; i < list.size(); i++) {
            System.out.println(list.get(i).getService() +" - "+ list.get(i).getKey()+" - "+ list.get(i).getValues().toString());
        }
       
        String fileName = "config-test.xml";
        String empty ="    ";        
       
        try {       
            XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
            XMLStreamWriter writer = xmlFactory.createXMLStreamWriter(new java.io.FileWriter(fileName));
       
            writer.writeStartDocument("1.0");
            writer.writeCharacters(System.getProperty("line.separator"));
            writer.writeStartElement("sjava-config");
            writer.writeCharacters(System.getProperty("line.separator"));
           
           
            String serviceName = list.get(0).getService();
           
            ArrayList<String> serviceList = new ArrayList<String>();
            serviceList.add(serviceName);
           
            for(int i=0; i < list.size(); i++) {
                if(!serviceName.equals(list.get(i).getService()) ) {
                    serviceName = list.get(i).getService();
                    serviceList.add(serviceName);
                }
            }
           
            for(int i=0; i < serviceList.size(); i++) {
                writer.writeCharacters(empty);
                writer.writeStartElement("sjava-service");
                writer.writeAttribute("name", serviceList.get(i));
                writer.writeCharacters(System.getProperty("line.separator"));
               
               
                for(int j=0; j < list.size(); j++) {
                    if(serviceList.get(i).equals(list.get(j).getService()) ) {
                        serviceName = list.get(j).getService();
                       
                        writer.writeCharacters(empty + empty);
                        writer.writeStartElement("key");
                        writer.writeAttribute("name", list.get(j).getKey());
                       
                        String tmpValue = "";
                        for(int z =0; z < list.get(j).getValues().length; z++) {
                            tmpValue += list.get(j).getValues()[z];
                            if(z != list.get(j).getValues().length-1)
                                tmpValue +=",";
                        }
                           
                        writer.writeAttribute("value", tmpValue);
                        writer.writeEndElement();
                        writer.writeCharacters(System.getProperty("line.separator"));
                    }
                }
                writer.writeCharacters(empty);
                writer.writeEndElement();
                writer.writeCharacters(System.getProperty("line.separator"));
            }
           
            writer.writeEndElement();
            writer.flush();
            writer.close();
           
        } catch(Exception e) {
            e.printStackTrace();
        }
       
        return true;
    }

위 코드로 아래의 결과를 만들어 낼 수 있다.
<?xml version="1.0"?>
<sjava-config>
    <sjava-service name="sjava-config">
        <key name="watch" value="false"></key>
        <key name="period" value="60"></key>
    </sjava-service>
    <sjava-service name="sjava-logging-server">
        <key name="host" value="111.111.111.111,222.222.222.222"></key>
        <key name="port" value="20003"></key>
    </sjava-service>
</sjava-config>

Tag // java, sjava-config
sjava-config, sjava-logging 라이브러리가 1.4버전으로 업데이트 되었습니다.
sjava-config(1.4) : http://sjava-config.googlecode.com/files/sjava-config-1.4.zip
sjava-logging(1.4) : http://sjava-logging.googlecode.com/files/sjava-logging-1.4.zip


구글 프로젝트 호스팅의 도움을 받아서 코드 및 문서를 이동합니다.
기본적인 문서는 아래의 위치를 참고하세요..
http://code.google.com/p/sjava-config/wiki/
http://code.google.com/p/sjava-config/wiki/Introduce

그리고, 소스는 아래의 위치를 참고하세요.
http://code.google.com/p/sjava-config/source/checkout
http://code.google.com/p/sjava-config/source/browse/
http://code.google.com/p/sjava-config/source/list

다시한번, 구글이 좋아지네요.. ^^


sjava-config 1.3

from My Project 2009/10/23 17:30
ConfigHandler의 생성자 부분에 대한 변경이 있었습니다.
그리고, getValue의 조건체크를 Specification Pattern을 통해서 적용하였습니다.
사용법은 http://www.sjava.net/121를 참고하시면 됩니다.

바이너리 & 소스



sjava-logging 1.0

from My Project 2009/07/09 10:55
java logging library 입니다.
file에 write 하는 BufferedWriter의 성능을 높이기 위한 tip이 적용되어 있습니다.
config 처리는 sjava-config 코드를 복사해서 패키지 이름만 바꿨습니다. ^^;;
아래 예제는 설정파일과 sjava-logging-1.0.jar를 클래스 패스가 잡힌 위치에 복사를 하시고 돌리시면 됩니다.

예제
package net.sjava.logging.test;

import net.sjava.logging.Logger;

import java.util.Date;
import java.text.SimpleDateFormat;

public class LoggingTest {

    private static SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS");
   
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //load();

        // add shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                net.sjava.logging.util.BufferedWriterCacheUtility.shutdown();
            }
        });
       
        System.out.println("s - " + format.format(new Date()));
       
        for(int i=0; i < 1000000; i++) {
            Logger.getInstance().log("aaaaaaaaaaaaaaa");
            Logger.getInstance().log("aaaaaaaaaaaaccccccccccccccccccaaa");
           
            Logger.getInstance().log("metoo", "푸푸푸푸푸박.. ");
           
            Logger.getInstance().log("abcded", "abcde", "aaaa b aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        }
   
        System.out.println("e - " + format.format(new Date()));
    }
}

설정파일
<?xml version="1.0" encoding="utf-8"?>
<sjava-logging>
    <!-- array variable delimeter is "," -->
    <!-- do not delete  -->
    <sjava-service name="config">
        <key name="watch" value="false" /> <!-- true, false -->
        <key name="period" value="60" /> <!-- 60 seconds -->
    </sjava-service>
   
    <!-- 로그서버 설정 -->
    <sjava-service name="logging">
        <key name="baseDir" value="d:\sjava-logging" />
        <key name="serviceDir" value="default" />
        <key name="fileName" value="default" />
        <key name="fileExt" value="log" />
        <key name="bufferSize" value="1024" />
        <!-- dayily(1), hourly(2), minutes(3) -->
        <key name="strategy" value="2" />
    </sjava-service>
   
</sjava-logging>

바이너리 & 소스

'My Project' 카테고리의 다른 글

sjava-config 1.3  (0) 2009/10/23
sjava-logging 1.0 Level  (0) 2009/07/13
sjava-logging 1.0  (0) 2009/07/09
sjava-config 1.2  (0) 2009/07/08
sjava-config 1.1  (0) 2009/07/03

sjava-config 1.2

from My Project 2009/07/08 17:10
테스트 코드의 변경이 있습니다.
기존코드에 영향이 없기 때문에 버전차이는 의미가 없을듯 합니다.
사용법은 http://www.sjava.net/121를 참고하시면 됩니다.

바이너리 & 소스


'My Project' 카테고리의 다른 글

sjava-logging 1.0 Level  (0) 2009/07/13
sjava-logging 1.0  (0) 2009/07/09
sjava-config 1.2  (0) 2009/07/08
sjava-config 1.1  (0) 2009/07/03
sjava-config 1.0  (0) 2009/06/30

sjava-config 1.1

from My Project 2009/07/03 14:17
config 파일을 모니터링하는 부분의 코드가 변경이 되었습니다.
기존의 net.sjava.config.util.Watcher 클래스를 Timer를 이용하는 TimerTask로 변경을 하였습니다.
사용법은 http://www.sjava.net/121를 참고하시면 됩니다.

바이너리

'My Project' 카테고리의 다른 글

sjava-logging 1.0 Level  (0) 2009/07/13
sjava-logging 1.0  (0) 2009/07/09
sjava-config 1.2  (0) 2009/07/08
sjava-config 1.1  (0) 2009/07/03
sjava-config 1.0  (0) 2009/06/30

sjava-config 1.0

from My Project 2009/06/30 10:37
설정파일을 저장하고 가져오는 라이브러리입니다.
sjava-config는 http://www.jconfig.org/jconfig를 보고 필요한 형태(xml만 지원)로만 개발했습니다.
여러형태의 설정파일을 읽어올 수 있도록 common한 기능은 추상 클래스로 빼고 설정을 읽는 코드는 하위 클래스에서 구현을 합니다.

설정파일의 형태는 아래와 같습니다.
sjava-config.xml
<?xml version="1.0" encoding="utf-8"?>
<sjava-config>
    <!-- array variable delimeter is "," -->
    <!-- sjava-config 설정, 아래 설정은 지우지 마세요 -->
    <sjava-service name="config">
        <key name="watch" value="true" /> <!-- true, false -->
        <key name="interval" value="60" /> <!-- 60 seconds -->
    </sjava-service>
   
    <!-- 로그서버 설정 -->
    <sjava-service name="log">
        <key name="host" value="111.111.111.111,222.222.222.222" />
        <key name="port" value="20003" />
    </sjava-service>
</sjava-config>

그리고 위 파일(sjava-config.xml)은 classpath에 위치를 해야 읽을 수 있습니다.

ConfigTest.java
package net.sjava.config.demo;

import net.sjava.config.ConfigHandler;

/**
 * Code Coverage Test Class using EclEmma
 * @author mcsong@gmail.com
 * @since 2009. 6. 29.
 */
public class ConfigTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
        ConfigHandler configHandler = ConfigHandler.getInstance();
        System.out.println(configHandler.isLoading() ? "loading true" : "loading fail");
       
        System.out.println("- get vlaue test ---");
        System.out.println(configHandler.getValue("config", "watch"));
        System.out.println(configHandler.getValue("config", "interval"));
        System.out.println(configHandler.getValue("log", "host"));
        System.out.println(configHandler.getValue("log", "port"));
        System.out.println(configHandler.getValue("auth", "host"));
        System.out.println(configHandler.getValue("auth", "port"));
       
        System.out.println("- default value test ---");
        System.out.println(configHandler.getValue("config", "watch", "false"));
        System.out.println(configHandler.getValue("config", "interval", "11"));
        System.out.println(configHandler.getValue("log", "host", "222.222.222.222"));
        System.out.println(configHandler.getValue("log", "port", "20003"));
        System.out.println(configHandler.getValue("auth", "host", "222.222.222.222"));
       
        System.out.println("- array value test ---");
        for(int i = 0; i < configHandler.getValues("log", "host").length; i++) {
            System.out.println(configHandler.getValues("log", "host")[i].toString());
        }
       
        for(int i = 0; i < configHandler.getValues("auth", "host").length; i++) {
            System.out.println(configHandler.getValues("auth", "host")[i].toString());
        }
       
        System.out.println("- add value ---");
        configHandler.addValue("test", "host", "1.1.1.1");
        System.out.println(configHandler.getValue("test", "host"));
       
        System.out.println("- modify value ---");
        configHandler.setValue("test", "host", "2.2.2.2");
        System.out.println(configHandler.getValue("test", "host"));
       
        System.out.println("- modify values ---");
        String[] values = {"2.2.2.2", "3.3.3.3"};
        configHandler.setValues("test", "host", values);
       
        for(int i = 0; i < configHandler.getValues("test", "host").length; i++) {
            System.out.println(configHandler.getValues("test", "host")[i].toString());
        }
    }

}

바이너리

소스

'My Project' 카테고리의 다른 글

sjava-logging 1.0 Level  (0) 2009/07/13
sjava-logging 1.0  (0) 2009/07/09
sjava-config 1.2  (0) 2009/07/08
sjava-config 1.1  (0) 2009/07/03
sjava-config 1.0  (0) 2009/06/30