* @throws InstantiationException 如果实例化失败。
*/
private void addActionFactoryProperties(Element root) throws ClassNotFoundException,
IllegalAccessException, IntrospectionException, InvocationTargetException {
if (factory instanceof DefaultActionFactory) {
DefaultActionFactory defaultFactory = (DefaultActionFactory) this.factory;
List<Element> list = null;
//interceptor
list = getChildNodesByTagName(root, INTERCEPTOR);
for (Element e : list) {
//System.out.println(e.getAttribute(CLASS));
Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
//set property nodes
setProperties(obj, getChildNodesByTagName(e, PROPERTY));
//add interceptor
defaultFactory.addInterceptors(obj);
}
printSeparator(!list.isEmpty());
//interceptor-stack
list = getChildNodesByTagName(root, INTERCEPTOR_STACK);
for (Element e : list) {
//System.out.println(INTERCEPTOR_STACK + " : " + e.getAttribute(CLASS));
//add interceptor stacks
defaultFactory.addInterceptorStacks(factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS))));
}
printSeparator(!list.isEmpty());
//result-type
list = getChildNodesByTagName(root, RESULT_TYPE);
for (Element e : list) {
Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
//set property nodes
setProperties(obj, getChildNodesByTagName(e, PROPERTY));
//add result types
defaultFactory.addResultTypes(obj);
}
printSeparator(!list.isEmpty());
//result
list = getChildNodesByTagName(root, RESULT);
for (Element e : list) {
//add results
Object obj = factory.getObjectFactory().newInstance(Class.forName(e.getAttribute(CLASS)));
//set property nodes
setProperties(obj, getChildNodesByTagName(e, PROPERTY));
defaultFactory.addResults(obj);
}
printSeparator(!list.isEmpty());
//action
list = getChildNodesByTagName(root, ACTION);
for (Element action : list) {
//System.out.println(e.getAttribute(CLASS));
Object obj = factory.getObjectFactory().newInstance(Class.forName(action.getAttribute(CLASS)));
//action <property> nodes
List<Element> propnodes = getChildNodesByTagName(action, PROPERTY);
//common class properties
Map<String, PropertyDescriptor> supports = Injector.getSupportedProperties(obj.getClass());
//待注入相应class的Action属性列表
Map<String, Injection> classInjections = getInjections(propnodes, obj, supports);
//properties for action class
if (classInjections.size() > 0) {
Injector.putClassProperties(obj.getClass(), classInjections.values().toArray(new Injection[classInjections.size()]));
//Action对象属性注入
Injector.injectObject(obj);
}
//<path> nodes
List<Element> pathnodes = getChildNodesByTagName(action, PATH);
for (Element path : pathnodes) {
//path <property> nodes
propnodes = getChildNodesByTagName(path, PROPERTY);
//待注入相应path的Action属性列表
Map<String, Injection> pathInjections = getInjections(propnodes, obj, supports);
if (pathInjections.size() > 0) {
//属性包含class注入属性和path注入属性
Map<String, Injection> allInjections = new LinkedHashMap<String, Injection>(classInjections.size() + pathInjections.size());
allInjections.putAll(classInjections);
allInjections.putAll(pathInjections);
//System.out.println(path.getAttribute(NAME) + "," + allInjections);
Injector.putActionProperties(path.getAttribute(NAME), allInjections.values().toArray(new Injection[allInjections.size()]));
}
}
//add actions
defaultFactory.addActions(obj);
}
printSeparator(!list.isEmpty());
}
}