!DAO_CONFIG_ELEMENT.equals(rootname)) {
throw new IOException("Error while configuring DaoManager. The root tag of the DAO configuration XML " +
"document must be '" + DAO_CONFIG_ELEMENT + "'.");
}
//瑙f瀽绗竴灞傝妭鐐逛俊鎭?
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (CONTEXT_ELEMENT.equals(child.getNodeName())) {
// 瑙f瀽绗竴灞傝妭鐐逛腑context鑺傜偣鐨勪俊鎭紝棣栧厛鍒涘缓涓涓狣aoContext瀵硅薄锛岀劧鍚庡姞鍒癝tandardDaoManager瀵硅薄涓?
DaoContext daoContext = parseContext((Element) child, daoManager);
daoManager.addContext(daoContext);
} else if (PROPERTIES_ELEMENT.equals(child.getNodeName())) {
// 瑙f瀽绗竴灞傝妭鐐逛腑property鑺傜偣鐨勪俊鎭?
Properties attributes = parseAttributes(child);
if (attributes.containsKey("resource")) {
String resource = attributes.getProperty("resource");
if (properties == null) {
properties = Resources.getResourceAsProperties(resource);
} else {
Properties tempProps = Resources.getResourceAsProperties(resource);
tempProps.putAll(properties);
properties = tempProps;
}
} else if (attributes.containsKey("url")) {
String url = attributes.getProperty("url");
if (properties == null) {
properties = Resources.getUrlAsProperties(url);
} else {
Properties tempProps = Resources.getUrlAsProperties(url);
tempProps.putAll(properties);
properties = tempProps;
}
}
}
}
}
} catch (Exception e) {
throw new DaoException("Error while configuring DaoManager. Cause: " + e.toString(), e);
}
return daoManager;
}
public boolean isValidationEnabled() {
return validationEnabled;
}
public void setValidationEnabled(boolean validationEnabled) {
this.validationEnabled = validationEnabled;
}
//瑙f瀽绗竴灞傝妭鐐逛腑context鑺傜偣鐨勪俊鎭?
private DaoContext parseContext(Element contextElement, StandardDaoManager daoManager)
throws DaoException {
DaoContext daoContext = new DaoContext();
daoContext.setDaoManager(daoManager);
String id = contextElement.getAttribute("id");
if (id != null && id.length() > 0) {
daoContext.setId(id);
}
NodeList children = contextElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
// 瑙f瀽context鑺傜偣涓璽ransactionManager鑺傜偣鐨勪俊鎭?
if (TRANS_MGR_ELEMENT.equals(child.getNodeName())) {
DaoTransactionManager txMgr = parseTransactionManager((Element) child);
daoContext.setTransactionManager(txMgr);
} else if (DAO_ELEMENT.equals(child.getNodeName())) {
// 瑙f瀽context鑺傜偣涓璬ao鑺傜偣鐨勪俊鎭紝棣栧厛鍒涘缓涓涓狣ao瀵硅薄锛岀劧鍚庡姞鍒癉aoContext瀵硅薄涓?
DaoImpl daoImpl = parseDao((Element) child, daoManager, daoContext);
daoContext.addDao(daoImpl);
}
}
}
return daoContext;
}
//瑙f瀽context鑺傜偣涓璽ransactionManager鑺傜偣鐨勪俊鎭?
private DaoTransactionManager parseTransactionManager(Element transPoolElement)
throws DaoException {
DaoTransactionManager txMgr = null;
Properties attributes = parseAttributes(transPoolElement);
String implementation = attributes.getProperty("type");
implementation = resolveAlias(implementation);
//鏍规嵁瀛楃鍚嶇О鍔ㄦ佸疄渚嬪寲涓涓狣aoTransactionManager瀵硅薄
try {
txMgr = (DaoTransactionManager) Resources.classForName(implementation).newInstance();
} catch (Exception e) {
throw new DaoException("Error while configuring DaoManager. Cause: " + e.toString(), e);
}
Properties props = properties;
if (props == null) {
props = parsePropertyElements(transPoolElement);
} else {
props.putAll(parsePropertyElements(transPoolElement));
}
//鍒濆鍖朌aoT