package com.cpic.xim.config;

import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

public class WeatherDisasterNotifyConfig
{
    private static final int BUFFER_SIZE = 1024;

    public static WeatherDisasterNotifyConfig load( String filePath )
            throws IOException

    {
        WeatherDisasterNotifyConfig config = null;
        ObjectMapper mapper = new ObjectMapper();
        FileReader configFile = null;
        StringBuffer json = null;
        char[] buffer = new char[BUFFER_SIZE];

        //设置json属性
        mapper.setPropertyNamingStrategy( PropertyNamingStrategy.SNAKE_CASE );

        try{
            configFile = new FileReader( filePath );
            json = new StringBuffer();

            int length = configFile.read( buffer );

            while ( length != -1 )
            {
                json.append( buffer );

                length = configFile.read( buffer );
            }

            config = mapper.readValue( json.toString(), WeatherDisasterNotifyConfig.class );
        }
        finally
        {
            if ( configFile != null )
            {
                try
                {
                    configFile.close();
                }
                catch ( IOException e )
                {
                    e.printStackTrace();
                }
            }
        }

        return config;
    }

    public WeatherDisasterNotifyConfig() {};

    public String getTitle()
    {
        return title;
    }

    public void setTitle( String title )
    {
        this.title = title;
    }

    public String getKey()
    {
        return key;
    }

    public void setKey( String key )
    {
        this.key = key;
    }

    public String getQueryUrl()
    {
        return queryUrl;
    }

    public void setQueryUrl( String queryUrl )
    {
        this.queryUrl = queryUrl;
    }

    public Vector<City> getCities()
    {
        return cities;
    }

    public void setCities( Vector<City> cities )
    {
        this.cities = cities;
    }

    public Vector<CpicxmStuff> getNotifyStuffs()
    {
        return notifyStuffs;
    }

    public void setNotifyStuffs( Vector<CpicxmStuff> notifyStuffs )
    {
        this.notifyStuffs = notifyStuffs;
    }

    private String              title;
    private String              key;
    private String              queryUrl;
    private Vector<City>        cities;
    private Vector<CpicxmStuff> notifyStuffs;
}
