throws SAXParseException {
String name = null;
String depends = "";
Project project = context.getProject();
Target target = new Target();
target.setProject(project);
context.addTarget(target);
for (int i = 0; i < attrs.getLength(); i++) {
String attrUri = attrs.getURI(i);
if (attrUri != null
&& !attrUri.equals("")
&& !attrUri.equals(uri)) {
continue; // Ignore attributes from unknown uris
}
String key = attrs.getLocalName(i);
String value = attrs.getValue(i);
if (key.equals("name")) {
name = value;
if ("".equals(name)) {
throw new BuildException("name attribute must "
+ "not be empty");
}
} else if (key.equals("depends")) {
depends = value;
} else if (key.equals("if")) {
target.setIf(value);
} else if (key.equals("unless")) {
target.setUnless(value);
} else if (key.equals("id")) {
if (value != null && !value.equals("")) {
context.getProject().addReference(value, target);
}
} else if (key.equals("description")) {
target.setDescription(value);
} else {
throw new SAXParseException("Unexpected attribute \""
+ key + "\"", context.getLocator());
}
}
if (name == null) {
throw new SAXParseException("target element appears without "
+ "a name attribute", context.getLocator());
}
Hashtable currentTargets = project.getTargets();
// If the name has already been defined ( import for example )
if (currentTargets.containsKey(name)) {
// Alter the name.
if (context.getCurrentProjectName() != null) {
String newName = context.getCurrentProjectName()
+ "." + name;
project.log("Already defined in main or a previous import, "
+ "define " + name + " as " + newName,
Project.MSG_VERBOSE);
name = newName;
} else {
project.log("Already defined in main or a previous import, "
+ "ignore " + name, Project.MSG_VERBOSE);
name = null;
}
}
if (name != null) {
target.setName(name);
project.addOrReplaceTarget(name, target);
}
// take care of dependencies
if (depends.length() > 0) {
target.setDepends(depends);
}
}