方枪枪的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 做强大的自己 阅读(125) 评论(0)  编辑  收藏 所属分类: Socket


只有注册用户登录后才能发表评论。


网站导航: