diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
index be3ff5e98..9df1cdb42 100644
--- a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
+++ b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
@@ -18,7 +18,9 @@
package org.apache.tools.ant.util.regexp;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
/***
@@ -52,9 +54,9 @@ public class RegexpFactory extends RegexpMatcherFactory {
public Regexp newRegexp(Project p) throws BuildException {
String systemDefault = null;
if (p == null) {
- systemDefault = System.getProperty("ant.regexp.regexpimpl");
+ systemDefault = System.getProperty(MagicNames.REGEXP_IMPL);
} else {
- systemDefault = p.getProperty("ant.regexp.regexpimpl");
+ systemDefault = p.getProperty(MagicNames.REGEXP_IMPL);
}
if (systemDefault != null) {
@@ -85,10 +87,8 @@ public class RegexpFactory extends RegexpMatcherFactory {
} catch (BuildException be) {
cause = orCause(cause, be, true);
}
-
- throw new BuildException(
- "No supported regular expression matcher found"
- + (cause != null ? ": " + cause : ""), cause);
+ throw new BuildException("No supported regular expression matcher found"
+ + (cause != null ? ": " + cause : ""), cause);
}
/**
@@ -101,15 +101,9 @@ public class RegexpFactory extends RegexpMatcherFactory {
*
* @see RegexpMatcherFactory#createInstance(String)
*/
- protected Regexp createRegexpInstance(String classname)
- throws BuildException {
-
- RegexpMatcher m = createInstance(classname);
- if (m instanceof Regexp) {
- return (Regexp) m;
- } else {
- throw new BuildException(classname + " doesn't implement the Regexp interface");
- }
+ protected Regexp createRegexpInstance(String classname) throws BuildException {
+ return (Regexp) ClasspathUtils.newInstance(classname, RegexpFactory.class.getClassLoader(),
+ Regexp.class);
}
}
diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
index 6549b06b9..7d9569537 100644
--- a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
+++ b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
@@ -15,7 +15,6 @@
* limitations under the License.
*
*/
-
package org.apache.tools.ant.util.regexp;
import org.apache.tools.ant.Project;
@@ -25,14 +24,13 @@ import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
/**
- * Simple Factory Class that produces an implementation of
- * RegexpMatcher based on the system property
- * ant.regexp.regexpimpl
and the classes
- * available.
- *
- *
In a more general framework this class would be abstract and - * have a static newInstance method.
- * + * Simple Factory Class that produces an implementation of RegexpMatcher based on the system + * propertyant.regexp.regexpimpl
and the classes available.
+ *
+ * + * In a more general framework this class would be abstract and have a static newInstance method. + *
+ * */ public class RegexpMatcherFactory { @@ -56,8 +54,7 @@ public class RegexpMatcherFactory { * @return the matcher * @throws BuildException on error */ - public RegexpMatcher newRegexpMatcher(Project p) - throws BuildException { + public RegexpMatcher newRegexpMatcher(Project p) throws BuildException { String systemDefault = null; if (p == null) { systemDefault = System.getProperty(MagicNames.REGEXP_IMPL); @@ -93,11 +90,9 @@ public class RegexpMatcherFactory { } catch (BuildException be) { cause = orCause(cause, be, true); } - - throw new BuildException( - "No supported regular expression matcher found" - + (cause != null ? ": " + cause : ""), cause); - } + throw new BuildException("No supported regular expression matcher found" + + (cause != null ? ": " + cause : ""), cause); + } static Throwable orCause(Throwable deflt, BuildException be, boolean ignoreCnfe) { if (deflt != null) { @@ -114,10 +109,9 @@ public class RegexpMatcherFactory { * @return aRegexpMatcher
value
* @exception BuildException if an error occurs
*/
- protected RegexpMatcher createInstance(String className)
- throws BuildException {
- return (RegexpMatcher) ClasspathUtils.newInstance(className,
- RegexpMatcherFactory.class.getClassLoader(), RegexpMatcher.class);
+ protected RegexpMatcher createInstance(String className) throws BuildException {
+ return (RegexpMatcher) ClasspathUtils.newInstance(className, RegexpMatcherFactory.class
+ .getClassLoader(), RegexpMatcher.class);
}
/**
@@ -143,7 +137,7 @@ public class RegexpMatcherFactory {
try {
// The factory throws a BuildException if no usable matcher
// cant be instantiated. We dont need the matcher itself here.
- (new RegexpMatcherFactory()).newRegexpMatcher(project);
+ new RegexpMatcherFactory().newRegexpMatcher(project);
return true;
} catch (Throwable ex) {
return false;