org.nutz.ioc.aop.config.impl.XmlAopConfigration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nutz Show documentation
Show all versions of nutz Show documentation
Nutz, which is a collections of lightweight frameworks, each of them can be used independently
package org.nutz.ioc.aop.config.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.nutz.lang.Lang;
import org.nutz.resource.NutResource;
import org.nutz.resource.Scans;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
*
* 通过Xml配置文件判断需要拦截哪些方法
* @author wendal([email protected])
*
*/
public class XmlAopConfigration extends AbstractAopConfigration {
public XmlAopConfigration(String... fileNames) throws ParserConfigurationException,
SAXException, IOException {
DocumentBuilder builder = Lang.xmls();
Document document;
List aopList = new ArrayList();
List list = Scans.me().loadResource(null, fileNames);
for (NutResource nutResource : list) {
document = builder.parse(nutResource.getInputStream());
document.normalizeDocument();
NodeList nodeListZ = ((Element) document.getDocumentElement()).getElementsByTagName("class");
for (int i = 0; i < nodeListZ.getLength(); i++)
aopList.add(parse((Element) nodeListZ.item(i)));
}
setAopItemList(aopList);
}
private AopConfigrationItem parse(Element item) {
AopConfigrationItem aopItem = new AopConfigrationItem();
aopItem.setClassName(item.getAttribute("name"));
aopItem.setMethodName(item.getAttribute("method"));
aopItem.setInterceptor(item.getAttribute("interceptor"));
if (item.hasAttribute("singleton"))
aopItem.setSingleton(Boolean.parseBoolean(item.getAttribute("singleton")));
return aopItem;
}
}