@@ -1,7 +1,7 @@
/*
/*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
@@ -99,42 +99,81 @@ import org.apache.tools.ant.util.regexp.RegexpFactory;
public class RegularExpression extends DataType {
public class RegularExpression extends DataType {
/** Name of this data type */
/** Name of this data type */
public static final String DATA_TYPE_NAME = "regexp";
public static final String DATA_TYPE_NAME = "regexp";
private boolean alreadyInit = false;
// The regular expression factory
// The regular expression factory
private static final RegexpFactory factory = new RegexpFactory();
private static final RegexpFactory FACTORY = new RegexpFactory();
private Regexp regexp;
private Regexp regexp = null;
// temporary variable
private String myPattern;
private boolean setPatternPending = false;
/**
* default constructor
*/
public RegularExpression() {
public RegularExpression() {
this.regexp = factory.newRegexp();
}
}
private void init(Project p) {
if (!alreadyInit) {
this.regexp = FACTORY.newRegexp(p);
alreadyInit = true;
}
}
private void setPattern() {
if (setPatternPending) {
regexp.setPattern(myPattern);
setPatternPending = false;
}
}
/**
* sets the regular expression pattern
* @param pattern regular expression pattern
*/
public void setPattern(String pattern) {
public void setPattern(String pattern) {
this.regexp.setPattern(pattern);
if (regexp == null) {
myPattern = pattern;
setPatternPending = true;
} else {
regexp.setPattern(pattern);
}
}
}
/***
/***
* Gets the pattern string for this RegularExpression in the
* Gets the pattern string for this RegularExpression in the
* given project.
* given project.
* @param p project
* @return pattern
*/
*/
public String getPattern(Project p) {
public String getPattern(Project p) {
init(p);
if (isReference()) {
if (isReference()) {
return getRef(p).getPattern(p);
return getRef(p).getPattern(p);
}
}
setPattern();
return regexp.getPattern();
return regexp.getPattern();
}
}
/**
* provides a reference to the Regexp contained in this
* @param p project
* @return Regexp instance associated with this RegularExpression instance
*/
public Regexp getRegexp(Project p) {
public Regexp getRegexp(Project p) {
init(p);
if (isReference()) {
if (isReference()) {
return getRef(p).getRegexp(p);
return getRef(p).getRegexp(p);
}
}
setPattern();
return this.regexp;
return this.regexp;
}
}
/***
/***
* Get the RegularExpression this reference refers to in
* Get the RegularExpression this reference refers to in
* the given project. Check for circular references too
* the given project. Check for circular references too
* @param p project
* @return resolved RegularExpression instance
*/
*/
public RegularExpression getRef(Project p) {
public RegularExpression getRef(Project p) {
if (!isChecked()) {
if (!isChecked()) {
@@ -147,7 +186,7 @@ public class RegularExpression extends DataType {
Object o = getRefid().getReferencedObject(p);
Object o = getRefid().getReferencedObject(p);
if (!(o instanceof RegularExpression)) {
if (!(o instanceof RegularExpression)) {
String msg = getRefid().getRefId() + " doesn\'t denote a "
String msg = getRefid().getRefId() + " doesn\'t denote a "
+ DATA_TYPE_NAME;
+ DATA_TYPE_NAME;
throw new BuildException(msg);
throw new BuildException(msg);
} else {
} else {
return (RegularExpression) o;
return (RegularExpression) o;