com.sun.xml.ws.binding.BindingImpl Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.xml.ws.binding;
import com.sun.istack.NotNull;
import com.sun.istack.Nullable;
import com.sun.xml.ws.api.BindingID;
import com.sun.xml.ws.api.SOAPVersion;
import com.sun.xml.ws.api.WSBinding;
import com.sun.xml.ws.api.addressing.AddressingVersion;
import com.sun.xml.ws.api.pipe.Codec;
import com.sun.xml.ws.client.HandlerConfiguration;
import com.sun.xml.ws.developer.MemberSubmissionAddressingFeature;
import com.sun.xml.ws.developer.BindingTypeFeature;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.soap.AddressingFeature;
import javax.xml.ws.handler.Handler;
import java.util.Collections;
import java.util.List;
/**
* Instances are created by the service, which then
* sets the handler chain on the binding impl.
*
*
* This class is made abstract as we don't see a situation when
* a BindingImpl has much meaning without binding id.
* IOW, for a specific binding there will be a class
* extending BindingImpl, for example SOAPBindingImpl.
*
*
* The spi Binding interface extends Binding.
*
* @author WS Development Team
*/
public abstract class BindingImpl implements WSBinding {
private HandlerConfiguration handlerConfig;
private final BindingID bindingId;
// Features that are set(enabled/disabled) on the binding
protected final WebServiceFeatureList features = new WebServiceFeatureList();
protected BindingImpl(BindingID bindingId) {
this.bindingId = bindingId;
setHandlerConfig(createHandlerConfig(Collections.emptyList()));
}
public
@NotNull
List getHandlerChain() {
return handlerConfig.getHandlerChain();
}
public HandlerConfiguration getHandlerConfig() {
return handlerConfig;
}
/**
* Sets the handlers on the binding and then
* sorts the handlers in to logical and protocol handlers.
* Creates a new HandlerConfiguration object and sets it on the BindingImpl.
*/
public void setHandlerChain(List chain) {
setHandlerConfig(createHandlerConfig(chain));
}
/**
* This is called when ever Binding.setHandlerChain() or SOAPBinding.setRoles()
* is called.
* This sorts out the Handlers into Logical and SOAP Handlers and
* sets the HandlerConfiguration.
*/
protected void setHandlerConfig(HandlerConfiguration handlerConfig) {
this.handlerConfig = handlerConfig;
}
protected abstract HandlerConfiguration createHandlerConfig(List handlerChain);
public
@NotNull
BindingID getBindingId() {
return bindingId;
}
public final SOAPVersion getSOAPVersion() {
return bindingId.getSOAPVersion();
}
public AddressingVersion getAddressingVersion() {
AddressingVersion addressingVersion;
if (features.isEnabled(AddressingFeature.class))
addressingVersion = AddressingVersion.W3C;
else if (features.isEnabled(MemberSubmissionAddressingFeature.class))
addressingVersion = AddressingVersion.MEMBER;
else
addressingVersion = null;
return addressingVersion;
}
public final
@NotNull
Codec createCodec() {
return bindingId.createEncoder(this);
}
public static BindingImpl create(@NotNull BindingID bindingId) {
if (bindingId.equals(BindingID.XML_HTTP))
return new HTTPBindingImpl();
else
return new SOAPBindingImpl(bindingId);
}
public static BindingImpl create(@NotNull BindingID bindingId, WebServiceFeature[] features) {
// Override the BindingID from the features
for(WebServiceFeature feature : features) {
if (feature instanceof BindingTypeFeature) {
BindingTypeFeature f = (BindingTypeFeature)feature;
bindingId = BindingID.parse(f.getBindingId());
}
}
if (bindingId.equals(BindingID.XML_HTTP))
return new HTTPBindingImpl();
else
return new SOAPBindingImpl(bindingId, features);
}
public static WSBinding getDefaultBinding() {
return new SOAPBindingImpl(BindingID.SOAP11_HTTP);
}
public String getBindingID() {
return bindingId.toString();
}
public @Nullable F getFeature(@NotNull Class featureType){
return features.get(featureType);
}
public boolean isFeatureEnabled(@NotNull Class extends WebServiceFeature> feature){
return features.isEnabled(feature);
}
@NotNull
public WebServiceFeatureList getFeatures() {
return features;
}
public void setFeatures(WebServiceFeature... newFeatures) {
if (newFeatures != null) {
for (WebServiceFeature f : newFeatures) {
features.add(f);
}
}
}
public void addFeature(@NotNull WebServiceFeature newFeature) {
features.add(newFeature);
}
}