方槍槍的java世界

          不要因?yàn)轱L(fēng)雨飄落就停止了你的腳步,真正的得失就在你的心中。 做喜歡做的事,不輕言放棄!

          02 一個簡單的HttpServer_Processor_ProcessorImpl

          package com.tianhe.frm.http;

          public interface Processor
          {
              public byte[] process(String resource, char[] postData, String charset);
          }

          package com.tianhe.frm.http;

          import com.tianhe.frm.context.GlobalConfig;
          import com.tianhe.frm.utils.ObjectUtil;

          public class ProcessorImpl implements Processor
          {
             
              public byte[] process(String resource, char[] postData, String charset)
              {
                  Command command = createCommand(resource);
                 
                  byte[] resVal = command.execute(resource, postData, charset);
                 
                  return resVal;
              }
             
              private Command createCommand(String resource)
              {
                  String type = getCommandType(resource);
                 
                  String clazzName = GlobalConfig.getString("ProcessorImpl.command." + type + ".CLASS_NAME",
                          "com.tianhe.frm.http.CommandImpl");
                  Command command = (Command)ObjectUtil.createObject(clazzName);

                  return command;
              }
             
              private String getCommandType(String resource)
              {
                  String vsTemp = resource;
                  int index = resource.indexOf("?");
                  if (index > 0)
                  {
                      vsTemp = vsTemp.substring(0, index);
                      int index2 = vsTemp.lastIndexOf(".");
                      vsTemp = vsTemp.substring(index2 + 1);
                  }
                  else
                  {
                      int index2 = vsTemp.lastIndexOf(".");
                      vsTemp = vsTemp.substring(index2 + 1);
                  }
                 
                  return vsTemp;
              }
             
              public static void main(String[] args)
              {
                  String type = null;
                 
                  {
                      type = new ProcessorImpl().getCommandType("example/aaa.cmd1");
                      System.out.println(type);
                  }
                 
                  {
                      type = new ProcessorImpl().getCommandType("example/aaa.cmd1?aaa.cmd=111");
                      System.out.println(type);
                  }
              }
             
          }

          posted on 2012-07-09 22:14 做強(qiáng)大的自己 閱讀(133) 評論(0)  編輯  收藏 所屬分類: Socket

          主站蜘蛛池模板: 陇川县| 长寿区| 铁力市| 绥阳县| 曲水县| 栾川县| 庆安县| 仁寿县| 时尚| 洛阳市| 渭南市| 历史| 普兰店市| 双峰县| 札达县| 柏乡县| 舞钢市| 洞口县| 赫章县| 清丰县| 新余市| 龙口市| 郎溪县| 巩留县| 浏阳市| 密山市| 桑日县| 上栗县| 乌拉特中旗| 光山县| 田阳县| 龙泉市| 安宁市| 商都县| 鹤山市| 楚雄市| 本溪| 海门市| 高唐县| 罗甸县| 南华县|