⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jaxbtype.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
字号:
package org.codehaus.xfire.jaxb;import javanet.staxutils.StAXSource;import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Marshaller;import javax.xml.bind.Unmarshaller;import javax.xml.namespace.QName;import javax.xml.stream.XMLStreamReader;import org.codehaus.xfire.MessageContext;import org.codehaus.xfire.XFireRuntimeException;import org.codehaus.xfire.aegis.MessageReader;import org.codehaus.xfire.aegis.MessageWriter;import org.codehaus.xfire.aegis.stax.ElementReader;import org.codehaus.xfire.aegis.stax.ElementWriter;import org.codehaus.xfire.aegis.type.Type;import org.codehaus.xfire.fault.XFireFault;public class JaxbType extends Type{    private QName mySchemaType;    public JaxbType(Class clazz, JAXBContext jaxbContext)    {        mySchemaType = new JaxbIntrospector(jaxbContext).introspect(clazz);        try        {            unmarshaller = jaxbContext.createUnmarshaller();            unmarshaller.setValidating(false);        } catch (JAXBException e)        {            throw new XFireRuntimeException("error creating unmarshaller", e);        }        try        {            marshaller = jaxbContext.createMarshaller();        } catch (JAXBException e)        {            throw new XFireRuntimeException("error creating marshaller", e);        }    }    Unmarshaller unmarshaller;    Marshaller marshaller;    public boolean isAbstract()    {        // right now we dont support abstract types        return false;    }    public boolean isComplex()    {        return true;    }    public Object readObject(MessageReader reader, MessageContext context) throws XFireFault    {        try        {            XMLStreamReader xmlStreamReader = ((ElementReader) reader).getXMLStreamReader();            StAXSource stAXSource = new StAXSource(xmlStreamReader);            return unmarshaller.unmarshal(stAXSource);        } catch (Exception e)        {            e.printStackTrace();            throw new XFireFault("Could not unmarshall type.", e, XFireFault.SENDER);        }    }    public void writeObject(Object object, MessageWriter writer, MessageContext context) throws XFireFault    {        try        {            marshaller.marshal(object, new FilteringStaxResult(((ElementWriter) writer).getXMLStreamWriter()));        } catch (JAXBException e)        {            throw new XFireFault("Could not marshall type.", e, XFireFault.RECEIVER);        }    }    public QName getSchemaType()    {        return mySchemaType;    }    public boolean isWriteOuter()    {        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -