01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.xml.internal.bind.v2.runtime;
27:
28: import javax.activation.DataHandler;
29: import javax.xml.bind.annotation.XmlAttachmentRef;
30: import javax.xml.bind.annotation.adapters.XmlAdapter;
31: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32: import javax.xml.bind.attachment.AttachmentMarshaller;
33: import javax.xml.bind.attachment.AttachmentUnmarshaller;
34:
35: import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
36:
37: /**
38: * {@link XmlAdapter} that binds the value as a SOAP attachment.
39: *
40: * <p>
41: * On the user classes the SwA handling is done by using the {@link XmlAttachmentRef}
42: * annotation, but internally we treat it as a {@link XmlJavaTypeAdapter} with this
43: * adapter class. This is true with both XJC and the runtime.
44: *
45: * <p>
46: * the model builder code and the code generator does the conversion and
47: * shield the rest of the RI from this mess.
48: * Also see @see <a href="http://webservices.xml.com/pub/a/ws/2003/09/16/wsbp.html?page=2">http://webservices.xml.com/pub/a/ws/2003/09/16/wsbp.html?page=2</a>.
49: *
50: * @author Kohsuke Kawaguchi
51: */
52: public final class SwaRefAdapter extends
53: XmlAdapter<String, DataHandler> {
54:
55: public SwaRefAdapter() {
56: }
57:
58: public DataHandler unmarshal(String cid) {
59: AttachmentUnmarshaller au = UnmarshallingContext.getInstance().parent
60: .getAttachmentUnmarshaller();
61: // TODO: error check
62: return au.getAttachmentAsDataHandler(cid);
63: }
64:
65: public String marshal(DataHandler data) {
66: if (data == null)
67: return null;
68: AttachmentMarshaller am = XMLSerializer.getInstance().attachmentMarshaller;
69: // TODO: error check
70: return am.addSwaRefAttachment(data);
71: }
72: }
|