JDOM是一個開源項目
JDOM的官方地址
[Moveable
package com
public interface Moveable {
void run();
}
[Plane
package com
public class Plane implements Moveable {
@Override
public void run() {
// TODO Auto
System
}
}
[Train
package com
public class Train implements Moveable{
@Override
public void run() {
System
}
}
package com
public interface BeanFactory {
Object getBean(String id);
}
<?xml version="
<beans>
<bean
id="train"
class="com
</bean>
<bean
id="plane"
class="com
</bean>
</beans>
package com
import java
import java
import java
import org
import org
import org
import org
public class ClassPathXmlApplicationContext implements BeanFactory {
private Map<String
public ClassPathXmlApplicationContext(String fileName) throws Exception {
SAXBuilder sb = new SAXBuilder();
Document doc = sb
Element root = doc
List list = XPath
System
for (int i =
Element bean = (Element) list
String id = bean
String clazz = bean
Object o = Class
mapContainer
System
}
}
@Override
public Object getBean(String id) {
return mapContainer
}
}
package com
public class TestMain {
public static void main(String[] args) throws Exception {
BeanFactory f = new ClassPathXmlApplicationContext(
"com/njupt/zhb/test/sample
Object obj
Moveable m
m
// //
Object obj
Moveable m
m
}
}
實驗結果
train com
plane com
火車在飛奔
飛機在翱翔
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20309.html