001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.message.jaxb;
038:
039: import com.sun.xml.bind.api.Bridge;
040: import com.sun.xml.bind.api.JAXBRIContext;
041: import com.sun.xml.bind.api.TypeReference;
042: import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
043: import com.sun.xml.bind.v2.runtime.MarshallerImpl;
044: import org.w3c.dom.Node;
045: import org.xml.sax.ContentHandler;
046:
047: import javax.xml.bind.JAXBException;
048: import javax.xml.bind.Marshaller;
049: import javax.xml.bind.Unmarshaller;
050: import javax.xml.namespace.NamespaceContext;
051: import javax.xml.stream.XMLStreamReader;
052: import javax.xml.stream.XMLStreamWriter;
053: import javax.xml.transform.Result;
054: import javax.xml.transform.Source;
055: import java.io.InputStream;
056: import java.io.OutputStream;
057:
058: /**
059: * Used to adapt {@link Marshaller} into a {@link Bridge}.
060: *
061: * @author Kohsuke Kawaguchi
062: */
063: final class MarshallerBridge extends Bridge {
064: public MarshallerBridge(JAXBRIContext context) {
065: super ((JAXBContextImpl) context);
066: }
067:
068: public void marshal(Marshaller m, Object object,
069: XMLStreamWriter output) throws JAXBException {
070: m.setProperty(Marshaller.JAXB_FRAGMENT, true);
071: try {
072: m.marshal(object, output);
073: } finally {
074: m.setProperty(Marshaller.JAXB_FRAGMENT, false);
075: }
076: }
077:
078: public void marshal(Marshaller m, Object object,
079: OutputStream output, NamespaceContext nsContext)
080: throws JAXBException {
081: m.setProperty(Marshaller.JAXB_FRAGMENT, true);
082: try {
083: ((MarshallerImpl) m).marshal(object, output, nsContext);
084: } finally {
085: m.setProperty(Marshaller.JAXB_FRAGMENT, false);
086: }
087: }
088:
089: public void marshal(Marshaller m, Object object, Node output)
090: throws JAXBException {
091: m.setProperty(Marshaller.JAXB_FRAGMENT, true);
092: try {
093: m.marshal(object, output);
094: } finally {
095: m.setProperty(Marshaller.JAXB_FRAGMENT, false);
096: }
097: }
098:
099: public void marshal(Marshaller m, Object object,
100: ContentHandler contentHandler) throws JAXBException {
101: m.setProperty(Marshaller.JAXB_FRAGMENT, true);
102: try {
103: m.marshal(object, contentHandler);
104: } finally {
105: m.setProperty(Marshaller.JAXB_FRAGMENT, false);
106: }
107: }
108:
109: public void marshal(Marshaller m, Object object, Result result)
110: throws JAXBException {
111: m.setProperty(Marshaller.JAXB_FRAGMENT, true);
112: try {
113: m.marshal(object, result);
114: } finally {
115: m.setProperty(Marshaller.JAXB_FRAGMENT, false);
116: }
117: }
118:
119: public Object unmarshal(Unmarshaller u, XMLStreamReader in) {
120: throw new UnsupportedOperationException();
121: }
122:
123: public Object unmarshal(Unmarshaller u, Source in) {
124: throw new UnsupportedOperationException();
125: }
126:
127: public Object unmarshal(Unmarshaller u, InputStream in) {
128: throw new UnsupportedOperationException();
129: }
130:
131: public Object unmarshal(Unmarshaller u, Node n) {
132: throw new UnsupportedOperationException();
133: }
134:
135: public TypeReference getTypeReference() {
136: throw new UnsupportedOperationException();
137: }
138: }
|