FileDocCategorySizeDatePackage
Mapper.javaAPI DocApache Ant 1.709574Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.types

Mapper

public class Mapper extends DataType implements Cloneable
Element to define a FileNameMapper.

Fields Summary
protected MapperType
type
protected String
classname
protected Path
classpath
protected String
from
protected String
to
private org.apache.tools.ant.util.ContainerMapper
container
Constructors Summary
public Mapper(org.apache.tools.ant.Project p)
Construct a new Mapper element.

param
p the owning Ant Project.


                      
       
        setProject(p);
    
Methods Summary
public voidadd(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
Add a nested FileNameMapper.

param
fileNameMapper the FileNameMapper to add.

        if (isReference()) {
            throw noChildrenAllowed();
        }
        if (container == null) {
            if (type == null && classname == null) {
                container = new CompositeMapper();
            } else {
                FileNameMapper m = getImplementation();
                if (m instanceof ContainerMapper) {
                    container = (ContainerMapper) m;
                } else {
                    throw new BuildException(String.valueOf(m)
                        + " mapper implementation does not support nested mappers!");
                }
            }
        }
        container.add(fileNameMapper);
    
public voidaddConfigured(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
Cannot mix add and addconfigured in same type, so provide this to override the add method.

param
fileNameMapper the FileNameMapper to add.

        add(fileNameMapper);
    
public voidaddConfiguredMapper(org.apache.tools.ant.types.Mapper mapper)
Add a Mapper

param
mapper the mapper to add

        add(mapper.getImplementation());
    
public PathcreateClasspath()
Set the classpath to load the FileNameMapper through (nested element).

return
a path object to be configured

        if (isReference()) {
            throw noChildrenAllowed();
        }
        if (this.classpath == null) {
            this.classpath = new Path(getProject());
        }
        return this.classpath.createPath();
    
public org.apache.tools.ant.util.FileNameMappergetImplementation()
Returns a fully configured FileNameMapper implementation.

return
a FileNameMapper object to be configured
throws
BuildException on error

        if (isReference()) {
            return getRef().getImplementation();
        }

        if (type == null && classname == null && container == null) {
            throw new BuildException(
                "nested mapper or "
                + "one of the attributes type or classname is required");
        }

        if (container != null) {
            return container;
        }

        if (type != null && classname != null) {
            throw new BuildException(
                "must not specify both type and classname attribute");
        }

        try {
            FileNameMapper m
                = (FileNameMapper) (getImplementationClass().newInstance());
            final Project p = getProject();
            if (p != null) {
                p.setProjectReference(m);
            }
            m.setFrom(from);
            m.setTo(to);

            return m;
        } catch (BuildException be) {
            throw be;
        } catch (Throwable t) {
            throw new BuildException(t);
        }
    
protected java.lang.ClassgetImplementationClass()
Gets the Class object associated with the mapper implementation.

return
Class.
throws
ClassNotFoundException if the class cannot be found


        String cName = this.classname;
        if (type != null) {
            cName = type.getImplementation();
        }

        ClassLoader loader = (classpath == null)
            ? getClass().getClassLoader()
            : getProject().createClassLoader(classpath);

        return Class.forName(cName, true, loader);
    
protected org.apache.tools.ant.types.MappergetRef()
Performs the check for circular references and returns the referenced Mapper.

return
the referenced Mapper

        return (Mapper) getCheckedRef();
    
public voidsetClassname(java.lang.String classname)
Set the class name of the FileNameMapper to use.

param
classname the name of the class

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.classname = classname;
    
public voidsetClasspath(Path classpath)
Set the classpath to load the FileNameMapper through (attribute).

param
classpath the classpath

        if (isReference()) {
            throw tooManyAttributes();
        }
        if (this.classpath == null) {
            this.classpath = classpath;
        } else {
            this.classpath.append(classpath);
        }
    
public voidsetClasspathRef(Reference ref)
Set the classpath to load the FileNameMapper through via reference (attribute).

param
ref the reference to the FileNameMapper

        if (isReference()) {
            throw tooManyAttributes();
        }
        createClasspath().setRefid(ref);
    
public voidsetFrom(java.lang.String from)
Set the argument to FileNameMapper.setFrom

param
from the from attribute to pass to the FileNameMapper

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.from = from;
    
public voidsetRefid(Reference r)
Make this Mapper instance a reference to another Mapper.

You must not set any other attribute if you make it a reference.

param
r the reference to another mapper
throws
BuildException if other attributes are set

        if (type != null || from != null || to != null) {
            throw tooManyAttributes();
        }
        super.setRefid(r);
    
public voidsetTo(java.lang.String to)
Set the argument to FileNameMapper.setTo

param
to the to attribute to pass to the FileNameMapper

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.to = to;
    
public voidsetType(org.apache.tools.ant.types.Mapper$MapperType type)
Set the type of FileNameMapper to use.

param
type the MapperType enumerated attribute.

        if (isReference()) {
            throw tooManyAttributes();
        }
        this.type = type;