FileDocCategorySizeDatePackage
RegexpFactory.javaAPI DocApache Ant 1.704051Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.util.regexp

RegexpFactory

public class RegexpFactory extends RegexpMatcherFactory
Regular expression factory, which will create Regexp objects. The actual implementation class depends on the System or Ant Property: ant.regexp.regexpimpl.

Fields Summary
Constructors Summary
public RegexpFactory()
Constructor for RegexpFactory

    
Methods Summary
protected RegexpcreateRegexpInstance(java.lang.String classname)
Wrapper over RegexpMatcherFactory.createInstance that ensures that we are dealing with a Regexp implementation.

param
classname the name of the class to use.
return
the instance.
throws
BuildException if there is a problem.
since
1.3
see
RegexpMatcherFactory#createInstance(String)


        RegexpMatcher m = createInstance(classname);
        if (m instanceof Regexp) {
            return (Regexp) m;
        } else {
            throw new BuildException(classname + " doesn't implement the Regexp interface");
        }
    
public RegexpnewRegexp()
Create a new regular expression matcher instance.

return
the matcher instance
throws
BuildException on error

        return (Regexp) newRegexp(null);
    
public RegexpnewRegexp(org.apache.tools.ant.Project p)
Create a new regular expression matcher instance.

param
p Project whose ant.regexp.regexpimpl property will be used.
return
the matcher instance
throws
BuildException on error

        String systemDefault = null;
        if (p == null) {
            systemDefault = System.getProperty("ant.regexp.regexpimpl");
        } else {
            systemDefault = p.getProperty("ant.regexp.regexpimpl");
        }

        if (systemDefault != null) {
            return createRegexpInstance(systemDefault);
            // XXX     should we silently catch possible exceptions and try to
            //         load a different implementation?
        }

        Throwable cause = null;

        try {
            testAvailability("java.util.regex.Matcher");
            return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp");
        } catch (BuildException be) {
            cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14);
        }

        try {
            testAvailability("org.apache.oro.text.regex.Pattern");
            return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp");
        } catch (BuildException be) {
            cause = orCause(cause, be, true);
        }

        try {
            testAvailability("org.apache.regexp.RE");
            return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp");
        } catch (BuildException be) {
            cause = orCause(cause, be, true);
        }

        throw new BuildException(
            "No supported regular expression matcher found"
            + (cause != null ? ": " + cause : ""), cause);