001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.encoding.jaxb;
026:
027: import com.sun.xml.internal.ws.encoding.soap.SerializationException;
028: import com.sun.xml.internal.bind.api.BridgeContext;
029:
030: import javax.xml.bind.JAXBContext;
031: import javax.xml.bind.Marshaller;
032: import javax.xml.bind.Unmarshaller;
033: import javax.xml.transform.dom.DOMSource;
034: import javax.xml.transform.Source;
035: import javax.xml.stream.XMLStreamWriter;
036: import javax.xml.stream.XMLStreamReader;
037: import java.io.OutputStream;
038:
039: /**
040: * XML infoset represented as a JAXB object.
041: *
042: * @author WS Development Team
043: */
044: public final class JAXBBeanInfo {
045: private final Object jaxbBean;
046: private JAXBContext jaxbContext;
047: private BridgeContext bc;
048: private Marshaller marshaller;
049: private Unmarshaller unmarshaller;
050:
051: public JAXBBeanInfo(Object payload, JAXBContext jaxbContext) {
052: this .jaxbBean = payload;
053: this .jaxbContext = jaxbContext;
054: }
055:
056: public static JAXBBeanInfo fromSource(Source source,
057: JAXBContext context) {
058: Object obj = JAXBTypeSerializer.deserialize(source, context);
059: return new JAXBBeanInfo(obj, context);
060: }
061:
062: public static JAXBBeanInfo fromStAX(XMLStreamReader reader,
063: JAXBContext context) {
064:
065: Object obj = JAXBTypeSerializer.deserialize(reader, context);
066: return new JAXBBeanInfo(obj, context);
067: }
068:
069: public static JAXBBeanInfo fromStAX(XMLStreamReader reader,
070: JAXBContext context, Unmarshaller um) {
071:
072: Object obj = JAXBTypeSerializer
073: .deserialize(reader, context, um);
074: return new JAXBBeanInfo(obj, context);
075: }
076:
077: public Object getBean() {
078: return jaxbBean;
079: }
080:
081: public JAXBContext getJAXBContext() {
082: return jaxbContext;
083: }
084:
085: /**
086: * Creates a {@link DOMSource} from this JAXB bean.
087: */
088: public DOMSource toDOMSource() {
089: return JAXBTypeSerializer.serialize(jaxbBean, jaxbContext);
090: }
091:
092: /**
093: * Writes this bean to StAX.
094: */
095: public void writeTo(XMLStreamWriter w) {
096: if (marshaller != null)
097: JAXBTypeSerializer.serialize(jaxbBean, w, jaxbContext,
098: marshaller);
099: else
100: JAXBTypeSerializer.serialize(jaxbBean, w, jaxbContext);
101: }
102:
103: public void writeTo(OutputStream os) {
104: if (marshaller != null)
105: JAXBTypeSerializer.serialize(jaxbBean, os, jaxbContext,
106: marshaller);
107: else
108: JAXBTypeSerializer.serialize(jaxbBean, os, jaxbContext);
109: }
110:
111: public void setMarshallers(Marshaller m, Unmarshaller u) {
112: this.marshaller = m;
113: this.unmarshaller = u;
114: }
115: }
|