FileDocCategorySizeDatePackage
MacroDef.javaAPI DocApache Ant 1.7024122Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

MacroDef

public class MacroDef extends AntlibDefinition
Describe class MacroDef here.
since
Ant 1.6

Fields Summary
private NestedSequential
nestedSequential
private String
name
private boolean
backTrace
private List
attributes
private Map
elements
private String
textName
private Text
text
private boolean
hasImplicitElement
Constructors Summary
Methods Summary
public voidaddConfiguredAttribute(org.apache.tools.ant.taskdefs.MacroDef$Attribute attribute)
Add an attribute element.

param
attribute an attribute nested element.

        if (attribute.getName() == null) {
            throw new BuildException(
                "the attribute nested element needed a \"name\" attribute");
        }
        if (attribute.getName().equals(textName)) {
            throw new BuildException(
                "the name \"" + attribute.getName()
                + "\" has already been used by the text element");
        }
        for (int i = 0; i < attributes.size(); ++i) {
            Attribute att = (Attribute) attributes.get(i);
            if (att.getName().equals(attribute.getName())) {
                throw new BuildException(
                    "the name \"" + attribute.getName()
                        + "\" has already been used in "
                        + "another attribute element");
            }
        }
        attributes.add(attribute);
    
public voidaddConfiguredElement(org.apache.tools.ant.taskdefs.MacroDef$TemplateElement element)
Add an element element.

param
element an element nested element.

        if (element.getName() == null) {
            throw new BuildException(
                "the element nested element needed a \"name\" attribute");
        }
        if (elements.get(element.getName()) != null) {
            throw new BuildException(
                "the element " + element.getName()
                + " has already been specified");
        }
        if (hasImplicitElement
            || (element.isImplicit() && elements.size() != 0)) {
            throw new BuildException(
                "Only one element allowed when using implicit elements");
        }
        hasImplicitElement = element.isImplicit();
        elements.put(element.getName(), element);
    
public voidaddConfiguredText(org.apache.tools.ant.taskdefs.MacroDef$Text text)
Add the text element.

param
text the nested text element to add
since
ant 1.6.1

        if (this.text != null) {
            throw new BuildException(
                "Only one nested text element allowed");
        }
        if (text.getName() == null) {
            throw new BuildException(
                "the text nested element needed a \"name\" attribute");
        }
        // Check if used by attributes
        for (Iterator i = attributes.iterator(); i.hasNext();) {
            Attribute attribute = (Attribute) i.next();
            if (text.getName().equals(attribute.getName())) {
                throw new BuildException(
                    "the name \"" + text.getName()
                    + "\" is already used as an attribute");
            }
        }
        this.text = text;
        this.textName = text.getName();
    
public org.apache.tools.ant.taskdefs.MacroDef$NestedSequentialcreateSequential()
This is the sequential nested element of the macrodef.

return
a sequential element to be configured.

        if (this.nestedSequential != null) {
            throw new BuildException("Only one sequential allowed");
        }
        this.nestedSequential = new NestedSequential();
        return this.nestedSequential;
    
public voidexecute()
Create a new ant type based on the embedded tasks and types.

        if (nestedSequential == null) {
            throw new BuildException("Missing sequential element");
        }
        if (name == null) {
            throw new BuildException("Name not specified");
        }

        name = ProjectHelper.genComponentName(getURI(), name);

        MyAntTypeDefinition def = new MyAntTypeDefinition(this);
        def.setName(name);
        def.setClass(MacroInstance.class);

        ComponentHelper helper = ComponentHelper.getComponentHelper(
            getProject());

        helper.addDataTypeDefinition(def);
        log("creating macro  " + name, Project.MSG_VERBOSE);
    
public java.util.ListgetAttributes()
Gets this macro's attribute (and define?) list.

return
the nested Attributes

        return attributes;
    
public booleangetBackTrace()

return
the backTrace attribute.
since
ant 1.7

        return backTrace;
    
public java.util.MapgetElements()
Gets this macro's elements.

