1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/client/ServiceInterceptor.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,125 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.api.client; 1.30 + 1.31 +import com.sun.istack.internal.NotNull; 1.32 +import com.sun.istack.internal.Nullable; 1.33 +import com.sun.xml.internal.ws.api.BindingID; 1.34 +import com.sun.xml.internal.ws.api.WSBinding; 1.35 +import com.sun.xml.internal.ws.api.WSFeatureList; 1.36 +import com.sun.xml.internal.ws.api.WSService; 1.37 +import com.sun.xml.internal.ws.developer.WSBindingProvider; 1.38 + 1.39 +import javax.xml.ws.BindingProvider; 1.40 +import javax.xml.ws.Dispatch; 1.41 +import javax.xml.ws.WebServiceFeature; 1.42 +import java.util.ArrayList; 1.43 +import java.util.Collections; 1.44 +import java.util.List; 1.45 + 1.46 +/** 1.47 + * Interception point for inner working of {@link WSService}. 1.48 + * 1.49 + * <p> 1.50 + * System-level code could hook an implementation of this to 1.51 + * {@link WSService} to augument its behavior. 1.52 + * 1.53 + * @author Kohsuke Kawaguchi 1.54 + * @since 2.1 EA3 1.55 + * @see ServiceInterceptorFactory 1.56 + */ 1.57 +public abstract class ServiceInterceptor { 1.58 + /** 1.59 + * Called before {@link WSBinding} is created, to allow interceptors 1.60 + * to add {@link WebServiceFeature}s to the created {@link WSBinding}. 1.61 + * 1.62 + * @param port 1.63 + * Information about the port for which dispatch/proxy will be created. 1.64 + * @param serviceEndpointInterface 1.65 + * Null if the created binding is for {@link Dispatch}. Otheriwse 1.66 + * it represents the port interface of the proxy to be created. 1.67 + * @param defaultFeatures 1.68 + * The list of features that are currently scheduled to be set for 1.69 + * the newly created {@link WSBinding}. 1.70 + * 1.71 + * @return 1.72 + * A set of features to be added to the newly created {@link WSBinding}. 1.73 + * Can be empty but never null. 1.74 + * <tt>defaultFeatures</tt> will take precedence over what this method 1.75 + * would return (because it includes user-specified ones which will 1.76 + * take the at-most priority), but features you return from this method 1.77 + * will take precedence over {@link BindingID}'s 1.78 + * {@link BindingID#createBuiltinFeatureList() implicit features}. 1.79 + */ 1.80 + public List<WebServiceFeature> preCreateBinding(@NotNull WSPortInfo port, @Nullable Class<?> serviceEndpointInterface, @NotNull WSFeatureList defaultFeatures) { 1.81 + return Collections.emptyList(); 1.82 + } 1.83 + 1.84 + /** 1.85 + * A callback to notify the event of creation of proxy object for SEI endpoint. The 1.86 + * callback could set some properties on the {@link BindingProvider}. 1.87 + * 1.88 + * @param bp created proxy instance 1.89 + * @param serviceEndpointInterface SEI of the endpoint 1.90 + */ 1.91 + public void postCreateProxy(@NotNull WSBindingProvider bp,@NotNull Class<?> serviceEndpointInterface) { 1.92 + } 1.93 + 1.94 + /** 1.95 + * A callback to notify that a {@link Dispatch} object is created. The callback 1.96 + * could set some properties on the {@link BindingProvider}. 1.97 + * 1.98 + * @param bp BindingProvider of dispatch object 1.99 + */ 1.100 + public void postCreateDispatch(@NotNull WSBindingProvider bp) { 1.101 + } 1.102 + 1.103 + /** 1.104 + * Aggregates multiple interceptors into one facade. 1.105 + */ 1.106 + public static ServiceInterceptor aggregate(final ServiceInterceptor... interceptors) { 1.107 + if(interceptors.length==1) 1.108 + return interceptors[0]; 1.109 + return new ServiceInterceptor() { 1.110 + public List<WebServiceFeature> preCreateBinding(@NotNull WSPortInfo port, @Nullable Class<?> portInterface, @NotNull WSFeatureList defaultFeatures) { 1.111 + List<WebServiceFeature> r = new ArrayList<WebServiceFeature>(); 1.112 + for (ServiceInterceptor si : interceptors) 1.113 + r.addAll(si.preCreateBinding(port,portInterface,defaultFeatures)); 1.114 + return r; 1.115 + } 1.116 + 1.117 + public void postCreateProxy(@NotNull WSBindingProvider bp, @NotNull Class<?> serviceEndpointInterface) { 1.118 + for (ServiceInterceptor si : interceptors) 1.119 + si.postCreateProxy(bp,serviceEndpointInterface); 1.120 + } 1.121 + 1.122 + public void postCreateDispatch(@NotNull WSBindingProvider bp) { 1.123 + for (ServiceInterceptor si : interceptors) 1.124 + si.postCreateDispatch(bp); 1.125 + } 1.126 + }; 1.127 + } 1.128 +}