001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxws.binding.soap;
019:
020: import java.util.HashSet;
021: import java.util.ResourceBundle;
022: import java.util.Set;
023: import java.util.logging.Logger;
024:
025: import javax.xml.soap.MessageFactory;
026: import javax.xml.soap.SOAPConstants;
027: import javax.xml.soap.SOAPException;
028: import javax.xml.soap.SOAPFactory;
029: import javax.xml.ws.WebServiceException;
030: import javax.xml.ws.soap.SOAPBinding;
031:
032: import org.apache.cxf.binding.soap.Soap11;
033: import org.apache.cxf.binding.soap.Soap12;
034: import org.apache.cxf.binding.soap.model.SoapBindingInfo;
035: import org.apache.cxf.common.logging.LogUtils;
036: import org.apache.cxf.jaxws.binding.BindingImpl;
037: import org.apache.cxf.message.Message;
038: import org.apache.cxf.service.model.BindingInfo;
039:
040: public class SOAPBindingImpl extends BindingImpl implements SOAPBinding {
041:
042: private static final Logger LOG = LogUtils
043: .getL7dLogger(SOAPBindingImpl.class);
044: private static final ResourceBundle BUNDLE = LOG
045: .getResourceBundle();
046:
047: private BindingInfo soapBinding;
048: private Set<String> roles;
049:
050: public SOAPBindingImpl(BindingInfo sb) {
051: soapBinding = sb;
052: addRequiredRoles();
053: }
054:
055: private void addRequiredRoles() {
056: if (this .roles == null) {
057: this .roles = new HashSet<String>();
058: }
059: if (this .soapBinding instanceof SoapBindingInfo) {
060: SoapBindingInfo bindingInfo = (SoapBindingInfo) this .soapBinding;
061: if (bindingInfo.getSoapVersion() instanceof Soap11) {
062: this .roles.add(bindingInfo.getSoapVersion()
063: .getNextRole());
064: } else if (bindingInfo.getSoapVersion() instanceof Soap12) {
065: this .roles.add(bindingInfo.getSoapVersion()
066: .getNextRole());
067: this .roles.add(bindingInfo.getSoapVersion()
068: .getUltimateReceiverRole());
069: }
070: }
071: }
072:
073: public Set<String> getRoles() {
074: return this .roles;
075: }
076:
077: public void setRoles(Set<String> set) {
078: if (set != null
079: && (set.contains(Soap11.getInstance().getNoneRole()) || set
080: .contains(Soap12.getInstance().getNoneRole()))) {
081: throw new WebServiceException(BUNDLE
082: .getString("NONE_ROLE_ERR"));
083: }
084: this .roles = set;
085: addRequiredRoles();
086: }
087:
088: public boolean isMTOMEnabled() {
089: return Boolean.TRUE.equals(soapBinding
090: .getProperty(Message.MTOM_ENABLED));
091: }
092:
093: public void setMTOMEnabled(boolean flag) {
094: soapBinding.setProperty(Message.MTOM_ENABLED, flag);
095: }
096:
097: public MessageFactory getMessageFactory() {
098: if (this .soapBinding instanceof SoapBindingInfo) {
099: SoapBindingInfo bindingInfo = (SoapBindingInfo) this .soapBinding;
100: try {
101: if (bindingInfo.getSoapVersion() instanceof Soap11) {
102: return MessageFactory.newInstance();
103: } else if (bindingInfo.getSoapVersion() instanceof Soap12) {
104: return MessageFactory
105: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
106: }
107: } catch (SOAPException e) {
108: throw new WebServiceException(BUNDLE
109: .getString("SAAJ_FACTORY_ERR"), e);
110: }
111: }
112: return null;
113: }
114:
115: public SOAPFactory getSOAPFactory() {
116: if (this .soapBinding instanceof SoapBindingInfo) {
117: SoapBindingInfo bindingInfo = (SoapBindingInfo) this .soapBinding;
118: try {
119: if (bindingInfo.getSoapVersion() instanceof Soap11) {
120: return SOAPFactory.newInstance();
121: } else if (bindingInfo.getSoapVersion() instanceof Soap12) {
122: return SOAPFactory
123: .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
124: }
125: } catch (SOAPException e) {
126: throw new WebServiceException(BUNDLE
127: .getString("SAAJ_FACTORY_ERR"), e);
128: }
129: }
130: return null;
131: }
132:
133: }
|