方槍槍的java世界

          不要因為風雨飄落就停止了你的腳步,真正的得失就在你的心中。 做喜歡做的事,不輕言放棄!

          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 做強大的自己 閱讀(133) 評論(0)  編輯  收藏 所屬分類: Socket

          主站蜘蛛池模板: 巴里| 福安市| 南郑县| 柞水县| 疏附县| 温宿县| 吉首市| 大姚县| 山西省| 象州县| 苍南县| 湘潭县| 建始县| 平昌县| 巴南区| 类乌齐县| 伊吾县| 都安| 民勤县| 瓮安县| 毕节市| 新宁县| 永吉县| 闽侯县| 福海县| 安龙县| 江西省| 额敏县| 修水县| 锦屏县| 丰县| 孝昌县| 治多县| 抚远县| 河南省| 勐海县| 长武县| 丁青县| 宾川县| 盐源县| 万山特区|