1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.sun.xml.internal.bind.v2.runtime;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31
32 import javax.xml.bind.JAXBElement;
33 import javax.xml.bind.JAXBException;
34 import javax.xml.bind.Marshaller;
35 import javax.xml.bind.Unmarshaller;
36 import javax.xml.namespace.NamespaceContext;
37 import javax.xml.stream.XMLStreamException;
38 import javax.xml.stream.XMLStreamReader;
39 import javax.xml.stream.XMLStreamWriter;
40 import javax.xml.transform.Result;
41 import javax.xml.transform.Source;
42
43 import com.sun.istack.internal.NotNull;
44 import com.sun.xml.internal.bind.api.Bridge;
45 import com.sun.xml.internal.bind.api.TypeReference;
46 import com.sun.xml.internal.bind.marshaller.SAX2DOMEx;
47 import com.sun.xml.internal.bind.v2.runtime.output.SAXOutput;
48 import com.sun.xml.internal.bind.v2.runtime.output.XMLStreamWriterOutput;
49 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl;
50
51 import org.w3c.dom.Node;
52 import org.xml.sax.ContentHandler;
53 import org.xml.sax.SAXException;
54
55
56
57
58
59
60 final class BridgeImpl<T> extends InternalBridge<T> {
61
62
63
64
65
66 private final Name tagName;
67 private final JaxBeanInfo<T> bi;
68 private final TypeReference typeRef;
69
70 public BridgeImpl(JAXBContextImpl context, Name tagName, JaxBeanInfo<T> bi,TypeReference typeRef) {
71 super(context);
72 this.tagName = tagName;
73 this.bi = bi;
74 this.typeRef = typeRef;
75 }
76
77 public void marshal(Marshaller _m, T t, XMLStreamWriter output) throws JAXBException {
78 MarshallerImpl m = (MarshallerImpl)_m;
79 m.write(tagName,bi,t,XMLStreamWriterOutput.create(output,context),new StAXPostInitAction(output,m.serializer));
80 }
81
82 public void marshal(Marshaller _m, T t, OutputStream output, NamespaceContext nsContext) throws JAXBException {
83 MarshallerImpl m = (MarshallerImpl)_m;
84
85 Runnable pia = null;
86 if(nsContext!=null)
87 pia = new StAXPostInitAction(nsContext,m.serializer);
88
89 m.write(tagName,bi,t,m.createWriter(output),pia);
90 }
91
92 public void marshal(Marshaller _m, T t, Node output) throws JAXBException {
93 MarshallerImpl m = (MarshallerImpl)_m;
94 m.write(tagName,bi,t,new SAXOutput(new SAX2DOMEx(output)),new DomPostInitAction(output,m.serializer));
95 }
96
97 public void marshal(Marshaller _m, T t, ContentHandler contentHandler) throws JAXBException {
98 MarshallerImpl m = (MarshallerImpl)_m;
99 m.write(tagName,bi,t,new SAXOutput(contentHandler),null);
100 }
101
102 public void marshal(Marshaller _m, T t, Result result) throws JAXBException {
103 MarshallerImpl m = (MarshallerImpl)_m;
104 m.write(tagName,bi,t, m.createXmlOutput(result),m.createPostInitAction(result));
105 }
106
107 public @NotNull T unmarshal(Unmarshaller _u, XMLStreamReader in) throws JAXBException {
108 UnmarshallerImpl u = (UnmarshallerImpl)_u;
109 return ((JAXBElement<T>)u.unmarshal0(in,bi)).getValue();
110 }
111
112 public @NotNull T unmarshal(Unmarshaller _u, Source in) throws JAXBException {
113 UnmarshallerImpl u = (UnmarshallerImpl)_u;
114 return ((JAXBElement<T>)u.unmarshal0(in,bi)).getValue();
115 }
116
117 public @NotNull T unmarshal(Unmarshaller _u, InputStream in) throws JAXBException {
118 UnmarshallerImpl u = (UnmarshallerImpl)_u;
119 return ((JAXBElement<T>)u.unmarshal0(in,bi)).getValue();
120 }
121
122 public @NotNull T unmarshal(Unmarshaller _u, Node n) throws JAXBException {
123 UnmarshallerImpl u = (UnmarshallerImpl)_u;
124 return ((JAXBElement<T>)u.unmarshal0(n,bi)).getValue();
125 }
126
127 public TypeReference getTypeReference() {
128 return typeRef;
129 }
130
131 public void marshal(T value, XMLSerializer out) throws IOException, SAXException, XMLStreamException {
132 out.startElement(tagName,null);
133 if(value==null) {
134 out.writeXsiNilTrue();
135 } else {
136 out.childAsXsiType(value,null,bi,false);
137 }
138 out.endElement();
139 }
140
141 }