package com.easyway.stps.bp.handler;import java.io.StringReader;import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilderFactory;import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;import com.easyway.stps.bp.demo.RailwayDynamicData;
import com.easyway.stps.bp.exception.BPException;/**
*
* @author vipzj
*
*/
@Component
public class HandlerFactoryBean {
private static final String HANDLER_SUFFIX = "Handler";
@Autowired
private ApplicationContext applicationContext;
@SuppressWarnings("unchecked")
public void process(String bodyMsg){
JAXBContext c;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
StringReader reader = new StringReader(bodyMsg);
InputSource inputSource = new InputSource(reader);
Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);
//取出第一个节点,判断是什么业务来的
Element root = document.getDocumentElement();
String rootName = root.getTagName();
if(rootName.indexOf(":")>0)
rootName = rootName.substring(rootName.indexOf(":")+1,rootName.length());
String dataObjectClassName = rootName + HANDLER_SUFFIX;
DataObjectHandler handler = (DataObjectHandler) applicationContext.getBean(StringUtils.uncapitalize(dataObjectClassName));
c = JAXBContext.newInstance(Class.forName("com.easyway.stps.bp.datasource."+rootName));
Unmarshaller unMarshaller = c.createUnmarshaller();
reader = new StringReader(bodyMsg);
Object data = (Object) unMarshaller.unmarshal(reader);
handler.execute(data); } catch (Exception e) {
e.printStackTrace();
//throw new BPException();
}
}
}
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilderFactory;import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;import com.easyway.stps.bp.demo.RailwayDynamicData;
import com.easyway.stps.bp.exception.BPException;/**
*
* @author vipzj
*
*/
@Component
public class HandlerFactoryBean {
private static final String HANDLER_SUFFIX = "Handler";
@Autowired
private ApplicationContext applicationContext;
@SuppressWarnings("unchecked")
public void process(String bodyMsg){
JAXBContext c;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
StringReader reader = new StringReader(bodyMsg);
InputSource inputSource = new InputSource(reader);
Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);
//取出第一个节点,判断是什么业务来的
Element root = document.getDocumentElement();
String rootName = root.getTagName();
if(rootName.indexOf(":")>0)
rootName = rootName.substring(rootName.indexOf(":")+1,rootName.length());
String dataObjectClassName = rootName + HANDLER_SUFFIX;
DataObjectHandler handler = (DataObjectHandler) applicationContext.getBean(StringUtils.uncapitalize(dataObjectClassName));
c = JAXBContext.newInstance(Class.forName("com.easyway.stps.bp.datasource."+rootName));
Unmarshaller unMarshaller = c.createUnmarshaller();
reader = new StringReader(bodyMsg);
Object data = (Object) unMarshaller.unmarshal(reader);
handler.execute(data); } catch (Exception e) {
e.printStackTrace();
//throw new BPException();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货