com.aiwiown.face.internal.parser.xml.XmlConverter Maven / Gradle / Ivy
package com.aiwiown.face.internal.parser.xml;
import com.aiwiown.face.ApiConstants;
import com.aiwiown.face.ApiException;
import com.aiwiown.face.ApiResponse;
import com.aiwiown.face.internal.mapping.Converter;
import com.aiwiown.face.internal.mapping.Converters;
import com.aiwiown.face.internal.mapping.Reader;
import com.aiwiown.face.internal.util.XmlUtils;
import org.w3c.dom.Element;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* JSON格式转换器。
*
* @author carver.gu
* @since 1.0, Apr 11, 2010
*/
public class XmlConverter implements Converter {
@Override
public T toResponse(String rsp, Class clazz)
throws ApiException {
Element root = XmlUtils.getRootElementFromString(rsp);
return getModelFromXML(root, clazz);
}
private T getModelFromXML(final Element element, Class clazz) throws ApiException {
if (element == null) {
return null;
}
return Converters.convert(clazz, new Reader() {
@Override
public boolean hasReturnField(Object name) {
Element childE = XmlUtils.getChildElement(element, (String) name);
return childE != null;
}
@Override
public Object getPrimitiveObject(Object name) {
return XmlUtils.getElementValue(element, (String) name);
}
@Override
public Object getObject(Object name, Class> type) throws ApiException {
Element childE = XmlUtils.getChildElement(element, (String) name);
if (childE != null) {
return getModelFromXML(childE, type);
} else {
return null;
}
}
@Override
public List> getListObjects(Object listName, Object itemName, Class> subType)
throws ApiException {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy