方槍槍的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

          主站蜘蛛池模板: 永嘉县| 县级市| 越西县| 塔城市| 中西区| 师宗县| 翁牛特旗| 靖边县| 万安县| 广河县| 庄浪县| 海淀区| 辛集市| 保亭| 锡林郭勒盟| 乳源| 刚察县| 永清县| 囊谦县| 盐源县| 双辽市| 嘉定区| 蛟河市| 卢龙县| 德格县| 黑山县| 广西| 修水县| 嘉峪关市| 竹溪县| 门头沟区| 蒙城县| 宁远县| 鄂尔多斯市| 米泉市| 颍上县| 东莞市| 大埔区| 沙湾县| 和田县| 泽库县|