FileDocCategorySizeDatePackage
Antlib.javaAPI DocApache Ant 1.705200Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

Antlib

public class Antlib extends org.apache.tools.ant.Task implements org.apache.tools.ant.TaskContainer
Antlib task. It does not occur in an ant build file. It is the root element an antlib xml file.
since
Ant 1.6

Fields Summary
public static final String
TAG
The name of this task
private ClassLoader
classLoader
private String
uri
private List
tasks
Constructors Summary
Methods Summary
public voidaddTask(org.apache.tools.ant.Task nestedTask)
add a task to the list of tasks

param
nestedTask Nested task to execute in antlib

        tasks.add(nestedTask);
    
public static org.apache.tools.ant.taskdefs.AntlibcreateAntlib(org.apache.tools.ant.Project project, java.net.URL antlibUrl, java.lang.String uri)
Static method to read an ant lib definition from a url.

param
project the current project
param
antlibUrl the url to read the definitions from
param
uri the uri that the antlib is to be placed in
return
the ant lib task


                                                             
          
                                        
        // Check if we can contact the URL
        try {
            antlibUrl.openConnection().connect();
        } catch (IOException ex) {
            throw new BuildException(
                "Unable to find " + antlibUrl, ex);
        }
        ComponentHelper helper =
            ComponentHelper.getComponentHelper(project);
        helper.enterAntLib(uri);
        try {
            // Should be safe to parse
            ProjectHelper2 parser = new ProjectHelper2();
            UnknownElement ue =
                parser.parseUnknownElement(project, antlibUrl);
            // Check name is "antlib"
            if (!(ue.getTag().equals(TAG))) {
                throw new BuildException(
                    "Unexpected tag " + ue.getTag() + " expecting "
                    + TAG, ue.getLocation());
            }
            Antlib antlib = new Antlib();
            antlib.setProject(project);
            antlib.setLocation(ue.getLocation());
            antlib.setTaskName("antlib");
            antlib.init();
            ue.configure(antlib);
            return antlib;
        } finally {
            helper.exitAntLib();
        }
    
public voidexecute()
Execute the nested tasks, setting the classloader for any tasks that derive from Definer.

        for (Iterator i = tasks.iterator(); i.hasNext();) {
            UnknownElement ue = (UnknownElement) i.next();
            setLocation(ue.getLocation());
            ue.maybeConfigure();
            Object configuredObject = ue.getRealThing();
            if (configuredObject == null) {
                continue;
            }
            if (!(configuredObject instanceof AntlibDefinition)) {
                throw new BuildException(
                    "Invalid task in antlib " + ue.getTag()
                    + " " + configuredObject.getClass() + " does not "
                    + "extend org.apache.tools.ant.taskdefs.AntlibDefinition");
            }
            AntlibDefinition def = (AntlibDefinition) configuredObject;
            def.setURI(uri);
            def.setAntlibClassLoader(getClassLoader());
            def.init();
            def.execute();
        }
    
private java.lang.ClassLoadergetClassLoader()

        if (classLoader == null) {
            classLoader = Antlib.class.getClassLoader();
        }
        return classLoader;
    
protected voidsetClassLoader(java.lang.ClassLoader classLoader)
Set the class loader for this antlib. This class loader is used for any tasks that derive from Definer.

param
classLoader the class loader


                                 
        
        this.classLoader = classLoader;
    
protected voidsetURI(java.lang.String uri)
Set the URI for this antlib.

param
uri the namespace uri

        this.uri = uri;