01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding.soap;
19:
20: import java.util.HashSet;
21: import java.util.List;
22: import java.util.Set;
23:
24: import javax.wsdl.extensions.ExtensibilityElement;
25: import javax.xml.namespace.QName;
26:
27: import org.apache.cxf.helpers.CastUtils;
28: import org.apache.cxf.service.model.BindingMessageInfo;
29: import org.apache.cxf.service.model.BindingOperationInfo;
30: import org.apache.cxf.service.model.MessagePartInfo;
31: import org.apache.cxf.tools.common.extensions.soap.SoapHeader;
32: import org.apache.cxf.tools.util.SOAPBindingUtil;
33:
34: public final class HeaderUtil {
35: private static final String HEADERS_PROPERTY = HeaderUtil.class
36: .getName()
37: + ".HEADERS";
38:
39: private HeaderUtil() {
40: }
41:
42: private static Set<QName> getHeaderParts(BindingMessageInfo bmi) {
43: Object obj = bmi.getProperty(HEADERS_PROPERTY);
44: if (obj == null) {
45: Set<QName> set = getHeaderQNames(bmi);
46: bmi.setProperty(HEADERS_PROPERTY, set);
47: return set;
48: }
49: return CastUtils.cast((Set<?>) obj);
50: }
51:
52: private static Set<QName> getHeaderQNames(BindingMessageInfo bmi) {
53: Set<QName> set = new HashSet<QName>();
54: List<MessagePartInfo> mps = bmi.getMessageInfo()
55: .getMessageParts();
56: List<ExtensibilityElement> extList = bmi
57: .getExtensors(ExtensibilityElement.class);
58: if (extList != null) {
59: for (ExtensibilityElement ext : extList) {
60: if (SOAPBindingUtil.isSOAPHeader(ext)) {
61: SoapHeader header = SOAPBindingUtil
62: .getSoapHeader(ext);
63: String pn = header.getPart();
64: for (MessagePartInfo mpi : mps) {
65: if (pn.equals(mpi.getName().getLocalPart())) {
66: if (mpi.isElement()) {
67: set.add(mpi.getElementQName());
68: } else {
69: set.add(mpi.getTypeQName());
70: }
71: break;
72: }
73: }
74: }
75: }
76: }
77: return set;
78: }
79:
80: public static Set<QName> getHeaderQNameInOperationParam(
81: SoapMessage soapMessage) {
82: Set<QName> headers = new HashSet<QName>();
83: BindingOperationInfo bop = soapMessage.getExchange().get(
84: BindingOperationInfo.class);
85: if (bop != null) {
86: if (bop.getInput() != null) {
87: headers.addAll(getHeaderParts(bop.getInput()));
88: }
89: if (bop.getOutput() != null) {
90: headers.addAll(getHeaderParts(bop.getOutput()));
91: }
92: }
93: return headers;
94: }
95: }
|