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

          主站蜘蛛池模板: 南丰县| 观塘区| 黑河市| 含山县| 偃师市| 沁水县| 岚皋县| 齐齐哈尔市| 治县。| 东辽县| 南溪县| 乌恰县| 康保县| 武宁县| 巫山县| 专栏| 漾濞| 文成县| 嵊泗县| 枝江市| 织金县| 孟津县| 宝清县| 河曲县| 屏东县| 安岳县| 福鼎市| 江城| 灵山县| 漯河市| 太和县| 达日县| 南安市| 金秀| 盐源县| 石泉县| 镇赉县| 光山县| 九寨沟县| 于田县| 专栏|