Java tutorial
/** * Copyright (c) 2010-2011 love320.com * * Licensed under the Apache License, Version 2.0 (the "License"); * * Founder admin@love320.com */ package com.love320.templateparser.factory.impl; import java.lang.reflect.Method; import java.util.List; import org.dom4j.Element; import org.dom4j.Node; import com.love320.templateparser.cache.Cache; import com.love320.templateparser.factory.BeanFactory; import com.love320.templateparser.factory.entity.BeanString; /** * @ClassName: BeanFactoryImpl * @Description: TODO * @author love320.com * @date 2012-4-15 ?05:01:08 * */ public class BeanFactoryImpl implements BeanFactory { private Element docroot; @Override public BeanString getBeanString(String name) { BeanString beanString = new BeanString();//bean? beanString.setName(name);//bean?name Node node = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@class"); //?idnameclass?? beanString.setClassName(node.getText());//bean?className Node beanScope = docroot.selectSingleNode("/beans/bean[@id='" + name + "']/@scope"); //?idnamescope?? if (beanScope != null) beanString.setScope(beanScope.getText());//bean?scope List ls = docroot.selectNodes("/beans/bean[@id='" + name + "']/property");//??? for (int i = 0; i < ls.size(); i++) { Element element = (Element) ls.get(i); String propertyName = element.attributeValue("name");//beanName Node propertyBeanNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/ref/@bean"); if (propertyBeanNode != null) { //?? ???beanId String[] refs = { null, null }; refs[0] = propertyName; refs[1] = propertyBeanNode.getText(); beanString.getRefList().add(refs); } Node propertyValueNode = docroot.selectSingleNode( "/beans/bean[@id='" + name + "']/property[@name='" + propertyName + "']/value"); if (propertyValueNode != null) { //?? ???? String[] values = { null, null }; values[0] = propertyName; values[1] = propertyValueNode.getText(); beanString.getValueList().add(values); } } return beanString; } public void setDocroot(Element docroot) { this.docroot = docroot; } }