* @exception SAXParseException in case of error (not thrown in
* this implementation)
*/
public void onStartElement(String uri, String tag, String qname, Attributes attrs,
AntXMLContext context) throws SAXParseException {
RuntimeConfigurable parentWrapper = context.currentWrapper();
Object parent = null;
if (parentWrapper != null) {
parent = parentWrapper.getProxy();
}
/* UnknownElement is used for tasks and data types - with
delayed eval */
UnknownElement task = new UnknownElement(tag);
task.setProject(context.getProject());
task.setNamespace(uri);
task.setQName(qname);
task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));
task.setTaskName(qname);
Location location = new Location(context.getLocator().getSystemId(), context
.getLocator().getLineNumber(), context.getLocator().getColumnNumber());
task.setLocation(location);
task.setOwningTarget(context.getCurrentTarget());
if (parent != null) {
// Nested element
((UnknownElement) parent).addChild(task);
} else {
// Task included in a target ( including the default one ).
context.getCurrentTarget().addTask(task);
}
context.configureId(task, attrs);
// container.addTask(task);
// This is a nop in UE: task.init();
RuntimeConfigurable wrapper = new RuntimeConfigurable(task, task.getTaskName());
for (int i = 0; i < attrs.getLength(); i++) {
String name = attrs.getLocalName(i);
String attrUri = attrs.getURI(i);
if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
name = attrUri + ":" + attrs.getQName(i);
}
String value = attrs.getValue(i);
// PR: Hack for ant-type value
// an ant-type is a component name which can
// be namespaced, need to extract the name
// and convert from qualified name to uri/name
if (ANT_TYPE.equals(name)
|| (ANT_CORE_URI.equals(attrUri)
&& ANT_TYPE.equals(attrs.getLocalName(i)))) {
name = ANT_TYPE;
int index = value.indexOf(":");
if (index >= 0) {
String prefix = value.substring(0, index);
String mappedUri = context.getPrefixMapping(prefix);
if (mappedUri == null) {
throw new BuildException("Unable to find XML NS prefix \"" + prefix
+ "\"");
}
value = ProjectHelper.genComponentName(mappedUri, value
.substring(index + 1));
}
}
wrapper.setAttribute(name, value);
}
if (parentWrapper != null) {
parentWrapper.addChild(wrapper);
}
context.pushWrapper(wrapper);