summaryrefslogtreecommitdiff
path: root/src/main/org/apache/tools/ant/types/Mapper.java
diff options
context:
space:
mode:
authorStefan Bodewig <bodewig@apache.org>2000-11-30 14:20:19 +0000
committerStefan Bodewig <bodewig@apache.org>2000-11-30 14:20:19 +0000
commit47ba7d22e2e132bef06c232ee6b5ac4ec8fcbebd (patch)
treee09482eee21bc18a546feb5b38d0ef659bce0734 /src/main/org/apache/tools/ant/types/Mapper.java
parentd2d785c408ae380f80e33800ce63959f221576f9 (diff)
downloadant-47ba7d22e2e132bef06c232ee6b5ac4ec8fcbebd.tar.gz
Allow the user to specify a FileNameMapper by class name - and set the
classpath to load it from. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268278 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache/tools/ant/types/Mapper.java')
-rw-r--r--src/main/org/apache/tools/ant/types/Mapper.java76
1 files changed, 72 insertions, 4 deletions
diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java
index 5cd16e2d5..5b3716ff3 100644
--- a/src/main/org/apache/tools/ant/types/Mapper.java
+++ b/src/main/org/apache/tools/ant/types/Mapper.java
@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
@@ -54,6 +54,7 @@
package org.apache.tools.ant.types;
+import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.*;
@@ -86,6 +87,58 @@ public class Mapper extends DataType {
this.type = type;
}
+ protected String classname = null;
+
+ /**
+ * Set the class name of the FileNameMapper to use.
+ */
+ public void setClassname(String classname) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ this.classname = classname;
+ }
+
+ protected Path classpath = null;
+
+ /**
+ * Set the classpath to load the FileNameMapper through (attribute).
+ */
+ public void setClasspath(Path classpath) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ if (this.classpath == null) {
+ this.classpath = classpath;
+ } else {
+ this.classpath.append(classpath);
+ }
+ }
+
+ /**
+ * Set the classpath to load the FileNameMapper through (nested element).
+ */
+ public Path createClasspath() {
+ if (isReference()) {
+ throw noChildrenAllowed();
+ }
+ if (this.classpath == null) {
+ this.classpath = new Path(p);
+ }
+ return this.classpath.createPath();
+ }
+
+ /**
+ * Set the classpath to load the FileNameMapper through via
+ * reference (attribute).
+ */
+ public void setClasspathRef(Reference r) {
+ if (isReference()) {
+ throw tooManyAttributes();
+ }
+ createClasspath().setRefid(r);
+ }
+
protected String from = null;
/**
@@ -131,12 +184,27 @@ public class Mapper extends DataType {
return getRef().getImplementation();
}
- if (type == null) {
- throw new BuildException("type attribute is required");
+ if (type == null && classname == null) {
+ throw new BuildException("one of the attributes type or classname is required");
+ }
+
+ if (type != null && classname != null) {
+ throw new BuildException("must not specify both type and classname attribute");
}
try {
- Class c = Class.forName(type.getImplementation());
+ if (type != null) {
+ classname = type.getImplementation();
+ }
+
+ Class c = null;
+ if (classpath == null) {
+ c = Class.forName(classname);
+ } else {
+ AntClassLoader al = new AntClassLoader(p, classpath);
+ c = al.loadClass(classname);
+ }
+
FileNameMapper m = (FileNameMapper) c.newInstance();
m.setFrom(from);
m.setTo(to);