import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.xpath.XPath;
import org.jaxen.JaxenException;
import org.jdom.input.SAXBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class GlobalConfigure {
private static GlobalConfigure instance=new GlobalConfigure();
private Element rootElt;
private GlobalConfigure() throws IOException
{
SAXBuilder sb=new SAXBuilder();
try {
Document doc=sb.build(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("global-configure.xml"));
//得到元素根节点
this.rootElt=doc.getDocumentElement();
//得到子节点
//NodeList nodlist=rootElt.getChildNodes();
initJdbcInfo();
} catch (Exception e) {
e.printStackTrace();
}
}
public static GlobalConfigure getInstance()
{
return instance;
}
private void initJdbcInfo()
{
try {
Element element = XPath.selectSingleNode(rootElt,
"//sys-configure/jdbc-info/driver-class-name");
//System.out.println(element.getTextContent());
} catch (JaxenException e) {
e.printStackTrace();
}
}
private void initBean()
{
List beanList=XPath.selectNodes(rootElt,"//sys-configure/beans");
for(Iterator iter=beanList.iterator();iter.hasNext();)
{
Element beanElt=(Element)iter.next();
String id=beanElt.getAttribute("id");
String className=beanElt.getAttribute("class");
//System.out.println("id="+id);
//System.out.println("name="+className);
Object obj=Class.forName(className).newInstance();
Map beanMap=new HashMap();
beanMap.put(id, className);
}
}
public static void main(String args[])
{
GlobalConfigure.getInstance();
}
}