001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api.client;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.istack.Nullable;
041: import com.sun.xml.ws.api.BindingID;
042: import com.sun.xml.ws.api.WSBinding;
043: import com.sun.xml.ws.api.WSFeatureList;
044: import com.sun.xml.ws.api.WSService;
045: import com.sun.xml.ws.developer.WSBindingProvider;
046:
047: import javax.xml.ws.BindingProvider;
048: import javax.xml.ws.Dispatch;
049: import javax.xml.ws.WebServiceFeature;
050: import java.util.ArrayList;
051: import java.util.Collections;
052: import java.util.List;
053:
054: /**
055: * Interception point for inner working of {@link WSService}.
056: *
057: * <p>
058: * System-level code could hook an implementation of this to
059: * {@link WSService} to augument its behavior.
060: *
061: * @author Kohsuke Kawaguchi
062: * @since 2.1 EA3
063: * @see ServiceInterceptorFactory
064: */
065: public abstract class ServiceInterceptor {
066: /**
067: * Called before {@link WSBinding} is created, to allow interceptors
068: * to add {@link WebServiceFeature}s to the created {@link WSBinding}.
069: *
070: * @param port
071: * Information about the port for which dispatch/proxy will be created.
072: * @param serviceEndpointInterface
073: * Null if the created binding is for {@link Dispatch}. Otheriwse
074: * it represents the port interface of the proxy to be created.
075: * @param defaultFeatures
076: * The list of features that are currently scheduled to be set for
077: * the newly created {@link WSBinding}.
078: *
079: * @return
080: * A set of features to be added to the newly created {@link WSBinding}.
081: * Can be empty but never null.
082: * <tt>defaultFeatures</tt> will take precedence over what this method
083: * would return (because it includes user-specified ones which will
084: * take the at-most priority), but features you return from this method
085: * will take precedence over {@link BindingID}'s
086: * {@link BindingID#createBuiltinFeatureList() implicit features}.
087: */
088: public List<WebServiceFeature> preCreateBinding(@NotNull
089: WSPortInfo port, @Nullable
090: Class<?> serviceEndpointInterface, @NotNull
091: WSFeatureList defaultFeatures) {
092: return Collections.emptyList();
093: }
094:
095: /**
096: * A callback to notify the event of creation of proxy object for SEI endpoint. The
097: * callback could set some properties on the {@link BindingProvider}.
098: *
099: * @param bp created proxy instance
100: * @param serviceEndpointInterface SEI of the endpoint
101: */
102: public void postCreateProxy(@NotNull
103: WSBindingProvider bp, @NotNull
104: Class<?> serviceEndpointInterface) {
105: }
106:
107: /**
108: * A callback to notify that a {@link Dispatch} object is created. The callback
109: * could set some properties on the {@link BindingProvider}.
110: *
111: * @param bp BindingProvider of dispatch object
112: */
113: public void postCreateDispatch(@NotNull
114: WSBindingProvider bp) {
115: }
116:
117: /**
118: * Aggregates multiple interceptors into one facade.
119: */
120: public static ServiceInterceptor aggregate(
121: final ServiceInterceptor... interceptors) {
122: if (interceptors.length == 1)
123: return interceptors[0];
124: return new ServiceInterceptor() {
125: public List<WebServiceFeature> preCreateBinding(@NotNull
126: WSPortInfo port, @Nullable
127: Class<?> portInterface, @NotNull
128: WSFeatureList defaultFeatures) {
129: List<WebServiceFeature> r = new ArrayList<WebServiceFeature>();
130: for (ServiceInterceptor si : interceptors)
131: r.addAll(si.preCreateBinding(port, portInterface,
132: defaultFeatures));
133: return r;
134: }
135:
136: public void postCreateProxy(@NotNull
137: WSBindingProvider bp, @NotNull
138: Class<?> serviceEndpointInterface) {
139: for (ServiceInterceptor si : interceptors)
140: si.postCreateProxy(bp, serviceEndpointInterface);
141: }
142:
143: public void postCreateDispatch(@NotNull
144: WSBindingProvider bp) {
145: for (ServiceInterceptor si : interceptors)
146: si.postCreateDispatch(bp);
147: }
148: };
149: }
150: }
|