author | avstepan |
Thu, 24 Sep 2015 18:26:42 +0300 | |
changeset 32795 | 5a5710ee05a0 |
parent 25871 | b80b84e87032 |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22679
d785acd84a14
8032639: Update copyright year to match last edit in jaxws repository for 2013
mkos
parents:
16791
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.ws.message; |
|
27 |
||
28 |
import com.sun.istack.internal.NotNull; |
|
29 |
import com.sun.xml.internal.bind.api.Bridge; |
|
30 |
import com.sun.xml.internal.bind.api.BridgeContext; |
|
31 |
import com.sun.xml.internal.ws.api.SOAPVersion; |
|
32 |
import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
|
33 |
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; |
|
34 |
import com.sun.xml.internal.ws.api.message.Header; |
|
35 |
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory; |
|
36 |
import com.sun.xml.internal.ws.spi.db.XMLBridge; |
|
37 |
||
38 |
import org.xml.sax.helpers.AttributesImpl; |
|
39 |
||
40 |
import javax.xml.bind.JAXBException; |
|
41 |
import javax.xml.bind.Unmarshaller; |
|
42 |
import javax.xml.namespace.QName; |
|
43 |
import javax.xml.stream.XMLStreamException; |
|
44 |
import javax.xml.stream.XMLStreamReader; |
|
45 |
import java.util.Set; |
|
46 |
||
47 |
/** |
|
48 |
* Partial default implementation of {@link Header}. |
|
49 |
* |
|
50 |
* <p> |
|
51 |
* This is meant to be a convenient base class |
|
52 |
* for {@link Header}-derived classes. |
|
53 |
* |
|
54 |
* @author Kohsuke Kawaguchi |
|
55 |
*/ |
|
56 |
public abstract class AbstractHeaderImpl implements Header { |
|
57 |
||
58 |
protected AbstractHeaderImpl() { |
|
59 |
} |
|
60 |
||
61 |
/** |
|
62 |
* @deprecated |
|
63 |
*/ |
|
64 |
public final <T> T readAsJAXB(Bridge<T> bridge, BridgeContext context) throws JAXBException { |
|
65 |
return readAsJAXB(bridge); |
|
66 |
} |
|
67 |
||
68 |
public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException { |
|
69 |
try { |
|
70 |
return (T)unmarshaller.unmarshal(readHeader()); |
|
71 |
} catch (Exception e) { |
|
72 |
throw new JAXBException(e); |
|
73 |
} |
|
74 |
} |
|
75 |
/** @deprecated */ |
|
76 |
public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException { |
|
77 |
try { |
|
78 |
return bridge.unmarshal(readHeader()); |
|
79 |
} catch (XMLStreamException e) { |
|
80 |
throw new JAXBException(e); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
public <T> T readAsJAXB(XMLBridge<T> bridge) throws JAXBException { |
|
85 |
try { |
|
86 |
return bridge.unmarshal(readHeader(), null); |
|
87 |
} catch (XMLStreamException e) { |
|
88 |
throw new JAXBException(e); |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Default implementation that copies the infoset. Not terribly efficient. |
|
94 |
*/ |
|
95 |
public WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException { |
|
96 |
XMLStreamReader xsr = readHeader(); |
|
97 |
WSEndpointReference epr = new WSEndpointReference(xsr, expected); |
|
98 |
XMLStreamReaderFactory.recycle(xsr); |
|
99 |
return epr; |
|
100 |
} |
|
101 |
||
102 |
public boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles) { |
|
103 |
// check mustUnderstand |
|
104 |
String v = getAttribute(soapVersion.nsUri, "mustUnderstand"); |
|
105 |
if(v==null || !parseBool(v)) return true; |
|
106 |
||
16791 | 107 |
if (roles == null) return true; |
108 |
||
12009 | 109 |
// now role |
110 |
return !roles.contains(getRole(soapVersion)); |
|
111 |
} |
|
112 |
||
113 |
public @NotNull String getRole(@NotNull SOAPVersion soapVersion) { |
|
114 |
String v = getAttribute(soapVersion.nsUri, soapVersion.roleAttributeName); |
|
115 |
if(v==null) |
|
116 |
v = soapVersion.implicitRole; |
|
117 |
return v; |
|
118 |
} |
|
119 |
||
120 |
public boolean isRelay() { |
|
121 |
String v = getAttribute(SOAPVersion.SOAP_12.nsUri,"relay"); |
|
122 |
if(v==null) return false; // on SOAP 1.1 message there shouldn't be such an attribute, so this works fine |
|
123 |
return parseBool(v); |
|
124 |
} |
|
125 |
||
126 |
public String getAttribute(QName name) { |
|
127 |
return getAttribute(name.getNamespaceURI(),name.getLocalPart()); |
|
128 |
} |
|
129 |
||
130 |
/** |
|
32795
5a5710ee05a0
8133651: replace some <tt> tags (obsolete in html5) in core-libs docs
avstepan
parents:
25871
diff
changeset
|
131 |
* Parses a string that looks like {@code xs:boolean} into boolean. |
12009 | 132 |
* |
133 |
* This method assumes that the whilespace normalization has already taken place. |
|
134 |
*/ |
|
135 |
protected final boolean parseBool(String value) { |
|
136 |
if(value.length()==0) |
|
137 |
return false; |
|
138 |
||
139 |
char ch = value.charAt(0); |
|
140 |
return ch=='t' || ch=='1'; |
|
141 |
} |
|
142 |
||
143 |
public String getStringContent() { |
|
144 |
try { |
|
145 |
XMLStreamReader xsr = readHeader(); |
|
146 |
xsr.nextTag(); |
|
147 |
return xsr.getElementText(); |
|
148 |
} catch (XMLStreamException e) { |
|
149 |
return null; |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
protected static final AttributesImpl EMPTY_ATTS = new AttributesImpl(); |
|
154 |
} |