package com.eactive.eai.adapter; 

import java.io.Serializable;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Properties;

import com.eactive.eai.common.util.NullControl;

/** 
* 1. 기능 : 어뎁터 프라퍼티 정보를 를 정의한 Java Value Object 클래스
* 2. 처리 개요 : 어뎁터 프라퍼티 정보를 정의한다.
* *     - 
* 3. 주의사항 
*
* @author  : 
* @version : v 1.0.0
* @see : 관련 기능을 참조
* @since   : 
*  : 
*/
public class AdapterPropGroupVO implements Serializable
{ 
    private String name;                //어뎁터 프라퍼티 그룹명[TSEAIAD14.PrptyGroupName]
    private String description;         //어뎁터 프라퍼티 그룹설명[TSEAIAD14.PrptyGroupDesc]
    private Properties props;           //어뎁터 프라퍼티 명, 프라퍼티2값[TSEAIAD15.PrptyName, TSEAIAD15.Prpty2Val]
    
    public AdapterPropGroupVO() {
        this("");
    }
    
    public AdapterPropGroupVO(String name) {
        this(name,"");
    }
    
    public AdapterPropGroupVO(String name, String description) {
        this.name = name;
        this.description = description;
        this.props = new Properties();
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return NullControl.trimSpace(this.description); 
    }
    
    public String getProperty(String key) {
        return (String)props.get(key);
    }
    
    public String getProperty(String key, String defaultValue) {
        String value = (String)props.get(key);
        return (value==null) ? defaultValue : value;    
    }
    
    public void addProperty(String key, String value) {
        props.put(key, NullControl.trimSpace(value));   
    }
    
    public void setProperty(String key, String value) {
        props.put(key,value);   
    }
    
    public void removeProperty(String key) {
        props.remove(key);   
    }
    
    public String[] keys() {  
        Iterator it = this.props.keySet().iterator(); 
        String[] propKeys = new String[this.props.size()];  
        for(int i = 0; it.hasNext(); i++){
            propKeys[i] = (String)it.next();
        }
        Arrays.sort(propKeys);
        return propKeys;
    }
    
    public Properties getProperties() {    
        return props;   
    }
    
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AdapterPropGroupVO[ name=").append(name);
        sb.append(", description=").append(description);
        sb.append(", Properties=").append(props);
        sb.append(" ]");
        
        return sb.toString();   
    }
    
    public void setProperties(Properties prop){
        this.props = prop;
    }
} 
