ProcessorInfo.java :  » Scripting » tinyappserver » cn » aprilsoft » TinyAppServer » processor » Java Open Source

Java Open Source » Scripting » tinyappserver 
tinyappserver » cn » aprilsoft » TinyAppServer » processor » ProcessorInfo.java
package cn.aprilsoft.TinyAppServer.processor;

import java.util.regex.Pattern;

public class ProcessorInfo {

    private String    filter;
    private Pattern   pattern;
    private Processor processor;

    public ProcessorInfo(String filter, Processor processor) {
        checkFitler(filter);
        this.filter = filter;
        this.processor = processor;
    }

    public String getFilter() {
        return filter;
    }

    synchronized public Pattern getPattern() {
        if (pattern == null) {
            String filterRegex = filter.replace(".", "\\.");
            filterRegex = filterRegex.replace("?", ".?");
            filterRegex = filterRegex.replace("*", ".*");
            filterRegex = filterRegex.replace("+", "\\+");
            filterRegex = filterRegex.replace("-", "\\-");
            filterRegex = filterRegex.replace("$", "\\$");
            filterRegex = filterRegex.replace("^", "\\^");
            filterRegex = filterRegex.replace("|", "\\|");
            filterRegex = filterRegex += "$";

            pattern = Pattern.compile(filterRegex);
        }
        return pattern;
    }

    public Processor getProcessor() {
        return processor;
    }

    private void checkFitler(String filter) {
        if (filter == null) {
            throw new NullPointerException();
        }
        String illegalChars = "\\";
        for (int i = 0; i < illegalChars.length(); i++) {
            char c = illegalChars.charAt(i);
            if (filter.indexOf(c) >= 0) {
                throw new IllegalArgumentException("Filter include illegal char(s).");
            }
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.