config.setBeanFields(beanFields);
return config;
}
public static BeanMappingField parseField(Node node) {
BeanMappingField beanField = new BeanMappingField();
Node srcNameNode = node.getAttributes().getNamedItem("srcName");
Node srcClassNode = node.getAttributes().getNamedItem("srcClass");
Node srcLocatorNode = node.getAttributes().getNamedItem("srcLocatorClass");
Node srcComponentNode = node.getAttributes().getNamedItem("srcComponentClass");
Node targetNameNode = node.getAttributes().getNamedItem("targetName");
Node targetClassNode = node.getAttributes().getNamedItem("targetClass");
Node targetLocatorNode = node.getAttributes().getNamedItem("targetLocatorClass");
Node targetComponentNode = node.getAttributes().getNamedItem("targetComponentClass");
Node defaultValueNode = node.getAttributes().getNamedItem("defaultValue");
Node convertorNode = node.getAttributes().getNamedItem("convertor");
Node scriptNode = node.getAttributes().getNamedItem("script");
if (scriptNode == null && srcNameNode == null) {
throw new BeanMappingException("srcName or script is requied");
}
if (targetNameNode == null) {
throw new BeanMappingException("targetName is requied");
}
if (srcNameNode != null) {
beanField.getSrcField().setName(srcNameNode.getNodeValue());
}
if (srcClassNode != null) {
beanField.getSrcField().setClazz(ReflectionHelper.forName(srcClassNode.getNodeValue()));
}
if (srcLocatorNode != null) {
beanField.getSrcField().setLocatorClass(ReflectionHelper.forName(srcLocatorNode.getNodeValue()));
}
if (srcComponentNode != null) {
beanField.getSrcField().addComponentClasses(ReflectionHelper.forName(srcComponentNode.getNodeValue()));
}
if (targetNameNode != null) {
beanField.getTargetField().setName(targetNameNode.getNodeValue());
}
if (targetClassNode != null) {
beanField.getTargetField().setClazz(ReflectionHelper.forName(targetClassNode.getNodeValue()));
}
if (targetLocatorNode != null) {
beanField.getTargetField().setLocatorClass(ReflectionHelper.forName(targetLocatorNode.getNodeValue()));
}
if (targetComponentNode != null) {
beanField.getTargetField().addComponentClasses(ReflectionHelper.forName(targetComponentNode.getNodeValue()));
}
if (defaultValueNode != null) {
beanField.setDefaultValue(defaultValueNode.getNodeValue());
}
if (convertorNode != null) {
beanField.setConvertor(convertorNode.getNodeValue());
}
if (scriptNode != null) {
beanField.setScript(scriptNode.getNodeValue());
}
// 处理下mapping
Node mappingNode = node.getAttributes().getNamedItem("mapping");
if (mappingNode != null) {
beanField.setMapping(Boolean.valueOf(mappingNode.getNodeValue()));
}
// 处理下nest name
Node nestNode = node.getAttributes().getNamedItem("nest");
if (nestNode != null) {
beanField.setNestName(nestNode.getNodeValue());
}
return beanField;
}