⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.java

📁 短信网关发送接受平台。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        Config.db_type=Config.MYSQL_DB;
                }else if(temp.equalsIgnoreCase("oracle")){
                        Config.db_type=Config.ORALCE_DB;
                }else{
                        throw new ConfigException("unsupported database type!");
                }
                //取数据库位置
                if ((Config.db_host=xml.getStringValue("/config/db_info/db_host"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'db_host' in config.ini");
                }
                //取数据库名
                if ((Config.db_name=xml.getStringValue("/config/db_info/db_name"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'db_name' in config.ini");
                }

//del                if (!Config.getDBConfig(db_type,db_host,db_name)){
//del                         throw new ConfigException("unsupported database type!");
//del                }
                //取数据库用户名
                if ((Config.db_Account=xml.getStringValue("/config/db_info/db_user"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'db_user' in config.ini");
                }
                //取数据库密码
                if ((Config.db_Password=xml.getStringValue("/config/db_info/db_password"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'db_password' in config.ini");
                }

                Config.getServiceInfo();

                //取管理信息
                //取SMTP服务器地址
                if ((Config.mail_smtp_host=xml.getStringValue("/config/administrator/mail_sender.mail_smtp_host"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'mail_sender.mail_smtp_host' in config.ini");
                }
                //取发信人馨香
                if ((Config.mail_sender=xml.getStringValue("/config/administrator/mail_sender"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'mail_sender' in config.ini");
                }
                //取是否需要认证

                        Config.mail_need_auth=true;
                //取发信人用户名
                if ((Config.mail_sender_user_name=xml.getStringValue("/config/administrator/mail_sender.account"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'mail_sender.account' in config.ini");
                }
                //取发信人密码
                if ((Config.mail_sender_user_password=xml.getStringValue("/config/administrator/mail_sender.password"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'mail_sender.password' in config.ini");
                }
                //取收件人地址
                if ((temp=xml.getStringValue("/config/administrator/mail_reciever"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'mail_reciever' in config.ini");
                }else{
                        StringTokenizer st=new StringTokenizer(temp,";");
                        while (st.hasMoreTokens()){
                                Config.mail_reciever.add(st.nextElement());
                        }
                }



                //取服务器信息
                if ((Config.server_host=xml.getStringValue("/config/server_info/xmlcenter.host"))==null){
                        throw new ConfigException("config option: Cann't find the value of 'xmlcenter.host' in config.ini");
                }

                if((Config.server_port=xml.getIntValue("/config/server_info/xmlcenter.port"))==0 ){
                        Config.server_port=8809;
                }

                if((Config.local_port=xml.getIntValue("/config/server_info/xmlrouter.port"))==0 ){
                        Config.local_port=9000;
                }

                if((Config.flux=xml.getIntValue("/config/router/flux"))==0 ){
                        Config.flux=30;
                }

                Config.send_queue=new DataPool(Config.flux);
                Config.sleep_time=1000/Config.flux;

                //取提示信息
                if ((temp=xml.getStringValue("/config/notice_info/is_not_working"))==null || temp.equalsIgnoreCase("")){
                        temp="对不起,该服务忙,请稍后再试!";
                        //throw new ConfigException("config option: Cann't find the value of 'mail_reciever' in config.ini");
                }else{
                        if (temp.length()>140)
                                temp=temp.substring(0,140);
                }
                Config.is_not_working=temp.getBytes();

                if ((temp=xml.getStringValue("/config/notice_info/no_such_service"))==null || temp.equalsIgnoreCase("")){
                        temp="对不起,没有该项业务!";
                        //throw new ConfigException("config option: Cann't find the value of 'mail_reciever' in config.ini");
                }else{
                        if (temp.length()>140)
                                temp=temp.substring(0,140);
                }
                Config.no_such_service=temp.getBytes();

                if ((temp=xml.getStringValue("/config/notice_info/message_is_null"))==null || temp.equalsIgnoreCase("")){
                        temp="上行信息不能为空,请检查!";
                        //throw new ConfigException("config option: Cann't find the value of 'mail_reciever' in config.ini");
                }else{
                        if (temp.length()>140)
                                temp=temp.substring(0,140);
                }
                Config.message_is_null=temp.getBytes();



                //释放对象,关闭文件
                xml.release();
                xml=null;
                return true;
        }

        private static void getServiceInfo(){
                String db_driver="";
                String db_url="";
                if (Config.db_type==Config.MSSQL_DB){
                        db_driver="com.thinweb.tds.Driver";
                        db_url="jdbc:twtds:sqlserver://"+Config.db_host+"/"+Config.db_name+";TDS=7.0";
                }else if(Config.db_type==Config.MYSQL_DB){
                        db_driver="org.gjt.mm.mysql.Driver";
                        db_url="jdbc:mysql://"+Config.db_host+"/"+Config.db_name;
                }else if(Config.db_type==Config.ORALCE_DB){
                        db_driver="oracle.jdbc.driver.OracleDriver";
                        db_url="jdbc:oracle:thin:@localhost:1521:orcl";
                }
                try{
                        //type1 ------ 二级代码类
                        ServiceInfo type1=null;
                        //type2 ------ 业务代码类
                        ServiceInfo type2=null;
                        Class.forName(db_driver);
                        Connection con=DriverManager.getConnection(db_url,Config.db_Account,Config.db_Password);
                        Statement st=con.createStatement();
                        ResultSet rs=st.executeQuery("select module_id,host,service_id,subcode from services group by module_id");
                        int id=0;
                        int module_id=0;
                        String host="";
                        String service_id="";
                        String subcode="";
                        while(rs.next()){
                                host=rs.getString("host");
                                Config.trustIP.add(host);
                                module_id=rs.getInt("module_id");
                                service_id=rs.getString("service_id");
                                subcode=rs.getString("subcode");
                                if (subcode!=null && !subcode.equalsIgnoreCase("")){
                                        type1=new ServiceInfo(module_id,host);
                                        Config.subcode_item.add(type1);
                                }else{
                                        type2=new ServiceInfo(module_id,host);
                                        Config.service_id_item.add(type2);
                                }
                        }
                        rs.close();
                        for (int i=0;i<Config.subcode_item.size();i++){
                                type1=(ServiceInfo)Config.subcode_item.elementAt(i);
                                rs=st.executeQuery("select subcode,host from services where module_id="+type1.id);
                                while(rs.next()){
                                        type1.client_host=rs.getString("host");
                                        type1.addService(rs.getString("subcode"));
                                }
                                rs.close();
                        }
                        for (int i=0;i<Config.service_id_item.size();i++){
                                type2=(ServiceInfo)Config.service_id_item.elementAt(i);
                                rs=st.executeQuery("select service_id,host from services where module_id="+type2.id);
                                while(rs.next()){
                                        type2.client_host=rs.getString("host");
                                        type2.addService(rs.getString("service_id"));
                                }
                                rs.close();
                        }

                        st.close();
                        con.close();
                }catch(Exception e){
                        Config.log.log(e,"while get service_info in Config class!");
                        e.printStackTrace();
                        System.out.println("System exit ...");
                        Config.releaseConfig();
                        System.exit(0);
                }

        }

        public static void releaseConfig(){
                Config.trustIP.removeAllElements();
                //Config.clients.removeAllElements();
                Config.recv_queue.release();
                Config.send_queue.release();
                Config.service_id_queue.release();
                Config.subcode_queue.release();
                Config.log.log("Close the Config,System.exit ... ...");
                Config.log.close();
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -