import org.xml.sax.AttributeList; //导入方法依赖的package包/类
/**
* Initialisation routine called after handler creation
* with the element name and attributes. The attributes which
* this handler can deal with are: "default"
,
* "name"
, "id"
and "basedir"
.
*
* @param tag Name of the element which caused this handler
* to be created. Should not be null
.
* Ignored in this implementation.
* @param attrs Attributes of the element which caused this
* handler to be created. Must not be null
.
*
* @exception SAXParseException if an unexpected attribute is
* encountered or if the "default"
attribute
* is missing.
*/
public void init(String tag, AttributeList attrs) throws SAXParseException {
String def = null;
String name = null;
String id = null;
String baseDir = null;
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i);
String value = attrs.getValue(i);
if ("default".equals(key)) {
def = value;
} else if ("name".equals(key)) {
name = value;
} else if ("id".equals(key)) {
id = value;
} else if ("basedir".equals(key)) {
baseDir = value;
} else {
throw new SAXParseException(
"Unexpected attribute \"" + attrs.getName(i)
+ "\"", helperImpl.locator);
}
}
if (def != null && !def.isEmpty()) {
helperImpl.project.setDefault(def);
} else {
throw new BuildException("The default attribute is required");
}
if (name != null) {
helperImpl.project.setName(name);
helperImpl.project.addReference(name, helperImpl.project);
}
if (id != null) {
helperImpl.project.addReference(id, helperImpl.project);
}
if (helperImpl.project.getProperty("basedir") != null) {
helperImpl.project.setBasedir(helperImpl.project.getProperty("basedir"));
} else {
if (baseDir == null) {
helperImpl.project.setBasedir(helperImpl.buildFileParent.getAbsolutePath());
} else {
// check whether the user has specified an absolute path
if ((new File(baseDir)).isAbsolute()) {
helperImpl.project.setBasedir(baseDir);
} else {
File resolvedBaseDir = FILE_UTILS.resolveFile(helperImpl.buildFileParent,
baseDir);
helperImpl.project.setBaseDir(resolvedBaseDir);
}
}
}
helperImpl.project.addTarget("", helperImpl.implicitTarget);
}