return
the map nested elements, keyed by element name, with {@link TemplateElement} values.

        return elements;
    
public org.apache.tools.ant.UnknownElementgetNestedTask()
Convert the nested sequential to an unknown element

return
the nested sequential as an unknown element.

        UnknownElement ret = new UnknownElement("sequential");
        ret.setTaskName("sequential");
        ret.setNamespace("");
        ret.setQName("sequential");
        new RuntimeConfigurable(ret, "sequential");
        for (int i = 0; i < nestedSequential.getNested().size(); ++i) {
            UnknownElement e =
                (UnknownElement) nestedSequential.getNested().get(i);
            ret.addChild(e);
            ret.getWrapper().addChild(e.getWrapper());
        }
        return ret;
    
public org.apache.tools.ant.taskdefs.MacroDef$TextgetText()

return
the nested text element
since
ant 1.6.1

        return text;
    
private static booleanisValidName(java.lang.String name)
Check if a string is a valid name for an element or attribute.

param
name the string to check
return
true if the name consists of valid name characters

        if (name.length() == 0) {
            return false;
        }
        for (int i = 0; i < name.length(); ++i) {
            if (!isValidNameCharacter(name.charAt(i))) {
                return false;
            }
        }
        return true;
    
public static booleanisValidNameCharacter(char c)
Check if a character is a valid character for an element or attribute name.

param
c the character to check
return
true if the character is a letter or digit or '.' or '-' attribute name

        // ? is there an xml api for this ?
        return Character.isLetterOrDigit(c) || c == '." || c == '-";
    
private static intobjectHashCode(java.lang.Object o)

        if (o == null) {
            return 0;
        } else {
            return o.hashCode();
        }
    
public booleansameDefinition(java.lang.Object obj)
Equality method for this definition

param
obj another definition
return
true if the definitions are the same

        return sameOrSimilar(obj, true);
    
private booleansameOrSimilar(java.lang.Object obj, boolean same)
same or similar equality method for macrodef, ignores project and runtime info.

param
obj an Object value
param
same if true test for sameness, otherwise just similiar
return
a boolean value

        if (obj == this) {
            return true;
        }

        if (obj == null) {
            return false;
        }
        if (!obj.getClass().equals(getClass())) {
            return false;
        }
        MacroDef other = (MacroDef) obj;
        if (name == null) {
            return other.name == null;
        }
        if (!name.equals(other.name)) {
            return false;
        }
        // Allow two macro definitions with the same location
        // to be treated as similar - bugzilla 31215
        if (other.getLocation() != null
            && other.getLocation().equals(getLocation())
            && !same) {
            return true;
        }
        if (text == null) {
            if (other.text != null) {
                return false;
            }
        } else {
            if (!text.equals(other.text)) {
                return false;
            }
        }
        if (getURI() == null || getURI().equals("")
            || getURI().equals(ProjectHelper.ANT_CORE_URI)) {
            if (!(other.getURI() == null || other.getURI().equals("")
                  || other.getURI().equals(ProjectHelper.ANT_CORE_URI))) {
                return false;
            }
        } else {
            if (!getURI().equals(other.getURI())) {
                return false;
            }
        }

        if (!nestedSequential.similar(other.nestedSequential)) {
            return false;
        }
        if (!attributes.equals(other.attributes)) {
            return false;
        }
        if (!elements.equals(other.elements)) {
            return false;
        }
        return true;
    
public voidsetBackTrace(boolean backTrace)
Set the backTrace attribute.

param
backTrace if true and the macro instance generates an error, a backtrace of the location within the macro and call to the macro will be output. if false, only the location of the call to the macro will be shown. Default is true.
since
ant 1.7

        this.backTrace = backTrace;
    
public voidsetName(java.lang.String name)
Name of the definition

param
name the name of the definition


                    
         
        this.name = name;
    
public booleansimilar(java.lang.Object obj)
Similar method for this definition

param
obj another definition
return
true if the definitions are similar

        return sameOrSimilar(obj, false);