<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    rochoc

    關于java、cobol、zos

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      6 Posts :: 1 Stories :: 21 Comments :: 0 Trackbacks
    CS結構軟件自動升級實現(三)

    Config.java處理配置文件:
      1/********************************************************************
      2 * 項目名稱                :rochoc<p>
      3 * 包名稱                  :com.rochoc.autoupdate<p>
      4 * 文件名稱                :Config.java<p>
      5 * 編寫者                 :kfzx-luoc<p>
      6 * 編寫日期                :2008-12-22<p>
      7 * 程序功能(類)描述    :<p>
      8 * 用于更新的配置文件讀取對像
      9 * 程序變更日期            :
     10 * 變更作者                :
     11 * 變更說明                :
     12********************************************************************/

     13package com.rochoc.autoupdate;
     14
     15import java.io.File;
     16import java.text.SimpleDateFormat;
     17import java.util.Date;
     18import java.util.List;
     19
     20import org.dom4j.Document;
     21import org.dom4j.Element;
     22import org.dom4j.io.SAXReader;
     23
     24
     25/**
     26 * @author kfzx-luoc
     27 *
     28 * TODO To change the template for this generated type comment go to
     29 * Window - Preferences - Java - Code Style - Code Templates
     30 */

     31public class Config
     32{
     33    public static String cfgFile = ".\\config\\autoupdate.xml";
     34    private static Config config = null;
     35    /** xml的document*/
     36    private Document doc = null;
     37    public static Config getInstance()
     38    {
     39        if(config==null)
     40        {
     41            config = new Config();
     42        }

     43        return config;
     44    }

     45    
     46    private Config()
     47    {
     48        try
     49        {
     50           SAXReader reader = new SAXReader();
     51           doc = reader.read(cfgFile);
     52        }
    catch(Exception e)
     53        {
     54            e.printStackTrace();
     55        }

     56    }

     57    public void refresh()
     58    {
     59        config = new Config();
     60    }

     61    public String getVerstion()
     62    {
     63        if(config==null)
     64        {
     65            return "";
     66        }

     67        List lst = doc.selectNodes("Info/Version");
     68        Element el = (Element)lst.get(0);
     69        return el.getText();
     70    }

     71    public String getServerIp()
     72    {
     73        if(config==null)
     74        {
     75            return "";
     76        }

     77        List lst = doc.selectNodes("Info/UpdateServer/Ip");
     78        Element el = (Element)lst.get(0);
     79        return el.getText();
     80    }

     81    public UpdFile [] getFiles()
     82    {
     83        if(config==null)
     84        {
     85            return null;
     86        }

     87        List file = doc.selectNodes("Info/Files");
     88        List lst = ((Element)file.get(0)).elements();
     89        if(lst.size()==0)
     90        {
     91            return null;
     92        }

     93        UpdFile files[] = new UpdFile[lst.size()];
     94        for(int i=0;i<lst.size();i++)
     95        {
     96            Element el = (Element)lst.get(i);
     97            List childs = el.elements();
     98            Element name = (Element)childs.get(0);//Name
     99            Element path = (Element)childs.get(1);//Path
    100            Element ver = (Element)childs.get(2);//Version
    101            files[i] = new UpdFile(name.getText());
    102            if("File".equals(el.getName()))
    103            {
    104               files[i].setType(0);//文件
    105            }
    else
    106            {
    107                files[i].setType(1);//目錄
    108            }

    109            files[i].setPath(path.getText());
    110            files[i].setVersion(ver.getText());
    111        }

    112        return files;
    113    }

    114    public String getServerPort()
    115    {
    116        if(config==null)
    117        {
    118            return "";
    119        }

    120        List lst = doc.selectNodes("Info/UpdateServer/Port");
    121        Element el = (Element)lst.get(0);
    122        return el.getText();
    123    }

    124    public static void print(String msg)
    125    {
    126        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss->>" );
    127        String str = sdf.format( new Date());
    128        System.out.println(str+msg);
    129    }

    130    public static void main(String args[])
    131    {
    132        Config cfg = Config.getInstance();        
    133        UpdFile files[] = cfg.getFiles();
    134        for(int i=0;i<files.length;i++)
    135        {
    136            System.out.println(files[i]);
    137        }

    138        Config.print("test");
    139    }

    140    /**
    141     * 格式化路徑,增加其尾部的目錄分隔符
    142     *
    143     * @param p 要格式化的目錄字符串
    144     */

    145    public static String formatPath(String p)
    146    {
    147        if (!p.endsWith(File.separator))
    148            return (p + File.separator);
    149        return p;
    150    }

    151
    152    /**
    153     * 格式化路徑,去除其尾部的目錄分隔符
    154     *
    155     * @param p 要格式化的目錄字符串
    156     */

    157    public static String unformatPath(String p)
    158    {
    159        if (p.endsWith(File.separator))
    160            return (p.substring(0, p.length()-1));
    161        return p;
    162    }

    163    public static byte[] getCmd(String cmd)
    164    {
    165        //第一位用于標識是命令,后面8位為命令名
    166        byte cmdb [] = new byte[9];
    167        cmdb[0= AUPD.CMD_DATA_SECT;
    168        byte [] tmp = cmd.getBytes();
    169        if(tmp.length!=8)
    170        {
    171            Config.print("命令有誤:"+cmd+"<<");
    172            return null;
    173        }

    174        for(int i=0;i<8;i++)
    175        {
    176            cmdb[i+1= tmp[i];
    177        }

    178        return cmdb;
    179    }

    180    public static String parseCmd(byte cmd[])
    181    {
    182        return new String(cmd,0,8);
    183    }

    184    public static byte [] getLen(int len)
    185    {
    186        String slen = String.valueOf(len);
    187        while(slen.length()<4)
    188        {
    189            slen = "0"+slen;
    190        }

    191        return slen.getBytes();
    192    }

    193    public static void copyArray(byte objary[], byte souary[], int o_begin,
    194            int s_begin, int len)
    195    {
    196        for (int i = 0; i < len; i++)
    197        {
    198            objary[o_begin + i] = souary[s_begin + i];
    199        }

    200    }

    201}

    UpdFile.java:這個類本來是想作為對象直接在服務端和客戶端之間傳遞的,但后來沒有采用,因此在本實現中用處不大

     

      1/********************************************************************
      2 * 項目名稱                :rochoc<p>
      3 * 包名稱                  :com.rochoc.autoupdate<p>
      4 * 文件名稱                :UpdFile.java<p>
      5 * 編寫者                 :kfzx-luoc<p>
      6 * 編寫日期                :2008-12-23<p>
      7 * 程序功能(類)描述    :<p>
      8 * 版本文件對像
      9 * 程序變更日期            :
     10 * 變更作者                :
     11 * 變更說明                :
     12********************************************************************/

     13package com.rochoc.autoupdate;
     14
     15import java.io.Serializable;
     16
     17/**
     18 * @author kfzx-luoc
     19 *
     20 * TODO To change the template for this generated type comment go to
     21 * Window - Preferences - Java - Code Style - Code Templates
     22 */

     23public class UpdFile implements Serializable
     24{
     25    private String name = "";//名稱
     26    private String path = "";//路徑
     27    private int type = 0;//類型 0.文件 1.目錄
     28    private String version = "";//版本號
     29    
     30    public UpdFile()
     31    {
     32        super();
     33    }

     34    public UpdFile(String name)
     35    {
     36        this();
     37        this.name = name;
     38    }

     39    public UpdFile(String name,String path,int type,String version)
     40    {
     41        this(name);
     42        this.path = path;
     43        this.type = type;
     44        this.version = version;
     45    }

     46    /**
     47     * @return Returns the name.
     48     */

     49    public String getName()
     50    {
     51        return name;
     52    }

     53    /**
     54     * @param name The name to set.
     55     */

     56    public void setName(String name)
     57    {
     58        this.name = name;
     59    }

     60    /**
     61     * @return Returns the path.
     62     */

     63    public String getPath()
     64    {
     65        return path;
     66    }

     67    /**
     68     * @param path The path to set.
     69     */

     70    public void setPath(String path)
     71    {
     72        this.path = path;
     73    }

     74    /**
     75     * @return Returns the type.
     76     */

     77    public int getType()
     78    {
     79        return type;
     80    }

     81    /**
     82     * @param type The type to set.
     83     */

     84    public void setType(int type)
     85    {
     86        this.type = type;
     87    }

     88    /**
     89     * @return Returns the version.
     90     */

     91    public String getVersion()
     92    {
     93        return version;
     94    }

     95    /**
     96     * @param version The version to set.
     97     */

     98    public void setVersion(String version)
     99    {
    100        this.version = version;
    101    }

    102    public String toString()
    103    {
    104        return "Name:"+getName()+",Path:"+getPath()
    105        +",Type:"+getType()+",Version:"+getVersion();
    106    }

    107}

    《CS結構軟件自動升級實現》已經全部寫完,這是本人原創,如果需要轉貼請注明出處,目前我也只發布到bolgjava上,謝謝。
    posted on 2009-01-09 21:18 rochoc 閱讀(2032) 評論(2)  編輯  收藏

    Feedback

    # re: CS結構軟件自動升級實現(四) 2009-01-09 23:39 yz
    支持原創,多寫  回復  更多評論
      

    # re: CS結構軟件自動升級實現(四) 2009-01-10 09:41 日月雨林@gmail.com
    強烈支持原創! 你的文章讓我學到了好多的東西!雖然還沒有看完,先收藏了!
    謝謝你!  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久精品国产亚洲av水果派| 免费看香港一级毛片| 中文无码成人免费视频在线观看| 亚洲区视频在线观看| 亚洲国产日韩女人aaaaaa毛片在线| 亚洲男女性高爱潮网站| 亚洲女人影院想要爱| 亚洲最新黄色网址| 精品亚洲国产成人| 亚洲一日韩欧美中文字幕在线| 久久狠狠爱亚洲综合影院| 亚洲影院天堂中文av色| 国产亚洲成在线播放va| 日日狠狠久久偷偷色综合免费| 一区二区三区免费在线视频 | 亚洲性一级理论片在线观看| 亚洲国产品综合人成综合网站| 亚洲乱码在线播放| 亚洲国产高清国产拍精品| 国产av无码专区亚洲av毛片搜| 四虎影视在线看免费观看| 国产又黄又爽又大的免费视频| 久久九九AV免费精品| 日本免费xxxx色视频| 四虎成人精品一区二区免费网站| 免费国产真实迷j在线观看| 亚洲免费视频一区二区三区| 亚洲综合色自拍一区| 亚洲人成网站在线播放影院在线 | a级亚洲片精品久久久久久久| 亚洲精品无码久久久久| 亚洲高清无在码在线电影不卡| 中文字幕亚洲男人的天堂网络 | 亚洲成在人天堂在线| 精品亚洲成A人无码成A在线观看| 国产99久久亚洲综合精品| 国产一级婬片A视频免费观看| 1区2区3区产品乱码免费| 国产精品色午夜免费视频| 亚洲日韩精品A∨片无码| 亚洲人成高清在线播放|